Commit version 24.12.13800

This commit is contained in:
2025-01-06 17:35:06 -05:00
parent b7f6a79c2c
commit 55d9218816
6133 changed files with 4239740 additions and 1374287 deletions

View File

@ -4,76 +4,76 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @package observium
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
function build_cbqos_query($vars)
{
$sql = 'SELECT * FROM `ports_cbqos`';
$sql = 'SELECT * FROM `ports_cbqos`';
//if ($vars['sort'] == 'hostname' || $vars['sort'] == 'device' || $vars['sort'] == 'device_id') {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
//}
//if ($vars['sort'] == 'hostname' || $vars['sort'] == 'device' || $vars['sort'] == 'device_id') {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
//}
$sql .= ' LEFT JOIN `ports` USING (`port_id`)';
$sql .= ' LEFT JOIN `ports` USING (`port_id`)';
// Rewrite `device_id` to use `ports_cbqos` table name to avoid dupe field error.
$sql .= ' WHERE 1' . str_replace('`device_id`', '`ports_cbqos`.`device_id`', generate_query_permitted(array('device')));
// Rewrite `device_id` to use `ports_cbqos` table name to avoid dupe field error.
$sql .= ' WHERE 1' . str_replace('`device_id`', '`ports_cbqos`.`device_id`', generate_query_permitted(['device']));
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "policy_name":
case "object_name":
$sql .= generate_query_values_and($value, $var);
break;
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'cbqos_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'ports_cbqos.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'ports_cbqos.device_id');
break;
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "policy_name":
case "object_name":
$sql .= generate_query_values_and($value, $var);
break;
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'cbqos_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'ports_cbqos.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'ports_cbqos.device_id');
break;
}
}
}
switch ($vars['sort_order']) {
case 'desc':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
}
switch ($vars['sort_order']) {
case 'desc':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
}
switch ($vars['sort']) {
case 'policy_name':
case 'object_name':
case 'PrePolicyByte_rate':
case 'PostPolicyByte_rate':
case 'DropByte_rate':
switch ($vars['sort']) {
case 'policy_name':
case 'object_name':
case 'PrePolicyByte_rate':
case 'PostPolicyByte_rate':
case 'DropByte_rate':
$sql .= ' ORDER BY '.$vars['sort'].' ' . $sort_order;
break;
default:
$sql .= ' ORDER BY `hostname` ' . $sort_order . ', `port_label_short` '. $sort_order;
}
$sql .= ' ORDER BY ' . $vars['sort'] . ' ' . $sort_order;
break;
default:
$sql .= ' ORDER BY `hostname` ' . $sort_order . ', `port_label_short` ' . $sort_order;
}
return $sql;
return $sql;
}
@ -81,77 +81,82 @@ function build_cbqos_query($vars)
function print_cbqos_table_header($vars)
{
echo('<table class="' . (get_var_true($vars['graphs']) ? OBS_CLASS_TABLE_STRIPED_TWO : OBS_CLASS_TABLE_STRIPED) . '">');
$cols[] = array('', 'class="state-marker"');
if(!isset($vars['device_id'])) { $cols['hostname'] = array('Device', 'style="width: 200px;"'); }
if(!isset($vars['device_id'])) { $cols['port_label'] = array('Port', 'style="width: 200px;"'); }
$cols['policy_name'] = array('Policy', 'style="width: 150px;"');
$cols['object_name'] = array('Object', 'style="width: 200px;"');
$cols['PrePolicyByte_rate'] = array('Traffic');
$cols['DropByte_rate'] = array('Dropped');
$cols[] = array();
echo get_table_header($cols, $vars);
echo '<tbody>' . PHP_EOL;
}
function print_cbqos_table($vars) {
global $config;
$sql = build_cbqos_query($vars);
$entries = dbFetchRows($sql);
if (!safe_empty($entries)) {
echo generate_box_open();
print_cbqos_table_header($vars);
foreach ($entries as $cbqos_id => $entry) {
$perc_drop = float_div($entry['DropByte_rate'], $entry['PrePolicyByte_rate']) * 100;
echo '<tr>';
echo '<td class="state-marker"></td>';
echo '<td class="entity">'.generate_device_link($entry).'</td>';
echo '<td class="entity">'.generate_port_link($entry).'</td>';
echo '<td class="entity"><a href="'.generate_url(array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'port', 'port' => $entry['port_id'], 'view' => 'cbqos')).'">'.$entry['policy_name'].'</a></td>';
echo '<td class="entity"><a href="'.generate_url(array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'port', 'port' => $entry['port_id'], 'view' => 'cbqos')).'">'.$entry['object_name'].'</a></td>';
echo '<td>'.format_number($entry['PrePolicyByte_rate']).'bps / '.format_number($entry['PostPolicyByte_rate']).'bps</td>';
echo '<td>'.format_number($entry['DropByte_rate']).'bps ('.$perc_drop.'%)</td>';
echo '<td></td>';
echo '</tr>';
if (get_var_true($vars['graphs'])) {
$vars['graph'] = "graph";
}
if ($vars['graph']) {
$graph_array = array();
$graph_title = $entry['oid_descr'];
$graph_array['type'] = "cbqos_".$vars['graph'];
$graph_array['id'] = $entry['cbqos_id'];
echo '<tr>';
echo ' <td class="state-marker"></td>';
echo ' <td colspan=8>';
print_graph_row($graph_array);
echo ' </td>';
echo '</tr>';
}
echo('<table class="' . (get_var_true($vars['graphs']) ? OBS_CLASS_TABLE_STRIPED_TWO : OBS_CLASS_TABLE_STRIPED) . '">');
$cols[] = ['', 'class="state-marker"'];
if (!isset($vars['device_id'])) {
$cols['hostname'] = ['Device', 'style="width: 200px;"'];
}
if (!isset($vars['device_id'])) {
$cols['port_label'] = ['Port', 'style="width: 200px;"'];
}
echo ' </table>' . PHP_EOL;
echo generate_box_close();
$cols['policy_name'] = ['Policy', 'style="width: 150px;"'];
$cols['object_name'] = ['Object', 'style="width: 200px;"'];
$cols['PrePolicyByte_rate'] = ['Traffic'];
$cols['DropByte_rate'] = ['Dropped'];
}
$cols[] = [];
echo get_table_header($cols, $vars);
echo '<tbody>' . PHP_EOL;
}
function print_cbqos_table($vars)
{
global $config;
$sql = build_cbqos_query($vars);
$entries = dbFetchRows($sql);
if (!safe_empty($entries)) {
echo generate_box_open();
print_cbqos_table_header($vars);
foreach ($entries as $cbqos_id => $entry) {
$perc_drop = float_div($entry['DropByte_rate'], $entry['PrePolicyByte_rate']) * 100;
echo '<tr>';
echo '<td class="state-marker"></td>';
echo '<td class="entity">' . generate_device_link($entry) . '</td>';
echo '<td class="entity">' . generate_port_link($entry) . '</td>';
echo '<td class="entity"><a href="' . generate_url(['page' => 'device', 'device' => $entry['device_id'], 'tab' => 'port', 'port' => $entry['port_id'], 'view' => 'cbqos']) . '">' . $entry['policy_name'] . '</a></td>';
echo '<td class="entity"><a href="' . generate_url(['page' => 'device', 'device' => $entry['device_id'], 'tab' => 'port', 'port' => $entry['port_id'], 'view' => 'cbqos']) . '">' . $entry['object_name'] . '</a></td>';
echo '<td>' . format_number($entry['PrePolicyByte_rate']) . 'bps / ' . format_number($entry['PostPolicyByte_rate']) . 'bps</td>';
echo '<td>' . format_number($entry['DropByte_rate']) . 'bps (' . $perc_drop . '%)</td>';
echo '<td></td>';
echo '</tr>';
if (get_var_true($vars['graphs'])) {
$vars['graph'] = "graph";
}
if ($vars['graph']) {
$graph_array = [];
$graph_title = $entry['oid_descr'];
$graph_array['type'] = "cbqos_" . $vars['graph'];
$graph_array['id'] = $entry['cbqos_id'];
echo '<tr>';
echo ' <td class="state-marker"></td>';
echo ' <td colspan=8>';
print_graph_row($graph_array);
echo ' </td>';
echo '</tr>';
}
}
echo ' </table>' . PHP_EOL;
echo generate_box_close();
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,8 @@
* This file is part of Observium.
*
* @package observium
* @subpackage functions
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
@ -14,43 +14,42 @@
function print_f5_lb_virtual_table_header($vars)
{
if ($vars['view'] == "graphs")
{
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
if ($vars['view'] == "graphs") {
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = array(
array(NULL, 'class="state-marker"'),
'device' => array('Device', 'style="width: 200px;"'),
'virt_name' => array('Virtual'),
array('', 'style="width: 100px;"'),
'virt_ip' => array('Address', 'style="width: 250px;"'),
'virt_type' => array('Type', 'style="width: 250px;"'),
'virt_state' => array('Status', 'style="width: 250px;"'),
);
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = [
[NULL, 'class="state-marker"'],
'device' => ['Device', 'style="width: 200px;"'],
'virt_name' => ['Virtual'],
['', 'style="width: 100px;"'],
'virt_ip' => ['Address', 'style="width: 250px;"'],
'virt_type' => ['Type', 'style="width: 250px;"'],
'virt_state' => ['Status', 'style="width: 250px;"'],
];
if ($vars['page'] == "device")
{
unset($cols['device']);
}
if ($vars['page'] == "device") {
unset($cols['device']);
}
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
}
function get_customoid_by_id($oid_id) {
function get_customoid_by_id($oid_id)
{
if (is_numeric($oid_id)) {
$oid = dbFetchRow('SELECT * FROM `oids` WHERE `oid_id` = ?', array($oid_id));
}
if (safe_count($oid)) {
return $oid;
}
if (is_numeric($oid_id)) {
$oid = dbFetchRow('SELECT * FROM `oids` WHERE `oid_id` = ?', [$oid_id]);
}
if (safe_count($oid)) {
return $oid;
}
return FALSE;
return FALSE;
} // end function get_customoid_by_id()
@ -58,409 +57,393 @@ function get_customoid_by_id($oid_id) {
// TESTME needs unit testing
function get_application_by_id($application_id)
{
if (is_numeric($application_id))
{
$application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", array($application_id));
}
if (is_array($application))
{
return $application;
} else {
return FALSE;
}
if (is_numeric($application_id)) {
$application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", [$application_id]);
}
if (is_array($application)) {
return $application;
} else {
return FALSE;
}
}
// DOCME needs phpdoc block
// TESTME needs unit testing
function accesspoint_by_id($ap_id, $refresh = '0')
{
$ap = dbFetchRow("SELECT * FROM `accesspoints` WHERE `accesspoint_id` = ?", array($ap_id));
$ap = dbFetchRow("SELECT * FROM `accesspoints` WHERE `accesspoint_id` = ?", [$ap_id]);
return $ap;
return $ap;
}
function generate_entity_popup_graphs($entity, $vars)
{
global $config;
global $config;
$entity_type = $vars['entity_type'];
$entity_type = $vars['entity_type'];
if (is_array($config['entities'][$entity_type]['graph']))
{
if (isset($config['entities'][$entity_type]['graph']['type']))
{
$graphs[] = $config['entities'][$entity_type]['graph'];
} else {
$graphs = $config['entities'][$entity_type]['graph'];
}
foreach($graphs as $graph_array)
{
//$graph_array = $config['entities'][$entity_type]['graph'];
// We can draw a graph for this type/metric pair!
foreach($graph_array as $key => $val)
{
// Check to see if we need to do any substitution
if (substr($val, 0, 1) == "@")
{
$nval = substr($val, 1);
$graph_array[$key] = $entity[$nval];
if (is_array($config['entities'][$entity_type]['graph'])) {
if (isset($config['entities'][$entity_type]['graph']['type'])) {
$graphs[] = $config['entities'][$entity_type]['graph'];
} else {
$graphs = $config['entities'][$entity_type]['graph'];
}
}
$graph_array['height'] = "100";
$graph_array['width'] = "323";
$content = '<div style="white-space: nowrap;">';
$content .= "<div class=entity-title><h4>" . nicecase(str_replace("_", " ", $graph_array['type'])) . "</h4></div>";
/*
$content = generate_box_open(array('title' => nicecase(str_replace("_", " ", $graph_array['type'])),
'body-style' => 'white-space: nowrap;'));
*/
foreach(array('day', 'month') as $period)
{
$graph_array['from'] = $config['time'][$period];
$content .= generate_graph_tag($graph_array);
}
$content .= "</div>";
//$content .= generate_box_close();
foreach ($graphs as $graph_array) {
//$graph_array = $config['entities'][$entity_type]['graph'];
// We can draw a graph for this type/metric pair!
foreach ($graph_array as $key => $val) {
// Check to see if we need to do any substitution
if (substr($val, 0, 1) === "@") {
$nval = substr($val, 1);
$graph_array[$key] = $entity[$nval];
}
}
$graph_array['height'] = "100";
$graph_array['width'] = "323";
$content = '<div style="white-space: nowrap;">';
$content .= "<div class=entity-title><h4>" . nicecase(str_replace("_", " ", $graph_array['type'])) . "</h4></div>";
/*
$content = generate_box_open(array('title' => nicecase(str_replace("_", " ", $graph_array['type'])),
'body-style' => 'white-space: nowrap;'));
*/
foreach ([ 'day', 'month' ] as $period) {
$graph_array['from'] = get_time($period);
$content .= generate_graph_tag($graph_array);
}
$content .= "</div>";
//$content .= generate_box_close();
}
//r($content);
return $content;
}
//r($content);
return $content;
}
}
function generate_entity_popup_header($entity, $vars)
{
$translate = entity_type_translate_array($vars['entity_type']);
$translate = entity_type_translate_array($vars['entity_type']);
$vars['popup'] = TRUE;
$vars['entity_icon'] = TRUE;
$contents = '';
$vars['popup'] = TRUE;
$vars['entity_icon'] = TRUE;
$contents = '';
switch($vars['entity_type'])
{
case "sensor":
switch ($vars['entity_type']) {
case "sensor":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_sensor_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_sensor_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "toner":
case "printersupply":
case "supply":
case "toner":
case "printersupply":
case "supply":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_printersupplies_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_printersupplies_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "bgp_peer":
if ($entity['peer_device_id'])
{
$peer_dev = device_by_id_cache($entity['peer_device_id']);
$peer_name = '<br /><a class="entity" style="font-weight: bold;">'.$peer_dev['hostname'].'</a>';
}
else if ($entity['reverse_dns'])
{
$peer_name = '<br /><span style="font-weight: bold;">' . $entity['reverse_dns'] . '</span>';
}
$astext = '<span>AS'.$entity['human_remote_as'];
if ($entity['astext'])
{
$astext .= '<br />' . $entity['astext'] . '</span>';
}
$astext .= '</span>';
$contents .= generate_box_open();
$contents .= '
<table class="'. OBS_CLASS_TABLE .'">
case "bgp_peer":
if ($entity['peer_device_id']) {
$peer_dev = device_by_id_cache($entity['peer_device_id']);
$peer_name = '<br /><a class="entity" style="font-weight: bold;">' . $peer_dev['hostname'] . '</a>';
} elseif ($entity['reverse_dns']) {
$peer_name = '<br /><span style="font-weight: bold;">' . $entity['reverse_dns'] . '</span>';
}
$astext = '<span>AS' . $entity['human_remote_as'];
if ($entity['astext']) {
$astext .= '<br />' . $entity['astext'] . '</span>';
}
$astext .= '</span>';
$contents .= generate_box_open();
$contents .= '
<table class="' . OBS_CLASS_TABLE . '">
<tr class="' . $entity['row_class'] . ' vertical-align" style="font-size: 10pt;">
<td class="state-marker"></td>
<td style="width: 10px;"></td>
<td style="width: 10px;"><i class="'.$translate['icon'].'"></i></td>
<td><a class="entity-popup" style="font-size: 15px; font-weight: bold;">'.escape_html($entity['entity_shortname']).'</a>'.$peer_name.'</td>
<td class="text-nowrap" style="width: 20%;">'.$astext.'</td>
<td style="width: 10px;"><i class="' . $translate['icon'] . '"></i></td>
<td><a class="entity-popup" style="font-size: 15px; font-weight: bold;">' . escape_html($entity['entity_shortname']) . '</a>' . $peer_name . '</td>
<td class="text-nowrap" style="width: 20%;">' . $astext . '</td>
<td></td>
</tr>
</table>';
$contents .= generate_box_close();
break;
$contents .= generate_box_close();
break;
case "sla":
case "sla":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_sla_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_sla_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "processor":
case "processor":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_processor_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_processor_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "mempool":
case "mempool":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_mempool_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_mempool_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "p2pradio":
case "p2pradio":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_p2pradio_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_p2pradio_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "status":
case "status":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_status_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_status_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "counter":
case "counter":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_counter_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_counter_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "storage":
case "storage":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_storage_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_storage_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "netscalervsvr":
case "netscalervsvr":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_netscalervsvr_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_netscalervsvr_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "netscalersvc":
case "netscalersvc":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_netscalersvc_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_netscalersvc_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
case "netscalersvcgrpmem":
case "netscalersvcgrpmem":
$contents .= generate_box_open();
$contents .= '<table class="'. OBS_CLASS_TABLE .'">';
$contents .= generate_netscalersvcmem_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
$contents .= generate_box_open();
$contents .= '<table class="' . OBS_CLASS_TABLE . '">';
$contents .= generate_netscalersvcmem_row($entity, $vars);
$contents .= '</table>';
$contents .= generate_box_close();
break;
break;
default:
entity_rewrite($vars['entity_type'], $entity);
$contents = generate_box_open(). '
default:
entity_rewrite($vars['entity_type'], $entity);
$contents = generate_box_open() . '
<table class="' . OBS_CLASS_TABLE_STRIPED . '">
<tr class="' . $entity['row_class'] . '" style="font-size: 10pt;">
<td class="state-marker"></td>
<td style="width: 10px;"></td>
<td width="400"><i class="'.$translate['icon'].'" style="margin-right: 10px;"></i> <a class="entity-popup" style="font-size: 15px; font-weight: bold;">'.escape_html($entity['entity_name']).'</a></td>
<td width="400"><i class="' . $translate['icon'] . '" style="margin-right: 10px;"></i> <a class="entity-popup" style="font-size: 15px; font-weight: bold;">' . escape_html($entity['entity_name']) . '</a></td>
<td width="100"></td>
<td></td>
</tr>
</table>'.generate_box_close();
}
</table>' . generate_box_close();
}
return $contents;
return $contents;
}
function generate_entity_popup($entity, $vars)
{
if (is_numeric($entity)) { $entity = get_entity_by_id_cache($vars['entity_type'], $entity); }
$device = device_by_id_cache($entity['device_id']);
if (is_numeric($entity)) {
$entity = get_entity_by_id_cache($vars['entity_type'], $entity);
}
$device = device_by_id_cache($entity['device_id']);
$content = generate_device_popup_header($device);
$content .= generate_entity_popup_header($entity, $vars);
$content .= generate_entity_popup_graphs($entity, $vars);
$content = generate_device_popup_header($device);
$content .= generate_entity_popup_header($entity, $vars);
$content .= generate_entity_popup_graphs($entity, $vars);
return $content;
return $content;
}
function generate_entity_popup_multi($entities, $vars)
{
// Note here limited only to one entity_type and one device_id
// Note here limited only to one entity_type and one device_id
$count = count($entities);
// First element
$entity = array_shift($entities);
if (is_numeric($entity))
{
$entity = get_entity_by_id_cache($vars['entity_type'], $entity);
}
$device = device_by_id_cache($entity['device_id']);
$header = generate_entity_popup_header($entity, $vars);
if ($count > 1)
{
// Multiple entities graph
/// FIXME. Need add multi-graphs
$graphs = generate_entity_popup_graphs($entity, $vars);// This is incorrect, only first graph
} else {
// Single entity graph
$graphs = generate_entity_popup_graphs($entity, $vars);
}
// All other elements
foreach ($entities as $entity)
{
if (is_numeric($entity))
{
$entity = get_entity_by_id_cache($vars['entity_type'], $entity);
$count = count($entities);
// First element
$entity = array_shift($entities);
if (is_numeric($entity)) {
$entity = get_entity_by_id_cache($vars['entity_type'], $entity);
}
if ($entity['device_id'] != $device['device_id'])
{
// Skip if passed entity from different device
continue;
$device = device_by_id_cache($entity['device_id']);
$header = generate_entity_popup_header($entity, $vars);
if ($count > 1) {
// Multiple entities graph
/// FIXME. Need add multi-graphs
$graphs = generate_entity_popup_graphs($entity, $vars);// This is incorrect, only first graph
} else {
// Single entity graph
$graphs = generate_entity_popup_graphs($entity, $vars);
}
$header .= generate_entity_popup_header($entity, $vars);
//$graphs .= generate_entity_popup_graphs($entity, $vars); // Currently disabled, need multi graph
}
// All other elements
foreach ($entities as $entity) {
if (is_numeric($entity)) {
$entity = get_entity_by_id_cache($vars['entity_type'], $entity);
}
if ($entity['device_id'] != $device['device_id']) {
// Skip if passed entity from different device
continue;
}
$content = generate_device_popup_header($device);
$content .= $header;
$content .= $graphs;
$header .= generate_entity_popup_header($entity, $vars);
//$graphs .= generate_entity_popup_graphs($entity, $vars); // Currently disabled, need multi graph
}
return $content;
$content = generate_device_popup_header($device);
$content .= $header;
$content .= $graphs;
return $content;
}
// Measured specific functions
function build_entity_measured_where($entity_type, $vars)
{
$entity_array = entity_type_translate_array($entity_type);
function generate_query_entity_measured($entity_type, $vars) {
$column_measured_id = $entity_array['table_fields']['measured_id'];
$column_measured_type = $entity_array['table_fields']['measured_type'];
$measure_array = [];
$entity_array = entity_type_translate_array($entity_type);
// Build query
foreach($vars as $var => $value)
{
if (!is_array($value)) { $value = explode(',', $value); }
$column_measured_id = $entity_array['table_fields']['measured_id'];
$column_measured_type = $entity_array['table_fields']['measured_type'];
$measure_array = [];
switch ($var)
{
case 'measured_group':
foreach (dbFetchColumn('SELECT DISTINCT `'.$column_measured_type.'` FROM `'.$entity_array['table'].'` WHERE `'.$entity_array['table_fields']['deleted'].'` = ?', [0]) as $measured_type)
{
if (!$measured_type) { continue; }
$entities = get_group_entities($value, $measured_type);
$measure_sql = '';
switch ($measured_type)
{
case 'port':
case 'printersupply':
$measure_sql = generate_query_values_ng($measured_type, $column_measured_type);
$measure_sql .= generate_query_values_and($entities, $column_measured_id);
break;
}
if ($measure_sql) { $measure_array[] = $measure_sql; }
// Build query
foreach ($vars as $var => $value) {
if (!is_array($value)) {
$value = explode(',', $value);
}
break;
case 'measured_state':
// UP / DOWN / STUTDOWN / NONE states
//$value = (array)$value;
// Select all without measured entities
if (in_array('none', $value)) {
$measure_array[] = generate_query_values_ng(1, $column_measured_id);
$value = array_diff($value, [ 'none' ]);
}
if (count($value))
{
// Limit statuses with measured entities
foreach (dbFetchColumn('SELECT DISTINCT `'.$column_measured_type.'` FROM `'.$entity_array['table'].'` WHERE `'.$entity_array['table_fields']['deleted'].'` = ?', [0]) as $measured_type)
{
if (!$measured_type) { continue; }
$measure_sql = '';
$measure_entities = dbFetchColumn('SELECT DISTINCT `'.$column_measured_id.'` FROM `'.$entity_array['table'].'` WHERE `'.$column_measured_type.'` = ? AND `'.$entity_array['table_fields']['deleted'].'` = ?', [$measured_type, 0]);
switch ($measured_type)
{
case 'port':
$where_array = build_ports_where_array(['port_id' => $measure_entities, 'state' => $value]);
switch ($var) {
case 'measured_group':
foreach (dbFetchColumn('SELECT DISTINCT `' . $column_measured_type . '` FROM `' . $entity_array['table'] . '` WHERE `' . $entity_array['table_fields']['deleted'] . '` = ?', [0]) as $measured_type) {
if (!$measured_type) {
continue;
}
$entity_sql = 'SELECT `port_id` FROM `ports` WHERE 1 ';
$entity_sql .= implode('', $where_array);
$entities = dbFetchColumn($entity_sql);
//$entities = dbFetchColumn($entity_sql, NULL, TRUE);
//r($entities);
$measure_sql = generate_query_values_ng($measured_type, $column_measured_type);
$measure_sql .= generate_query_values_and($entities, $column_measured_id);
$entities = get_group_entities($value, $measured_type);
$measure_sql = '';
switch ($measured_type) {
case 'port':
case 'printersupply':
$measure_sql = generate_query_values($measured_type, $column_measured_type);
$measure_sql .= generate_query_values_and($entities, $column_measured_id);
break;
}
if ($measure_sql) {
$measure_array[] = $measure_sql;
}
}
break;
case 'printersupply':
break;
}
if ($measure_sql) { $measure_array[] = $measure_sql; }
case 'measured_state':
// UP / DOWN / STUTDOWN / NONE states
//$value = (array)$value;
// Select all without measured entities
if (in_array('none', $value)) {
$measure_array[] = generate_query_values(1, $column_measured_id);
$value = array_diff($value, ['none']);
}
if (count($value)) {
// Limit statuses with measured entities
foreach (dbFetchColumn('SELECT DISTINCT `' . $column_measured_type . '` FROM `' . $entity_array['table'] . '` WHERE `' . $entity_array['table_fields']['deleted'] . '` = ?', [0]) as $measured_type) {
if (!$measured_type) {
continue;
}
}
$measure_sql = '';
$measure_entities = dbFetchColumn('SELECT DISTINCT `' . $column_measured_id . '` FROM `' . $entity_array['table'] . '` WHERE `' . $column_measured_type . '` = ? AND `' . $entity_array['table_fields']['deleted'] . '` = ?', [$measured_type, 0]);
switch ($measured_type) {
case 'port':
$where_array = build_ports_where_array(['port_id' => $measure_entities, 'state' => $value]);
$entity_sql = 'SELECT `port_id` FROM `ports` WHERE 1 ';
$entity_sql .= implode('', $where_array);
$entities = dbFetchColumn($entity_sql);
//$entities = dbFetchColumn($entity_sql, NULL, TRUE);
//r($entities);
$measure_sql = generate_query_values($measured_type, $column_measured_type);
$measure_sql .= generate_query_values_and($entities, $column_measured_id);
break;
case 'printersupply':
break;
}
if ($measure_sql) {
$measure_array[] = $measure_sql;
}
}
}
break;
}
break;
}
}
switch (count($measure_array))
{
case 0:
$sql = '';
break;
case 1:
$sql = ' AND ' . $measure_array[0];
break;
default:
$sql = ' AND (('.implode(') OR (', $measure_array).'))';
}
switch (count($measure_array)) {
case 0:
return '';
return $sql;
case 1:
return $measure_array[0];
}
//r($measure_array);
return '((' . implode(') OR (', $measure_array) . '))';
}
// EOF

View File

@ -6,221 +6,197 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
function build_mempool_query($vars)
{
global $config, $cache;
$sql = 'SELECT * FROM `mempools`';
$sql = 'SELECT *, `mempools`.`mempool_id` AS `mempool_id` FROM `mempools`';
//$sql .= ' LEFT JOIN `mempools-state` USING(`mempool_id`)';
if ($vars['sort'] === 'hostname' || $vars['sort'] === 'device' || $vars['sort'] === 'device_id') {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
}
$sql .= ' WHERE 1' . generate_query_permitted(array('device'));
// Build query
foreach ($vars as $var => $value)
{
switch ($var)
{
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'mempools.mempool_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'mempools.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'mempools.device_id');
break;
case "descr":
case "mempool_descr";
$sql .= generate_query_values_and($value, 'mempool_descr', '%LIKE%');
break;
if ($vars['sort'] === 'hostname' || $vars['sort'] === 'device' || $vars['sort'] === 'device_id') {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
}
}
switch ($vars['sort_order'])
{
case 'desc':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
}
$sql .= ' WHERE ' . generate_query_permitted_ng([ 'device' ]);
switch($vars['sort'])
{
case 'usage':
$sql .= ' ORDER BY `mempool_used` '.$sort_neg;
break;
case 'used':
$sql .= ' ORDER BY `mempool_perc` '.$sort_neg;
break;
case 'hostname':
$sql .= ' ORDER BY `hostname` '.$sort_order.', `mempool_descr` '.$sort_order;
break;
case 'descr':
default:
$sql .= ' ORDER BY `mempool_descr` '.$sort_order;
break;
}
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'mempools.mempool_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'mempools.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'mempools.device_id');
break;
case "descr":
case "mempool_descr";
$sql .= generate_query_values_and($value, 'mempool_descr', '%LIKE%');
break;
}
}
return $sql;
switch ($vars['sort_order']) {
case 'desc':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
}
switch ($vars['sort']) {
case 'usage':
$sql .= ' ORDER BY `mempool_used` ' . $sort_neg;
break;
case 'used':
$sql .= ' ORDER BY `mempool_perc` ' . $sort_neg;
break;
case 'hostname':
$sql .= ' ORDER BY `hostname` ' . $sort_order . ', `mempool_descr` ' . $sort_order;
break;
case 'descr':
default:
$sql .= ' ORDER BY `mempool_descr` ' . $sort_order;
break;
}
return $sql;
}
function print_mempool_table($vars)
{
global $cache;
$sql = build_mempool_query($vars);
$sql = build_mempool_query($vars);
$mempools = dbFetchRows($sql);
$mempools = array();
foreach (dbFetchRows($sql) as $mempool)
{
if (isset($cache['devices']['id'][$mempool['device_id']]))
{
$mempool['hostname'] = $cache['devices']['id'][$mempool['device_id']]['hostname'];
$mempool['html_row_class'] = $cache['devices']['id'][$mempool['device_id']]['html_row_class'];
$mempools[] = $mempool;
$mempools_count = safe_count($mempools);
// Pagination
$pagination_html = pagination($vars, $mempools_count);
echo $pagination_html;
if ($vars['pageno']) {
$mempools = array_chunk($mempools, $vars['pagesize']);
$mempools = $mempools[$vars['pageno'] - 1];
}
}
// End Pagination
$mempools_count = count($mempools);
echo generate_box_open();
// Pagination
$pagination_html = pagination($vars, $mempools_count);
echo $pagination_html;
print_mempool_table_header($vars);
if ($vars['pageno'])
{
$mempools = array_chunk($mempools, $vars['pagesize']);
$mempools = $mempools[$vars['pageno'] - 1];
}
// End Pagination
foreach ($mempools as $mempool) {
print_mempool_row($mempool, $vars);
}
echo generate_box_open();
echo("</tbody></table>");
print_mempool_table_header($vars);
echo generate_box_close();
foreach ($mempools as $mempool)
{
print_mempool_row($mempool, $vars);
}
echo("</tbody></table>");
echo generate_box_close();
echo $pagination_html;
echo $pagination_html;
}
function print_mempool_table_header($vars)
{
if ($vars['view'] === "graphs")
{
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
if ($vars['view'] === "graphs") {
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = array(
array(NULL, 'class="state-marker"'),
'device' => array('Device', 'style="width: 200px;"'),
'descr' => array('Memory'),
array('', 'style="width: 100px;"'),
'usage' => array('Usage', 'style="width: 280px;"'),
'used' => array('Used', 'style="width: 50px;"'),
);
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = [
[NULL, 'class="state-marker"'],
'device' => ['Device', 'style="width: 200px;"'],
'descr' => ['Memory'],
['', 'style="width: 100px;"'],
'usage' => ['Usage', 'style="width: 280px;"'],
'used' => ['Used', 'style="width: 50px;"'],
];
if ($vars['page'] === "device")
{
unset($cols['device']);
}
if ($vars['page'] === "device") {
unset($cols['device']);
}
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
}
function print_mempool_row($mempool, $vars)
{
echo generate_mempool_row($mempool, $vars);
echo generate_mempool_row($mempool, $vars);
}
function generate_mempool_row($mempool, $vars)
{
global $config;
global $config;
$table_cols = 7;
if ($vars['page'] !== "device" && $vars['popup'] != TRUE) { $table_cols++; } // Add a column for device.
$table_cols = 7;
if ($vars['page'] !== "device" && !get_var_true($vars['popup'])) {
$table_cols++;
} // Add a column for device.
$graph_array = array();
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $mempool['mempool_id'];
$graph_array['type'] = "mempool_usage";
$graph_array['legend'] = "no";
$graph_array = [];
$graph_array['to'] = get_time();
$graph_array['id'] = $mempool['mempool_id'];
$graph_array['type'] = "mempool_usage";
$graph_array['legend'] = "no";
$link_array = $graph_array;
$link_array['page'] = "graphs";
unset($link_array['height'], $link_array['width'], $link_array['legend']);
$link_graph = generate_url($link_array);
$link_array = $graph_array;
$link_array['page'] = "graphs";
unset($link_array['height'], $link_array['width'], $link_array['legend']);
$link_graph = generate_url($link_array);
$link = generate_url(array("page" => "device", "device" => $mempool['device_id'], "tab" => "health", "metric" => 'mempool'));
$link = generate_url(["page" => "device", "device" => $mempool['device_id'], "tab" => "health", "metric" => 'mempool']);
$overlib_content = generate_overlib_content($graph_array, $mempool['hostname'] . " - " . rewrite_entity_name($mempool['mempool_descr'], 'mempool'));
$overlib_content = generate_overlib_content($graph_array, $mempool['hostname'] . " - " . rewrite_entity_name($mempool['mempool_descr'], 'mempool'));
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = $config['time']['day'];
$mini_graph = generate_graph_tag($graph_array);
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = get_time('day');
$mini_graph = generate_graph_tag($graph_array);
if ($mempool['mempool_total'] != '100')
{
$total = formatStorage($mempool['mempool_total']);
$used = formatStorage($mempool['mempool_used']);
$free = formatStorage($mempool['mempool_free']);
}
else
{
// If total == 100, than memory not have correct size and uses percents only
$total = $mempool['mempool_total'] . '%';
$used = $mempool['mempool_used'] . '%';
$free = $mempool['mempool_free'] . '%';
}
if ($mempool['mempool_total'] != '100') {
$total = format_bytes($mempool['mempool_total']);
$used = format_bytes($mempool['mempool_used']);
$free = format_bytes($mempool['mempool_free']);
} else {
// If total == 100, then memory not have correct size and uses percents only
$total = $mempool['mempool_total'] . '%';
$used = $mempool['mempool_used'] . '%';
$free = $mempool['mempool_free'] . '%';
}
$background = get_percentage_colours($mempool['mempool_perc']);
$background = get_percentage_colours($mempool['mempool_perc']);
$mempool['html_row_class'] = $background['class'];
$mempool['html_row_class'] = $background['class'];
$row .= '<tr class="' . $mempool['html_row_class'] . '">
$row = '<tr class="' . $mempool['html_row_class'] . '">
<td class="state-marker"></td>';
if ($vars['page'] !== "device" && $vars['popup'] != TRUE)
{
$row .= '<td class="entity">' . generate_device_link($mempool) . '</td>';
}
if ($vars['page'] !== "device" && !get_var_true($vars['popup'])) {
$row .= '<td class="entity">' . generate_device_link($mempool) . '</td>';
}
$row .= '<td class="entity">' . generate_entity_link('mempool', $mempool) . '</td>
$row .= '<td class="entity">' . generate_entity_link('mempool', $mempool) . '</td>
<td>' . overlib_link($link_graph, $mini_graph, $overlib_content) . '</td>
<td><a href="' . $link_graph . '">
' . print_percentage_bar(400, 20, $mempool['mempool_perc'], $used . '/' . $total . ' (' . $mempool['mempool_perc'] . '%)', "ffffff", $background['left'], $free . ' (' . (100 - $mempool['mempool_perc']) . '%)', "ffffff", $background['right']) . '
@ -230,130 +206,128 @@ function generate_mempool_row($mempool, $vars)
</tr>
';
if ($vars['view'] === "graphs")
{
$vars['graph'] = "usage";
}
if ($vars['view'] === "graphs") {
$vars['graph'] = "usage";
}
if ($vars['graph'])
{
$row .= '<tr class="' . $mempool['html_row_class'] . '">';
$row .= '<td class="state-marker"></td>';
$row .= '<td colspan="' . $table_cols . '">';
if ($vars['graph']) {
$row .= '<tr class="' . $mempool['html_row_class'] . '">';
$row .= '<td class="state-marker"></td>';
$row .= '<td colspan="' . $table_cols . '">';
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $mempool['mempool_id'];
$graph_array['type'] = 'mempool_' . $vars['graph'];
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = get_time();
$graph_array['id'] = $mempool['mempool_id'];
$graph_array['type'] = 'mempool_' . $vars['graph'];
$row .= generate_graph_row($graph_array, TRUE);
$row .= generate_graph_row($graph_array, TRUE);
$row .= '</td></tr>';
} # endif graphs
$row .= '</td></tr>';
} # endif graphs
return $row;
return $row;
}
function print_mempool_form($vars, $single_device = FALSE)
{
//global $config;
//global $config;
$form = array('type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
$form = ['type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
$form_items = array();
$form_items = [];
if ($single_device)
{
// Single device, just hidden field
$form['row'][0]['device_id'] = array(
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%');
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `mempools`'));
if ($single_device) {
// Single device, just hidden field
$form['row'][0]['device_id'] = [
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%'];
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `mempools`'));
$form['row'][0]['device_id'] = array(
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']);
}
//$sensor_permitted = generate_query_permitted(array('device', 'sensor'));
$form['row'][0]['mempool_descr'] = array(
'type' => 'text',
'placeholder' => 'Mempool',
'width' => '100%', //'180px',
'grid' => 6,
'value' => $vars['mempool_descr']);
// Groups
foreach (get_type_groups('storage') as $entry)
{
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
$form['row'][0]['group'] = array(
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']);
$form['row'][0]['search'] = array(
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
);
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
// Custom panel form
$panel_form = array('type' => 'rows',
'title' => 'Search Mempools',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) { unset($form['row'][$row][$param]['grid']); }
$form['row'][0]['device_id'] = [
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']];
}
}
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['group'] = $form['row'][0]['group'];
//$sensor_permitted = generate_query_permitted(array('device', 'sensor'));
$form['row'][0]['mempool_descr'] = [
'type' => 'text',
'placeholder' => 'Mempool',
'width' => '100%', //'180px',
'grid' => 6,
'value' => $vars['mempool_descr']];
//$panel_form['row'][1]['supply_colour'] = $form['row'][0]['supply_colour'];
//$panel_form['row'][1]['supply_type'] = $form['row'][0]['supply_type'];
// Groups
foreach (get_type_groups('storage') as $entry) {
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
$form['row'][0]['group'] = [
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']];
//$panel_form['row'][2]['measured_state'] = $form['row'][0]['measured_state'];
//$panel_form['row'][2]['group'] = $form['row'][1]['group'];
$form['row'][0]['search'] = [
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
];
$panel_form['row'][3]['mempool_descr'] = $form['row'][0]['mempool_descr'];
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
//$panel_form['row'][5]['sort'] = $form['row'][0]['sort'];
$panel_form['row'][5]['search'] = $form['row'][0]['search'];
// Custom panel form
$panel_form = ['type' => 'rows',
'title' => 'Search Mempools',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
// Register custom panel
register_html_panel(generate_form($panel_form));
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) {
unset($form['row'][$row][$param]['grid']);
}
}
}
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['group'] = $form['row'][0]['group'];
//$panel_form['row'][1]['supply_colour'] = $form['row'][0]['supply_colour'];
//$panel_form['row'][1]['supply_type'] = $form['row'][0]['supply_type'];
//$panel_form['row'][2]['measured_state'] = $form['row'][0]['measured_state'];
//$panel_form['row'][2]['group'] = $form['row'][1]['group'];
$panel_form['row'][3]['mempool_descr'] = $form['row'][0]['mempool_descr'];
//$panel_form['row'][5]['sort'] = $form['row'][0]['sort'];
$panel_form['row'][5]['search'] = $form['row'][0]['search'];
// Register custom panel
register_html_panel(generate_form($panel_form));
}
// EOF

View File

@ -6,251 +6,245 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
function generate_oid_template_link($entry)
{
$url = generate_url(array('page' => 'customoid', 'oid_id' => $entry['oid_id']));
return '<a href="'.$url.'">'.$entry['oid_descr'].'</a>';
function generate_oid_template_link($entry) {
$url = generate_url([ 'page' => 'customoid', 'oid_id' => $entry['oid_id'] ]);
return '<a href="' . $url . '">' . escape_html($entry['oid_descr']) . '</a>';
}
function build_oid_query($vars)
{
$sql = 'SELECT * FROM `oids_entries` LEFT JOIN `oids` USING (`oid_id`)';
function build_oid_query($vars) {
$sql = 'SELECT * FROM `oids_entries` LEFT JOIN `oids` USING (`oid_id`)';
//if ($vars['sort'] == 'hostname' || $vars['sort'] == 'device' || $vars['sort'] == 'device_id') {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
//}
//if ($vars['sort'] == 'hostname' || $vars['sort'] == 'device' || $vars['sort'] == 'device_id') {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
//}
$sql .= ' WHERE 1' . generate_query_permitted(array('device'));
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "oid_id":
case "oid_descr":
case "oid":
case "oid_name":
$sql .= generate_query_values_and($value, $var);
break;
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'oid_entry_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'oids_entries.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'oids_entries.device_id');
break;
// Build query
$where_array = [];
foreach ($vars as $var => $value) {
switch ($var) {
case "oid_id":
case "oid_descr":
case "oid":
case "oid_name":
$where_array[] = generate_query_values($value, $var);
break;
case "group":
case "group_id":
$values = get_group_entities($value);
$where_array[] = generate_query_values($values, 'oid_entry_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$where_array[] = generate_query_values($values, 'oids_entries.device_id');
break;
case "device":
case "device_id":
$where_array[] = generate_query_values($value, 'oids_entries.device_id');
break;
}
}
}
$sql .= generate_where_clause($where_array, generate_query_permitted_ng(['device']));
switch ($vars['sort_order']) {
case 'desc':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
}
if (isset($vars['sort'])) {
$sort_order = get_sort_order($vars);
switch ($vars['sort']) {
case 'value':
case 'oid_descr':
case 'oid_name':
case 'oid':
case 'event':
$sort = generate_query_sort($vars['sort'], $sort_order);
break;
switch ($vars['sort']) {
case 'value':
case 'oid_descr':
case 'oid_name':
case 'oid':
case 'event':
$sql .= ' ORDER BY '.$vars['sort'].' ' . $sort_order;
break;
default:
$sql .= ' ORDER BY `hostname` ' . $sort_order;
}
return $sql;
default:
$sort = generate_query_sort('hostname', $sort_order);
}
} else {
$sort = generate_query_sort('hostname');
}
return $sql . $sort;
}
function print_oid_table_header($vars, $entries)
{
function print_oid_table_header($vars, $entries) {
echo('<table class="' . (get_var_true($vars['graphs']) ? OBS_CLASS_TABLE_STRIPED_TWO : OBS_CLASS_TABLE_STRIPED) . '">');
$cols[] = array('', 'class="state-marker"');
$cols['hostname'] = array('Device', 'style="width: 280px;"');
if(!isset($vars['oid_id'])){
$cols['oid_descr'] = array('OID Description');
} else { $cols[] = array(''); }
$cols[] = array('', 'style="width: 140px;"');
$cols[] = array('Thresholds', 'style="width: 100px;"');
$cols['value'] = array('Value', 'style="width: 80px;"');
$cols['event'] = array('Event', 'style="width: 60px;"');
$cols[] = ['', 'class="state-marker"'];
$cols['hostname'] = ['Device', 'style="width: 280px;"'];
if (!isset($vars['oid_id'])) {
$cols['oid_descr'] = ['OID Description'];
} else {
$cols[] = [''];
}
$cols[] = ['', 'style="width: 140px;"'];
$cols[] = ['Thresholds', 'style="width: 100px;"'];
$cols['value'] = ['Value', 'style="width: 80px;"'];
$cols['event'] = ['Event', 'style="width: 60px;"'];
if ($entries[0]['oid_autodiscover'] == '0' && $vars['page'] === "customoid") {
$cols['actions'] = array('', 'style="width: 40px;"');
$cols['actions'] = ['', 'style="width: 40px;"'];
}
echo get_table_header($cols, $vars);
echo '<tbody>' . PHP_EOL;
}
function print_oid_table($vars)
{
global $config;
function print_oid_table($vars) {
global $config;
$sql = build_oid_query($vars);
$entries = dbFetchRows($sql);
$count = count($entries);
$sql = build_oid_query($vars);
$entries = dbFetchRows($sql);
if (count($entries)) {
if (safe_empty($entries)) {
print_box("<strong>This Custom OID is not currently associated with any devices</strong>", 'warning');
return;
}
echo generate_box_open();
print_oid_table_header($vars, $entries);
foreach ($entries as $device_id => $entry) {
//$device = device_by_id_cache($device_id);
//$device = device_by_id_cache($device_id);
if (!is_numeric($entry['value'])) {
$entry['human_value'] = 'NaN';
} else {
if($entry['oid_kibi'] == 1) {
$entry['human_value'] = format_value($entry['value'], 'bi') . $entry['oid_symbol'];
if (!is_numeric($entry['value'])) {
$entry['human_value'] = 'NaN';
} else {
$entry['human_value'] = format_value($entry['value'], 'si') . $entry['oid_symbol'];
if ($entry['oid_kibi'] == 1) {
$entry['human_value'] = format_value($entry['value'], 'bi') . $entry['oid_symbol'];
} else {
$entry['human_value'] = format_value($entry['value'], 'si') . $entry['oid_symbol'];
}
}
}
$graph_array = array();
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $entry['oid_entry_id'];
$graph_array['type'] = "customoid_graph";
$graph_array['width'] = 100;
$graph_array['height'] = 20;
$graph_array['from'] = $config['time']['day'];
$graph_array = [];
$graph_array['to'] = get_time();
$graph_array['id'] = $entry['oid_entry_id'];
$graph_array['type'] = "customoid_graph";
$graph_array['width'] = 100;
$graph_array['height'] = 20;
$graph_array['from'] = get_time('day');
if (is_numeric($entry['value']) || TRUE) {
$mini_graph = generate_graph_tag($graph_array);
} else {
// Do not show "Draw Error" minigraph
$mini_graph = '';
}
if (is_numeric($entry['value']) || TRUE) {
$mini_graph = generate_graph_tag($graph_array);
} else {
// Do not show "Draw Error" minigraph
$mini_graph = '';
}
$thresholds = threshold_string($entry['alert_low'], $entry['warn_low'], $entry['warn_high'],
$entry['alert_high'], $entry['oid_symbol']);
$thresholds = threshold_string($entry['alert_low'], $entry['warn_low'], $entry['warn_high'],
$entry['alert_high'], $entry['oid_symbol']);
switch ($entry['event']) {
case "ok";
$entry['html_row_class'] = "up";
$entry['event_class'] = "success";
break;
case "warn";
$entry['html_row_class'] = "warning";
$entry['event_class'] = "warning";
break;
case "alert";
$entry['html_row_class'] = "error";
$entry['event_class'] = "error";
break;
case "ignore";
default:
$entry['html_row_class'] = "ignore";
$entry['event_class'] = "ignore";
break;
}
switch ($entry['event']) {
case "ok";
$entry['html_row_class'] = "up";
$entry['event_class'] = "success";
break;
case "warn";
$entry['html_row_class'] = "warning";
$entry['event_class'] = "warning";
break;
case "alert";
$entry['html_row_class'] = "error";
$entry['event_class'] = "error";
break;
case "ignore";
default:
$entry['html_row_class'] = "ignore";
$entry['event_class'] = "ignore";
break;
}
$event = '<span class="label label-' . $entry['event_class'] . '">' . $entry['event'] . '</span>';
$event = '<span class="label label-' . $entry['event_class'] . '">' . $entry['event'] . '</span>';
echo '
<tr class="' . $entry['html_row_class'] . '">
<td class="state-marker"></td>
<td><i class="' . $config['entities']['device']['icon'] . '"></i> <b>' . generate_device_link($entry) . '</b></td>';
if(!isset($vars['oid_id']))
{
echo '
<td>'.generate_oid_template_link($entry).'</td> ';
} else {
<tr class="' . $entry['html_row_class'] . '">
<td class="state-marker"></td>
<td><i class="' . $config['entities']['device']['icon'] . '"></i> <b>' .
generate_device_link($entry, NULL, [ 'tab' => 'graphs', 'group' => 'custom' ]) . '</b></td>';
if (!isset($vars['oid_id'])) {
echo '
<td>' . generate_oid_template_link($entry) . '</td> ';
} else {
echo '
<td></td>';
}
echo '
<td></td>';
}
<td>' . $mini_graph . '</td>
<td>' . $thresholds . '</td>
<td><span class="label label-' . $entry['event_class'] . '">' . $entry['human_value'] . '</span></td>
<td>' . $event . '</td>
';
echo '
<td>' . $mini_graph . '</td>
<td>' . $thresholds . '</td>
<td><span class="label label-' . $entry['event_class'] . '">' . $entry['human_value'] . '</span></td>
<td>' . $event . '</td>
';
if ($entries[0]['oid_autodiscover'] == '0' && $vars['page'] == "customoid") {
if ($entries[0]['oid_autodiscover'] == '0' && $vars['page'] == "customoid") {
$form = array('type' => 'simple',
//'userlevel' => 10, // Minimum user level for display form
'id' => 'delete_customoid_device_' . $entry['device_id'],
'style' => 'display:inline;',
);
$form['row'][0]['form_oid_id'] = array(
'type' => 'hidden',
'value' => $entry['oid_id']);
$form['row'][0]['form_device_id'] = array(
'type' => 'hidden',
'value' => $entry['device_id']);
$form = ['type' => 'simple',
//'userlevel' => 10, // Minimum user level for display form
'id' => 'delete_customoid_device_' . $entry['device_id'],
'style' => 'display:inline;',
];
$form['row'][0]['form_oid_id'] = [
'type' => 'hidden',
'value' => $entry['oid_id']];
$form['row'][0]['form_device_id'] = [
'type' => 'hidden',
'value' => $entry['device_id']];
$form['row'][99]['action'] = array(
'type' => 'submit',
'icon_only' => TRUE, // hide button styles
'name' => '',
'icon' => $config['icon']['cancel'],
//'right' => TRUE,
//'class' => 'btn-small',
// confirmation dialog
'attribs' => array('data-toggle' => 'confirm', // Enable confirmation dialog
'data-confirm-placement' => 'left',
'data-confirm-content' => 'Delete associated device "' . escape_html($entry['hostname']) . '"?',
),
'value' => 'delete_customoid_device');
$form['row'][99]['action'] = [
'type' => 'submit',
'icon_only' => TRUE, // hide button styles
'name' => '',
'icon' => $config['icon']['cancel'],
//'right' => TRUE,
//'class' => 'btn-small',
// confirmation dialog
'attribs' => ['data-toggle' => 'confirm', // Enable confirmation dialog
'data-confirm-placement' => 'left',
'data-confirm-content' => 'Delete associated device "' . escape_html($entry['hostname']) . '"?',
],
'value' => 'delete_customoid_device'];
echo('<td>');
print_form($form);
unset($form);
echo('</td>');
}
echo('<td>');
print_form($form);
unset($form);
echo('</td>');
}
echo '
</tr>';
echo '
</tr>';
if ($vars['graphs'] == "yes")
{
$vars['graph'] = "graph";
}
if ($vars['graphs'] == "yes") {
$vars['graph'] = "graph";
}
if ($vars['graph'])
{
$graph_array = array();
$graph_title = $entry['oid_descr'];
$graph_array['type'] = "customoid_".$vars['graph'];
$graph_array['id'] = $entry['oid_entry_id'];
if ($vars['graph']) {
$graph_array = [];
$graph_array['title'] = $entry['oid_descr'];
$graph_array['type'] = "customoid_" . $vars['graph'];
$graph_array['id'] = $entry['oid_entry_id'];
echo '<tr><td colspan=8>';
print_graph_row($graph_array);
echo '</td></tr>';
}
echo '<tr><td colspan=8>';
print_graph_row($graph_array);
echo '</td></tr>';
}
}
echo ' </table>' . PHP_EOL;
echo generate_box_close();
} else {
echo '<p class="text-center text-warning bg-warning" style="padding: 10px; margin: 0;"><strong>This Custom OID is not currently associated with any devices</strong></p>';
}
}
// EOF

View File

@ -4,49 +4,49 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @package observium
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
function generate_p2pradio_query($vars)
{
$sql = "SELECT * FROM `p2p_radios`";
$sql .= ' WHERE 1' . generate_query_permitted(array('device'));
$sql = "SELECT * FROM `p2p_radios`";
$sql .= ' WHERE 1' . generate_query_permitted(['device']);
// Build query
foreach($vars as $var => $value)
{
switch ($var)
{
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'radio_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'p2p_radios.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'device_id');
break;
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'radio_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'p2p_radios.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'device_id');
break;
}
}
}
return $sql;
return $sql;
}
function print_p2pradio_table_header($vars)
{
echo('<thead><tr>
echo('<thead><tr>
<th class="state-marker"></th>
<th width="1"></th>');
if ($vars['page'] != "device" && $vars['popup'] != TRUE) { echo(' <th style="width: 200px;">Device</th>'); }
echo('
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
echo(' <th style="width: 200px;">Device</th>');
}
echo('
<th>Radio</th>
<th>Modulation</th>
<th>Capacity</th>
@ -62,58 +62,58 @@ function print_p2pradio_table_header($vars)
function print_p2pradio_row($radio, $vars)
{
echo generate_p2pradio_row($radio, $vars);
echo generate_p2pradio_row($radio, $vars);
}
function print_p2pradio_table($vars)
{
if ($vars['view'] == "graphs" || isset($vars['graph']))
{
$stripe_class = "table-striped-two";
} else {
$stripe_class = "table-striped";
}
if ($vars['view'] == "graphs" || isset($vars['graph'])) {
$stripe_class = "table-striped-two";
} else {
$stripe_class = "table-striped";
}
echo generate_box_open();
echo generate_box_open();
echo '<table class="table table-hover '.$stripe_class.' table-condensed">';
echo '<table class="table table-hover ' . $stripe_class . ' table-condensed">';
print_p2pradio_table_header($vars);
print_p2pradio_table_header($vars);
$sql = generate_p2pradio_query($vars);
$sql = generate_p2pradio_query($vars);
$radios = dbFetchRows($sql);
$radios = dbFetchRows($sql);
foreach($radios as $radio)
{
print_p2pradio_row($radio, $vars);
}
foreach ($radios as $radio) {
print_p2pradio_row($radio, $vars);
}
echo('</table>');
echo('</table>');
echo generate_box_close();
echo generate_box_close();
}
function generate_p2pradio_row($radio, $vars)
{
global $config;
global $config;
$device = device_by_id_cache($radio['device_id']);
$device = device_by_id_cache($radio['device_id']);
$table_cols = 12;
if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $table_cols++; } // Add a column for device.
$table_cols = 12;
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
$table_cols++;
} // Add a column for device.
$row .= '<tr class="' . $radio['row_class'] . '">
$row .= '<tr class="' . $radio['row_class'] . '">
<td class="state-marker"></td>
<td></td>';
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
$row .=('<td class="entity">' . generate_device_link_short($device) . '</td>');
}
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
$row .= ('<td class="entity">' . generate_device_link_short($device) . '</td>');
}
$row .= '
$row .= '
<td class="entity">' . generate_entity_link('p2pradio', $radio) . '</td>
<td width="100"><span class="label">' . strtoupper($radio['radio_modulation']) . '</span></td>
<td width="90">' . format_si($radio['radio_cur_capacity']) . 'bps</td>
@ -125,37 +125,38 @@ function generate_p2pradio_row($radio, $vars)
<td width="90"><span class="label label-success">' . ($radio['radio_tx_freq'] / 1000000) . 'GHz</span></td>
<td width="90"><span class="label label-info">' . ($radio['radio_rx_freq'] / 1000000) . 'GHz</span></td>
';
$row .= '</tr>';
$row .= '</tr>';
if ($vars['view'] == "graphs")
{
$graphs = array('capacity', 'power', 'rxlevel', 'gain', 'rmse', 'symbol_rates');
$show_graph_title = TRUE;
} elseif (isset($vars['graph'])) { $graphs = explode(",", $vars['graph']); }
if (is_array($graphs))
{
$row .= '<tr class="' . $radio['row_class'] . '">';
$row .= '<td class="state-marker"></td>';
$row .= '<td colspan=' . $table_cols . '>';
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $radio['radio_id'];
foreach($graphs as $graph_type)
{
$graph_array['type'] = 'p2pradio_' . $graph_type;
if ($show_graph_title) { $row .= '<h3>'.$config['graph_types']['p2pradio'][$graph_type]['name'].'</h3>'; }
$row .= generate_graph_row($graph_array, TRUE);
if ($vars['view'] == "graphs") {
$graphs = ['capacity', 'power', 'rxlevel', 'gain', 'rmse', 'symbol_rates'];
$show_graph_title = TRUE;
} elseif (isset($vars['graph'])) {
$graphs = explode(",", $vars['graph']);
}
$row .= "</td>";
$row .= "</tr>";
}
return $row;
if (is_array($graphs)) {
$row .= '<tr class="' . $radio['row_class'] . '">';
$row .= '<td class="state-marker"></td>';
$row .= '<td colspan=' . $table_cols . '>';
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = get_time();
$graph_array['id'] = $radio['radio_id'];
foreach ($graphs as $graph_type) {
$graph_array['type'] = 'p2pradio_' . $graph_type;
if ($show_graph_title) {
$row .= '<h3>' . $config['graph_types']['p2pradio'][$graph_type]['name'] . '</h3>';
}
$row .= generate_graph_row($graph_array, TRUE);
}
$row .= "</td>";
$row .= "</tr>";
}
return $row;
}

File diff suppressed because it is too large Load Diff

View File

@ -6,324 +6,314 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
function build_printersupplies_query($vars)
{
$sql = 'SELECT * FROM `printersupplies`';
$sql .= ' WHERE 1' . generate_query_permitted(array('device'));
$sql = 'SELECT * FROM `printersupplies`';
$sql .= ' WHERE 1' . generate_query_permitted(['device']);
// Build query
foreach($vars as $var => $value)
{
switch ($var)
{
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'printersupplies.supply_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'printersupplies.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'printersupplies.device_id');
break;
case "supply":
case "supply_type";
$sql .= generate_query_values_and($value, 'printersupplies.supply_type');
break;
case "colour":
case "supply_colour";
$sql .= generate_query_values_and($value, 'supply_colour');
break;
case "descr":
case "supply_descr";
$sql .= generate_query_values_and($value, 'supply_descr', '%LIKE%');
break;
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'printersupplies.supply_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'printersupplies.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'printersupplies.device_id');
break;
case "supply":
case "supply_type";
$sql .= generate_query_values_and($value, 'printersupplies.supply_type');
break;
case "colour":
case "supply_colour";
$sql .= generate_query_values_and($value, 'supply_colour');
break;
case "descr":
case "supply_descr";
$sql .= generate_query_values_and($value, 'supply_descr', '%LIKE%');
break;
}
}
}
return $sql;
return $sql;
}
function print_printersupplies_table($vars)
{
$supplies = array();
foreach(dbFetchRows(build_printersupplies_query($vars)) as $supply)
{
global $cache;
$supplies = [];
if (isset($cache['devices']['id'][$supply['device_id']]))
{
$supply['hostname'] = $cache['devices']['id'][$supply['device_id']]['hostname'];
$supply['html_row_class'] = $cache['devices']['id'][$supply['device_id']]['html_row_class'];
$supplies[] = $supply;
$query = build_printersupplies_query($vars);
foreach (dbFetchRows($query) as $supply) {
global $cache;
if ($device = device_by_id_cache($supply['device_id'])) {
$supply['hostname'] = $device[$supply['device_id']]['hostname'];
$supply['html_row_class'] = $device[$supply['device_id']]['html_row_class'];
$supplies[] = $supply;
}
}
}
$supplies = array_sort_by($supplies, 'hostname', SORT_ASC, SORT_STRING, 'supply_descr', SORT_ASC, SORT_STRING);
$supplies_count = count($supplies);
echo generate_box_open();
$supplies = array_sort_by($supplies, 'hostname', SORT_ASC, SORT_STRING, 'supply_descr', SORT_ASC, SORT_STRING);
$supplies_count = count($supplies);
// Pagination
$pagination_html = pagination($vars, $supplies_count);
echo $pagination_html;
echo generate_box_open();
if ($vars['pageno'])
{
$supplies = array_chunk($supplies, $vars['pagesize']);
$supplies = $supplies[$vars['pageno'] - 1];
}
// End Pagination
// Pagination
$pagination_html = pagination($vars, $supplies_count);
echo $pagination_html;
if ($vars['view'] == "graphs")
{
$stripe_class = "table-striped-two";
} else {
$stripe_class = "table-striped";
}
// Allow the table to be printed headerless for use in some places.
if ($vars['headerless'] != TRUE)
{
echo('<table class="table ' . $stripe_class . ' table-condensed">');
echo(' <thead>');
echo '<tr class="strong">';
echo '<th class="state-marker"></th>';
if ($vars['page'] != "device" && $vars['popup'] != TRUE)
{
echo(' <th style="width: 250px;">Device</th>');
if ($vars['pageno']) {
$supplies = array_chunk($supplies, $vars['pagesize']);
$supplies = $supplies[$vars['pageno'] - 1];
}
echo '<th>Toner</th>';
if (!isset($vars['supply']))
{
echo '<th>Type</th>';
// End Pagination
if ($vars['view'] == "graphs") {
$stripe_class = "table-striped-two";
} else {
$stripe_class = "table-striped";
}
echo '<th></th>';
echo '<th>Level</th>';
echo '<th>Remaining</th>';
echo '</tr>';
echo '</thead>';
}
// Allow the table to be printed headerless for use in some places.
if ($vars['headerless'] != TRUE) {
echo('<table class="table ' . $stripe_class . ' table-condensed">');
echo(' <thead>');
foreach($supplies as $supply)
{
print_printersupplies_row($supply, $vars);
}
echo '<tr class="strong">';
echo '<th class="state-marker"></th>';
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
echo(' <th style="width: 250px;">Device</th>');
}
echo '<th>Toner</th>';
if (!isset($vars['supply'])) {
echo '<th>Type</th>';
}
echo '<th></th>';
echo '<th>Level</th>';
echo '<th>Remaining</th>';
echo '</tr>';
echo("</table>");
echo '</thead>';
}
echo generate_box_close();
foreach ($supplies as $supply) {
print_printersupplies_row($supply, $vars);
}
echo $pagination_html;
echo("</table>");
echo generate_box_close();
echo $pagination_html;
}
function print_printersupplies_row($supply, $vars)
{
echo generate_printersupplies_row($supply, $vars);
echo generate_printersupplies_row($supply, $vars);
}
function generate_printersupplies_row($supply, $vars)
{
$graph_type = "printersupply_usage";
$graph_type = "printersupply_usage";
$table_cols = 5;
$table_cols = 5;
$total = $supply['supply_capacity'];
$perc = $supply['supply_value'];
$total = $supply['supply_capacity'];
$perc = $supply['supply_value'];
$graph_array['type'] = $graph_type;
$graph_array['id'] = $supply['supply_id'];
$graph_array['from'] = $GLOBALS['config']['time']['day'];
$graph_array['to'] = $GLOBALS['config']['time']['now'];
$graph_array['height'] = "20";
$graph_array['width'] = "80";
$graph_array['type'] = $graph_type;
$graph_array['id'] = $supply['supply_id'];
$graph_array['from'] = get_time('day');
$graph_array['to'] = get_time();
$graph_array['height'] = "20";
$graph_array['width'] = "80";
if ($supply['supply_colour'] != '')
{
$background = toner_to_colour($supply['supply_colour'], $perc);
} else {
$background = toner_to_colour($supply['supply_descr'], $perc);
}
if ($supply['supply_colour'] != '') {
$background = toner_to_colour($supply['supply_colour'], $perc);
} else {
$background = toner_to_colour($supply['supply_descr'], $perc);
}
/// FIXME - popup for printersupply entity.
/// FIXME - popup for printersupply entity.
$output = '<tr class="' . $supply['html_row_class'] . '">';
$output .= '<td class="state-marker"></td>';
if ($vars['popup'] == TRUE )
{
$output .= '<td style="width: 40px; text-align: center;">'.get_icon($GLOBALS['config']['entities']['printersupply']['icon']).'</td>';
} else {
//$output .= '<td style="width: 1px;"></td>';
}
if ($vars['page'] != "device" && $vars['popup'] != TRUE)
{
$output .= '<td class="entity">' . generate_device_link($supply) . '</td>';
$table_cols++;
}
$output .= '<td class="entity">' . generate_entity_link('printersupply', $supply) . '</td>';
if (!isset($vars['supply']))
{
$output .= '<td><span class="label">' . nicecase($supply['supply_type']) . '</label></td>';
}
$output .= '<td style="width: 70px;">' . generate_graph_popup($graph_array) . '</td>';
$output .= '<td style="width: 200px;">' . print_percentage_bar(400, 20, $perc, $perc . '%', 'ffffff', $background['right'], NULL, "ffffff", $background['left']) . '</td>';
if ($vars['popup'] != TRUE)
{
$output .= '<td style="width: 50px; text-align: right;"><span class="label">' . $perc . '%</span></td>';
}
$output .= '</tr>';
if ($vars['view'] == "graphs")
{
$output .= '<tr class="' . $supply['html_row_class'] . '">';
$output = '<tr class="' . $supply['html_row_class'] . '">';
$output .= '<td class="state-marker"></td>';
$output .= '<td colspan='.$table_cols.'>';
if ($vars['popup'] == TRUE) {
$output .= '<td style="width: 40px; text-align: center;">' . get_icon($GLOBALS['config']['entities']['printersupply']['icon']) . '</td>';
} else {
//$output .= '<td style="width: 1px;"></td>';
}
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $supply['supply_id'];
$graph_array['type'] = $graph_type;
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
$output .= '<td class="entity">' . generate_device_link($supply) . '</td>';
$table_cols++;
}
$output .= '<td class="entity">' . generate_entity_link('printersupply', $supply) . '</td>';
$output .= generate_graph_row($graph_array, TRUE);
if (!isset($vars['supply'])) {
$output .= '<td><span class="label">' . nicecase($supply['supply_type']) . '</label></td>';
}
$output .= "</td></tr>";
} # endif graphs
$output .= '<td style="width: 70px;">' . generate_graph_popup($graph_array) . '</td>';
$output .= '<td style="width: 200px;">' . print_percentage_bar(400, 20, $perc, $perc . '%', 'ffffff', $background['right'], NULL, "ffffff", $background['left']) . '</td>';
if ($vars['popup'] != TRUE) {
$output .= '<td style="width: 50px; text-align: right;"><span class="label">' . $perc . '%</span></td>';
}
$output .= '</tr>';
return $output;
if ($vars['view'] == "graphs") {
$output .= '<tr class="' . $supply['html_row_class'] . '">';
$output .= '<td class="state-marker"></td>';
$output .= '<td colspan=' . $table_cols . '>';
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = get_time();
$graph_array['id'] = $supply['supply_id'];
$graph_array['type'] = $graph_type;
$output .= generate_graph_row($graph_array, TRUE);
$output .= "</td></tr>";
} # endif graphs
return $output;
}
function print_printersupplies_form($vars, $single_device = FALSE)
{
global $config;
global $config;
$form = array('type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
$form = ['type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
$form_items = array();
$form_items = [];
if ($single_device)
{
// Single device, just hidden field
$form['row'][0]['device_id'] = array(
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%');
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `printersupplies`'));
if ($single_device) {
// Single device, just hidden field
$form['row'][0]['device_id'] = [
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%'];
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `printersupplies`'));
$form['row'][0]['device_id'] = array(
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
$form['row'][0]['device_id'] = [
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']];
}
//$sensor_permitted = generate_query_permitted(array('device', 'sensor'));
$form['row'][0]['supply_descr'] = [
'type' => 'text',
'placeholder' => 'Toner',
'width' => '100%', //'180px',
'values' => $form_items['devices']);
}
'grid' => 3,
'value' => $vars['status_descr']];
//$sensor_permitted = generate_query_permitted(array('device', 'sensor'));
$form['row'][0]['supply_descr'] = array(
'type' => 'text',
'placeholder' => 'Toner',
'width' => '100%', //'180px',
'grid' => 3,
'value' => $vars['status_descr']);
foreach (['supply_colour' => 'Colour', 'supply_type' => 'Type'] as $param => $param_name) {
$sql = 'SELECT DISTINCT `' . $param . '` FROM `printersupplies` WHERE ' . $GLOBALS['cache']['where']['devices_permitted'];
if ($entries = dbFetchColumn($sql)) {
asort($entries);
}
foreach ($entries as $entry) {
if (safe_empty($entry)) {
$entry = OBS_VAR_UNSET;
}
$name = nicecase($entry);
$form_items[$param][$entry] = $name;
}
foreach ([ 'supply_colour' => 'Colour', 'supply_type' => 'Type' ] as $param => $param_name) {
$sql = 'SELECT DISTINCT `'.$param.'` FROM `printersupplies` WHERE 1' . $GLOBALS['cache']['where']['devices_permitted'];
if ($entries = dbFetchColumn($sql)) {
asort($entries);
}
foreach ($entries as $entry) {
if (safe_empty($entry)) { $entry = OBS_VAR_UNSET; }
$name = nicecase($entry);
$form_items[$param][$entry] = $name;
$form['row'][0][$param] = [
'type' => 'multiselect',
'name' => $param_name,
'width' => '100%', //'180px',
'grid' => $param === 'supply_colour' ? 1 : 2,
'value' => $vars[$param],
'values' => $form_items[$param]];
}
$form['row'][0][$param] = array(
'type' => 'multiselect',
'name' => $param_name,
'width' => '100%', //'180px',
'grid' => $param === 'supply_colour' ? 1: 2,
'value' => $vars[$param],
'values' => $form_items[$param]);
}
// Groups
foreach (get_type_groups('printersupply') as $entry)
{
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
$form['row'][0]['group'] = array(
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']);
$form['row'][0]['search'] = array(
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
);
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
// Custom panel form
$panel_form = array('type' => 'rows',
'title' => 'Search Sensors',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) { unset($form['row'][$row][$param]['grid']); }
// Groups
foreach (get_type_groups('printersupply') as $entry) {
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
}
$form['row'][0]['group'] = [
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']];
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['group'] = $form['row'][0]['group'];
$form['row'][0]['search'] = [
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
];
$panel_form['row'][1]['supply_colour'] = $form['row'][0]['supply_colour'];
$panel_form['row'][1]['supply_type'] = $form['row'][0]['supply_type'];
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
//$panel_form['row'][2]['measured_state'] = $form['row'][0]['measured_state'];
//$panel_form['row'][2]['group'] = $form['row'][1]['group'];
// Custom panel form
$panel_form = ['type' => 'rows',
'title' => 'Search Sensors',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
$panel_form['row'][3]['supply_descr'] = $form['row'][0]['supply_descr'];
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) {
unset($form['row'][$row][$param]['grid']);
}
}
}
//$panel_form['row'][5]['sort'] = $form['row'][0]['sort'];
$panel_form['row'][5]['search'] = $form['row'][0]['search'];
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['group'] = $form['row'][0]['group'];
// Register custom panel
register_html_panel(generate_form($panel_form));
$panel_form['row'][1]['supply_colour'] = $form['row'][0]['supply_colour'];
$panel_form['row'][1]['supply_type'] = $form['row'][0]['supply_type'];
//$panel_form['row'][2]['measured_state'] = $form['row'][0]['measured_state'];
//$panel_form['row'][2]['group'] = $form['row'][1]['group'];
$panel_form['row'][3]['supply_descr'] = $form['row'][0]['supply_descr'];
//$panel_form['row'][5]['sort'] = $form['row'][0]['sort'];
$panel_form['row'][5]['search'] = $form['row'][0]['search'];
// Register custom panel
register_html_panel(generate_form($panel_form));
}
// EOF

View File

@ -4,335 +4,312 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @package observium
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
function generate_processor_query($vars)
{
$sql = "SELECT * FROM `processors`";
if(!isset($vars['sort']) || $vars['sort'] == 'hostname' || $vars['sort'] == 'device' || $vars['sort'] == 'device_id')
{
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
}
$sql .= ' WHERE 1' . generate_query_permitted(array('device'));
// Build query
foreach($vars as $var => $value)
{
switch ($var)
{
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'processor_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'processors.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'processors.device_id');
break;
case "descr":
case "processor_descr";
$sql .= generate_query_values_and($value, 'processor_descr', '%LIKE%');
break;
$sql = "SELECT * FROM `processors`";
if (!isset($vars['sort']) || $vars['sort'] == 'hostname' || $vars['sort'] == 'device' || $vars['sort'] == 'device_id') {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
}
}
$sql .= ' WHERE ' . generate_query_permitted_ng(['device']);
switch ($vars['sort_order'])
{
case 'descr':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
}
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'processor_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'processors.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'processors.device_id');
break;
case "descr":
case "processor_descr";
$sql .= generate_query_values_and($value, 'processor_descr', '%LIKE%');
break;
}
}
switch($vars['sort'])
{
case 'usage':
$sql .= ' ORDER BY `processor_usage` '.$sort_neg;
break;
case 'descr':
$sql .= ' ORDER BY `processor_descr` '.$sort_order;
break;
default:
$sql .= ' ORDER BY `hostname` '.$sort_order.', `processor_descr` '.$sort_order;
break;
}
switch ($vars['sort_order']) {
case 'descr':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
}
return $sql;
switch ($vars['sort']) {
case 'usage':
$sql .= ' ORDER BY `processor_usage` ' . $sort_neg;
break;
case 'descr':
$sql .= ' ORDER BY `processor_descr` ' . $sort_order;
break;
default:
$sql .= ' ORDER BY `hostname` ' . $sort_order . ', `processor_descr` ' . $sort_order;
break;
}
return $sql;
}
function print_processor_table($vars)
{
global $cache;
$sql = generate_processor_query($vars);
$sql = generate_processor_query($vars);
$processors = array();
foreach(dbFetchRows($sql) as $proc)
{
if (isset($cache['devices']['id'][$proc['device_id']]))
{
$proc['hostname'] = $cache['devices']['id'][$proc['device_id']]['hostname'];
$proc['html_row_class'] = $cache['devices']['id'][$proc['device_id']]['html_row_class'];
$processors[] = $proc;
$processors = dbFetchRows($sql);
$processors_count = safe_count($processors);
// Pagination
$pagination_html = pagination($vars, $processors_count);
echo $pagination_html;
if ($vars['pageno']) {
$processors = array_chunk($processors, $vars['pagesize']);
$processors = $processors[$vars['pageno'] - 1];
}
}
// End Pagination
$processors_count = count($processors);
echo generate_box_open();
// Pagination
$pagination_html = pagination($vars, $processors_count);
echo $pagination_html;
print_processor_table_header($vars);
if ($vars['pageno'])
{
$processors = array_chunk($processors, $vars['pagesize']);
$processors = $processors[$vars['pageno']-1];
}
// End Pagination
foreach ($processors as $processor) {
print_processor_row($processor, $vars);
}
echo generate_box_open();
echo("</tbody></table>");
print_processor_table_header($vars);
echo generate_box_close();
foreach($processors as $processor)
{
print_processor_row($processor, $vars);
}
echo("</tbody></table>");
echo generate_box_close();
echo $pagination_html;
echo $pagination_html;
}
function print_processor_table_header($vars)
{
if ($vars['view'] == "graphs")
{
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
if ($vars['view'] == "graphs") {
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = array(
array(NULL, 'class="state-marker"'),
'device' => array('Device', 'style="width: 200px;"'),
'descr' => array('Processor'),
array('', 'style="width: 100px;"'),
'usage' => array('Usage', 'style="width: 250px;"'),
);
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = [
[NULL, 'class="state-marker"'],
'device' => ['Device', 'style="width: 200px;"'],
'descr' => ['Processor'],
['', 'style="width: 100px;"'],
'usage' => ['Usage', 'style="width: 250px;"'],
];
if ($vars['page'] == "device")
{
unset($cols['device']);
}
if ($vars['page'] == "device") {
unset($cols['device']);
}
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
}
function print_processor_row($processor, $vars)
{
echo generate_processor_row($processor, $vars);
echo generate_processor_row($processor, $vars);
}
function generate_processor_row($processor, $vars)
{
global $config;
global $config;
$table_cols = 4;
if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $table_cols++; } // Add a column for device.
$table_cols = 4;
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
$table_cols++;
} // Add a column for device.
// FIXME should that really be done here? :-)
// FIXME - not it shouldn't. we need some per-os rewriting on discovery-time.
$text_descr = rewrite_entity_name($processor['processor_descr'], 'processor');
//$text_descr = $processor['processor_descr'];
//$text_descr = str_replace("Routing Processor", "RP", $text_descr);
//$text_descr = str_replace("Switching Processor", "SP", $text_descr);
//$text_descr = str_replace("Sub-Module", "Module ", $text_descr);
//$text_descr = str_replace("DFC Card", "DFC", $text_descr);
// FIXME should that really be done here? :-)
// FIXME - not it shouldn't. we need some per-os rewriting on discovery-time.
$text_descr = rewrite_entity_name($processor['processor_descr'], 'processor');
//$text_descr = $processor['processor_descr'];
//$text_descr = str_replace("Routing Processor", "RP", $text_descr);
//$text_descr = str_replace("Switching Processor", "SP", $text_descr);
//$text_descr = str_replace("Sub-Module", "Module ", $text_descr);
//$text_descr = str_replace("DFC Card", "DFC", $text_descr);
$graph_array = array();
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $processor['processor_id'];
$graph_array['type'] = 'processor_usage';
$graph_array['legend'] = "no";
$graph_array = [];
$graph_array['to'] = get_time();
$graph_array['id'] = $processor['processor_id'];
$graph_array['type'] = 'processor_usage';
$graph_array['legend'] = "no";
$link_array = $graph_array;
$link_array['page'] = "graphs";
unset($link_array['height'], $link_array['width'], $link_array['legend']);
$link_graph = generate_url($link_array);
$link_array = $graph_array;
$link_array['page'] = "graphs";
unset($link_array['height'], $link_array['width'], $link_array['legend']);
$link_graph = generate_url($link_array);
$link = generate_url(array("page" => "device", "device" => $processor['device_id'], "tab" => "health", "metric" => 'processor'));
$link = generate_url(["page" => "device", "device" => $processor['device_id'], "tab" => "health", "metric" => 'processor']);
$overlib_content = generate_overlib_content($graph_array, $processor['hostname'] ." - " . $text_descr);
$overlib_content = generate_overlib_content($graph_array, $processor['hostname'] . " - " . $text_descr);
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = $config['time']['day'];
$mini_graph = generate_graph_tag($graph_array);
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = get_time('day');
$mini_graph = generate_graph_tag($graph_array);
$perc = round($processor['processor_usage']);
$background = get_percentage_colours($perc);
$perc = round($processor['processor_usage']);
$background = get_percentage_colours($perc);
$processor['html_row_class'] = $background['class'];
$processor['html_row_class'] = $background['class'];
$row = '<tr class="' . $processor['html_row_class'] . '">
$row = '<tr class="' . $processor['html_row_class'] . '">
<td class="state-marker"></td>';
if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $row .= '<td class="entity">' . generate_device_link($processor) . '</td>'; }
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
$row .= '<td class="entity">' . generate_device_link($processor) . '</td>';
}
$row .= ' <td class="entity">'.generate_entity_link('processor', $processor).'</td>
<td>'.overlib_link($link_graph, $mini_graph, $overlib_content).'</td>
<td><a href="'.$link_graph.'">
'.print_percentage_bar (400, 20, $perc, $perc."%", "ffffff", $background['left'], (100 - $perc)."%" , "ffffff", $background['right']).'
$row .= ' <td class="entity">' . generate_entity_link('processor', $processor) . '</td>
<td>' . overlib_link($link_graph, $mini_graph, $overlib_content) . '</td>
<td><a href="' . $link_graph . '">
' . print_percentage_bar(400, 20, $perc, $perc . "%", "ffffff", $background['left'], (100 - $perc) . "%", "ffffff", $background['right']) . '
</a>
</td>
</tr>
';
if ($vars['view'] == "graphs" || in_array($processor['processor_id'], (array)$vars['processor_id']))
{
if ($vars['view'] == "graphs" || in_array($processor['processor_id'], (array)$vars['processor_id'])) {
$vars['graph'] = "usage";
$vars['graph'] = "usage";
$row .= '<tr class="' . $processor['html_row_class'] . '">';
$row .= '<td class="state-marker"></td>';
$row .= '<td colspan='.$table_cols.'>';
$row .= '<tr class="' . $processor['html_row_class'] . '">';
$row .= '<td class="state-marker"></td>';
$row .= '<td colspan=' . $table_cols . '>';
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $processor['processor_id'];
$graph_array['type'] = 'processor_'.$vars['graph'];
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = get_time();
$graph_array['id'] = $processor['processor_id'];
$graph_array['type'] = 'processor_' . $vars['graph'];
$row .= generate_graph_row($graph_array, TRUE);
$row .= generate_graph_row($graph_array, TRUE);
$row .= '</td></tr>';
} # endif graphs
$row .= '</td></tr>';
} # endif graphs
return $row;
return $row;
}
function print_processor_form($vars, $single_device = FALSE)
{
//global $config;
//global $config;
$form = array('type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
$form = ['type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
$form_items = array();
$form_items = [];
if ($single_device)
{
// Single device, just hidden field
$form['row'][0]['device_id'] = array(
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%');
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `processors`'));
if ($single_device) {
// Single device, just hidden field
$form['row'][0]['device_id'] = [
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%'];
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `processors`'));
$form['row'][0]['device_id'] = array(
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']);
}
//$sensor_permitted = generate_query_permitted(array('device', 'sensor'));
$form['row'][0]['processor_descr'] = array(
'type' => 'text',
'placeholder' => 'Processor',
'width' => '100%', //'180px',
'grid' => 6,
'value' => $vars['processor_descr']);
// Groups
foreach (get_type_groups('storage') as $entry)
{
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
$form['row'][0]['group'] = array(
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']);
$form['row'][0]['search'] = array(
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
);
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
// Custom panel form
$panel_form = array('type' => 'rows',
'title' => 'Search Processors',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) { unset($form['row'][$row][$param]['grid']); }
$form['row'][0]['device_id'] = [
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']];
}
}
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['group'] = $form['row'][0]['group'];
//$sensor_permitted = generate_query_permitted(array('device', 'sensor'));
$form['row'][0]['processor_descr'] = [
'type' => 'text',
'placeholder' => 'Processor',
'width' => '100%', //'180px',
'grid' => 6,
'value' => $vars['processor_descr']];
//$panel_form['row'][1]['supply_colour'] = $form['row'][0]['supply_colour'];
//$panel_form['row'][1]['supply_type'] = $form['row'][0]['supply_type'];
// Groups
foreach (get_type_groups('processor') as $entry) {
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
$form['row'][0]['group'] = [
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']];
//$panel_form['row'][2]['measured_state'] = $form['row'][0]['measured_state'];
//$panel_form['row'][2]['group'] = $form['row'][1]['group'];
$form['row'][0]['search'] = [
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
];
$panel_form['row'][3]['processor_descr'] = $form['row'][0]['processor_descr'];
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
//$panel_form['row'][5]['sort'] = $form['row'][0]['sort'];
$panel_form['row'][5]['search'] = $form['row'][0]['search'];
// Custom panel form
$panel_form = ['type' => 'rows',
'title' => 'Search Processors',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
// Register custom panel
register_html_panel(generate_form($panel_form));
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) {
unset($form['row'][$row][$param]['grid']);
}
}
}
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['group'] = $form['row'][0]['group'];
$panel_form['row'][3]['processor_descr'] = $form['row'][0]['processor_descr'];
$panel_form['row'][5]['search'] = $form['row'][0]['search'];
// Register custom panel
register_html_panel(generate_form($panel_form));
}
// EOF

View File

@ -4,351 +4,446 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @package observium
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
function generate_pseudowire_query($vars)
{
$sql = 'SELECT * FROM `pseudowires` ';
$sql .= ' WHERE 1';
$sql = 'SELECT * FROM `pseudowires` ';
// Build query
foreach ($vars as $var => $value)
{
switch ($var)
{
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'pseudowire_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'device_id');
break;
case "port":
case "port_id":
$sql .= generate_query_values_and($value, 'port_id');
break;
case "id":
$sql .= generate_query_values_and($value, 'pseudowire_id');
break;
case "pwid":
case "pwID":
$sql .= generate_query_values_and($value, 'pwID');
break;
case "pwtype":
$sql .= generate_query_values_and($value, 'pwType');
break;
case "psntype":
$sql .= generate_query_values_and($value, 'pwPsnType');
break;
case "peer_id":
$sql .= generate_query_values_and($value, 'peer_device_id');
break;
case "peer_addr":
$sql .= generate_query_values_and($value, 'peer_addr');
break;
case "event":
$sql .= generate_query_values_and($value, 'event');
break;
$where = [];
$where[] = $GLOBALS['cache']['where']['devices_permitted'];
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$where[] = generate_query_values($values, 'pseudowire_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$where[] = generate_query_values($values, 'device_id');
break;
case "device":
case "device_id":
$where[] = generate_query_values($value, 'device_id');
break;
case "port":
case "port_id":
$where[] = generate_query_values($value, 'port_id');
break;
case "id":
$where[] = generate_query_values($value, 'pseudowire_id');
break;
case "pwid":
case "pwID":
$where[] = generate_query_values($value, 'pwID');
break;
case "pwtype":
$where[] = generate_query_values($value, 'pwType');
break;
case "psntype":
$where[] = generate_query_values($value, 'pwPsnType');
break;
case "peer_id":
$where[] = generate_query_values($value, 'peer_device_id');
break;
case "peer_addr":
$where[] = generate_query_values($value, 'peer_addr');
break;
case "event":
$where[] = generate_query_values($value, 'event');
break;
}
}
}
$sql .= $GLOBALS['cache']['where']['devices_permitted'];
return $sql;
$sql .= generate_where_clause($where);
return $sql;
}
function print_pseudowire_table_header($vars)
{
if ($vars['view'] == "graphs" || isset($vars['graph']) || isset($vars['id']))
{
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
if ($vars['view'] == "graphs" || isset($vars['graph']) || isset($vars['id'])) {
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = array(
array(NULL, 'class="state-marker"'),
'pwid' => array('pwID', 'style="width: 60px; text-align: right;"'),
'pwtype' => array('Type / PSN Type', 'style="width: 100px;"'),
'device' => array('Local Device', 'style="width: 180px;"'),
'port' => array('Local Port', 'style="width: 100px;"'),
array(NULL, 'style="width: 20px;"'), // arrow icon
'peer_addr' => array('Remote Peer', 'style="width: 180px;"'),
'peer_port' => array('Remote Port', 'style="width: 100px;"'),
array('History', 'style="width: 100px;"'),
'last_change' => array('Last&nbsp;changed', 'style="width: 60px;"'),
'event' => array('Event', 'style="width: 60px; text-align: right;"'),
'status' => array('Status', 'style="width: 60px; text-align: right;"'),
'uptime' => array('Uptime', 'style="width: 80px;"'),
);
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = [
[NULL, 'class="state-marker"'],
'pwid' => ['pwID', 'style="width: 60px; text-align: right;"'],
'pwtype' => ['Type / PSN Type', 'style="width: 100px;"'],
'device' => ['Local Device', 'style="width: 180px;"'],
'port' => ['Local Port', 'style="width: 100px;"'],
[NULL, 'style="width: 20px;"'], // arrow icon
'peer_addr' => ['Remote Peer', 'style="width: 180px;"'],
'peer_port' => ['Remote Port', 'style="width: 100px;"'],
['History', 'style="width: 100px;"'],
'last_change' => ['Last&nbsp;changed', 'style="width: 60px;"'],
'event' => ['Event', 'style="width: 60px; text-align: right;"'],
'status' => ['Status', 'style="width: 60px; text-align: right;"'],
'uptime' => ['Uptime', 'style="width: 80px;"'],
];
if ($vars['page'] == "device" || $vars['popup'] == TRUE)
{
unset($cols['device']);
}
if ($vars['page'] == "device" || $vars['popup'] == TRUE) {
unset($cols['device']);
}
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
}
function get_pseudowire_table($vars)
{
$sql = generate_pseudowire_query($vars);
$sql = generate_pseudowire_query($vars);
$entries = array();
foreach (dbFetchRows($sql) as $entry)
{
if (!isset($GLOBALS['cache']['devices']['id'][$entry['device_id']])) { continue; }
// Device hostname
$entry['hostname'] = $GLOBALS['cache']['devices']['id'][$entry['device_id']]['hostname'];
// Remote Peer
$peer_addr = $entry['peer_addr'];
$peer_addr_type = get_ip_version($peer_addr);
if ($peer_addr_type && $entry['peer_device_id'])
{
if ($peer_addr_type == 6)
{
$peer_addr = Net_IPv6::uncompress($peer_addr, TRUE);
}
$peer_addr_type = 'ipv'.$peer_addr_type;
//$entry['peer_addr'] = $peer_addr;
//$entry['peer_addr_type'] = $peer_addr_type;
if (!is_array($cache_pseudowires['ips'][$peer_addr]))
{
$cache_pseudowires['ips'][$peer_addr]['port_id'] = dbFetchCell('SELECT `port_id` FROM `'.$peer_addr_type.'_addresses` WHERE `'.$peer_addr_type.'_address` = ? '.generate_query_values_and($GLOBALS['cache']['ports']['pseudowires'], 'port_id').' LIMIT 1;', array($peer_addr));
if (!is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id']))
{
// Separate entry for find correct port
$cache_pseudowires['ips'][$peer_addr]['port_id_fix'] = dbFetchCell('SELECT `port_id` FROM `'.$peer_addr_type.'_addresses` WHERE `'.$peer_addr_type.'_address` = ? '.$GLOBALS['cache']['where']['ports_permitted'].' LIMIT 1;', array($peer_addr));
$entries = [];
foreach (dbFetchRows($sql) as $entry) {
if (!$device = device_by_id_cache($entry['device_id'])) {
continue;
}
//$cache_pseudowires['ips'][$peer_addr]['host'] = $entry['reverse_dns'];
}
$entry['peer_port_id'] = $cache_pseudowires['ips'][$peer_addr]['port_id'];
if (is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id_fix']))
{
// If we found port on remote device, than both devices in DB and will try to fix real port
$peer_port_tmp = get_port_by_id_cache($cache_pseudowires['ips'][$peer_addr]['port_id_fix']);
$peer_port_fix = dbFetchCell('SELECT `port_id` FROM `pseudowires` WHERE `device_id` = ? AND `pwID` = ? LIMIT 1;', array($peer_port_tmp['device_id'], $entry['pwID']));
if (is_numeric($peer_port_fix))
{
$entry['peer_port_id'] = $peer_port_fix;
} else {
$entry['peer_port_id'] = $cache_pseudowires['ips'][$peer_addr]['port_id_fix'];
// Device hostname
$entry['hostname'] = $device['hostname'];
// Remote Peer
$peer_addr = $entry['peer_addr'];
$peer_addr_type = get_ip_version($peer_addr);
if ($peer_addr_type && $entry['peer_device_id']) {
if ($peer_addr_type == 6) {
$peer_addr = Net_IPv6 ::uncompress($peer_addr, TRUE);
}
$peer_addr_type = 'ipv' . $peer_addr_type;
//$entry['peer_addr'] = $peer_addr;
//$entry['peer_addr_type'] = $peer_addr_type;
if (!is_array($cache_pseudowires['ips'][$peer_addr])) {
$cache_pseudowires['ips'][$peer_addr]['port_id'] = dbFetchCell('SELECT `port_id` FROM `' . $peer_addr_type . '_addresses` WHERE `' . $peer_addr_type . '_address` = ? ' . generate_query_values_and($GLOBALS['cache']['ports']['pseudowires'], 'port_id') . ' LIMIT 1;', [$peer_addr]);
if (!is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id'])) {
// Separate entry for find correct port
$cache_pseudowires['ips'][$peer_addr]['port_id_fix'] = dbFetchCell('SELECT `port_id` FROM `' . $peer_addr_type . '_addresses` ' . generate_where_clause($peer_addr_type . '_address` = ?', $GLOBALS['cache']['where']['ports_permitted']) . ' LIMIT 1;', [$peer_addr]);
}
//$cache_pseudowires['ips'][$peer_addr]['host'] = $entry['reverse_dns'];
}
$entry['peer_port_id'] = $cache_pseudowires['ips'][$peer_addr]['port_id'];
if (is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id_fix'])) {
// If we found port on remote device, than both devices in DB and will try to fix real port
$peer_port_tmp = get_port_by_id_cache($cache_pseudowires['ips'][$peer_addr]['port_id_fix']);
$peer_port_fix = dbFetchCell('SELECT `port_id` FROM `pseudowires` WHERE `device_id` = ? AND `pwID` = ? LIMIT 1;', [$peer_port_tmp['device_id'], $entry['pwID']]);
if (is_numeric($peer_port_fix)) {
$entry['peer_port_id'] = $peer_port_fix;
} else {
$entry['peer_port_id'] = $cache_pseudowires['ips'][$peer_addr]['port_id_fix'];
}
}
//r($entry['peer_port_id']);
if ($entry['peer_port_id']) {
$entry['peer_port'] = get_port_by_id_cache($entry['peer_port_id']);
//r($entry['peer_port']);
$entry['peer_device_id'] = $entry['peer_port']['device_id'];
//r($entry['peer_device_id']);
$entry['peer_device'] = device_by_id_cache($entry['peer_device_id']);
}
}
}
//r($entry['peer_port_id']);
if ($entry['peer_port_id'])
{
$entry['peer_port'] = get_port_by_id_cache($entry['peer_port_id']);
//r($entry['peer_port']);
$entry['peer_device_id'] = $entry['peer_port']['device_id'];
//r($entry['peer_device_id']);
$entry['peer_device'] = device_by_id_cache($entry['peer_device_id']);
}
$entries[] = $entry;
}
$entry['hostname'] = $GLOBALS['cache']['devices']['id'][$entry['device_id']]['hostname']; // Attach hostname for sorting
// Sorting
switch ($vars['sort_order']) {
case 'desc':
$sort_order = SORT_DESC;
$sort_neg = SORT_ASC;
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = SORT_ASC;
$sort_neg = SORT_DESC;
}
switch ($vars['sort']) {
case 'device':
$entries = array_sort_by($entries, 'hostname', $sort_order, SORT_STRING);
break;
case 'pwid':
$entries = array_sort_by($entries, 'pwID', $sort_order, SORT_NUMERIC);
break;
case 'pwtype':
$entries = array_sort_by($entries, 'pwType', $sort_order, SORT_STRING, 'pwPsnType', $sort_order, SORT_STRING);
//$pws = array_sort_by($pws, 'pwType', $sort_order, SORT_STRING);
break;
case 'peer_addr':
$entries = array_sort_by($entries, 'peer_addr', $sort_order, SORT_NUMERIC);
break;
case 'event':
$entries = array_sort_by($entries, 'event', $sort_order, SORT_STRING);
break;
case 'uptime':
$entries = array_sort_by($entries, 'pwUptime', $sort_order, SORT_NUMERIC);
break;
case 'last_change':
$entries = array_sort_by($entries, 'last_change', $sort_neg, SORT_NUMERIC);
break;
case 'status':
$entries = array_sort_by($entries, 'pwOperStatus', $sort_order, SORT_STRING);
break;
default:
// Not sorted
}
$entries[] = $entry;
}
// Sorting
switch ($vars['sort_order'])
{
case 'desc':
$sort_order = SORT_DESC;
$sort_neg = SORT_ASC;
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = SORT_ASC;
$sort_neg = SORT_DESC;
}
switch ($vars['sort'])
{
case 'device':
$entries = array_sort_by($entries, 'hostname', $sort_order, SORT_STRING);
break;
case 'pwid':
$entries = array_sort_by($entries, 'pwID', $sort_order, SORT_NUMERIC);
break;
case 'pwtype':
$entries = array_sort_by($entries, 'pwType', $sort_order, SORT_STRING, 'pwPsnType', $sort_order, SORT_STRING);
//$pws = array_sort_by($pws, 'pwType', $sort_order, SORT_STRING);
break;
case 'peer_addr':
$entries = array_sort_by($entries, 'peer_addr', $sort_order, SORT_NUMERIC);
break;
case 'event':
$entries = array_sort_by($entries, 'event', $sort_order, SORT_STRING);
break;
case 'uptime':
$entries = array_sort_by($entries, 'pwUptime', $sort_order, SORT_NUMERIC);
break;
case 'last_change':
$entries = array_sort_by($entries, 'last_change', $sort_neg, SORT_NUMERIC);
break;
case 'status':
$entries = array_sort_by($entries, 'pwOperStatus', $sort_order, SORT_STRING);
break;
default:
// Not sorted
}
return $entries;
return $entries;
}
function print_pseudowire_table($vars)
{
$pws = get_pseudowire_table($vars);
$pws_count = count($pws);
$pws = get_pseudowire_table($vars);
$pws_count = count($pws);
// Pagination
$pagination_html = pagination($vars, $pws_count);
echo $pagination_html;
// Pagination
$pagination_html = pagination($vars, $pws_count);
echo $pagination_html;
if ($vars['pageno'])
{
$pws = array_chunk($pws, $vars['pagesize']);
$pws = $pws[$vars['pageno'] - 1];
}
// End Pagination
if ($vars['pageno']) {
$pws = array_chunk($pws, $vars['pagesize']);
$pws = $pws[$vars['pageno'] - 1];
}
// End Pagination
echo generate_box_open();
echo generate_box_open();
print_pseudowire_table_header($vars);
print_pseudowire_table_header($vars);
foreach ($pws as $pw)
{
print_pseudowire_row($pw, $vars);
}
foreach ($pws as $pw) {
print_pseudowire_row($pw, $vars);
}
echo '</tbody></table>';
echo '</tbody></table>';
echo generate_box_close();
echo generate_box_close();
echo $pagination_html;
echo $pagination_html;
}
function humanize_pseudowire(&$pw)
{
global $config;
global $config;
if (isset($pw['humanized'])) { return; }
if (isset($pw['humanized'])) {
return;
}
if (isset($config['entity_events'][$pw['event']]))
{
$pw = array_merge($pw, $config['entity_events'][$pw['event']]);
} else {
$pw['event_class'] = 'label label-primary';
$pw['row_class'] = '';
}
if ($pw['pwRowStatus'] != 'active')
{
$pw['row_class'] = 'ignore';
}
if (isset($config['entity_events'][$pw['event']])) {
$pw = array_merge($pw, $config['entity_events'][$pw['event']]);
} else {
$pw['event_class'] = 'label label-primary';
$pw['row_class'] = '';
}
if ($pw['pwRowStatus'] != 'active') {
$pw['row_class'] = 'ignore';
}
$device = &$GLOBALS['cache']['devices']['id'][$pw['device_id']];
if ((isset($device['status']) && !$device['status']) || (isset($device['disabled']) && $device['disabled']))
{
$pw['row_class'] = 'error';
}
$device = device_by_id_cache($pw['device_id']);
$translate = entity_type_translate_array('pseudowire');
if ((isset($device['status']) && !$device['status']) || (isset($device['disabled']) && $device['disabled'])) {
$pw['row_class'] = 'error';
}
$pw['graph'] = $translate['graph']['type']; // Default graph
$translate = entity_type_translate_array('pseudowire');
$pw['humanized'] = TRUE;
$pw['graph'] = $translate['graph']['type']; // Default graph
$pw['humanized'] = TRUE;
}
function print_pseudowire_row($pw, $vars)
{
echo generate_pseudowire_row($pw, $vars);
echo generate_pseudowire_row($pw, $vars);
}
function generate_pseudowire_row($pw, $vars)
{
global $config;
global $config;
humanize_pseudowire($pw);
humanize_pseudowire($pw);
$table_cols = 11;
$table_cols = 11;
$graph_array = array();
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $pw['pseudowire_id'];
$graph_array['type'] = $pw['graph'];
$graph_array['legend'] = "no";
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = $config['time']['day'];
$graph_array = [];
$graph_array['to'] = get_time();
$graph_array['id'] = $pw['pseudowire_id'];
$graph_array['type'] = $pw['graph'];
$graph_array['legend'] = "no";
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = get_time('day');
if ($pw['event'] && $pw['pwOperStatus'])
{
$mini_graph = generate_graph_tag($graph_array);
} else {
// Do not show "Draw Error" minigraph
$mini_graph = '';
}
if ($pw['event'] && $pw['pwOperStatus']) {
$mini_graph = generate_graph_tag($graph_array);
} else {
// Do not show "Draw Error" minigraph
$mini_graph = '';
}
$out = '<tr class="' . $pw['row_class'] . '"><td class="state-marker"></td>';
$out .= '<td class="entity" style="text-align: right;">'. generate_entity_link('pseudowire', $pw, NULL, NULL, TRUE, TRUE) .'</td>';
$out .= '<td>'. nicecase($pw['pwType']) . '/' . nicecase($pw['pwPsnType']) .'</td>';
if ($vars['page'] != "device" && $vars['popup'] != TRUE)
{
$out .= '<td class="entity">' . generate_device_link($pw, NULL, array('tab' => 'pseudowires')) . '</td>';
$table_cols++;
}
$out .= '<td class="entity">'. generate_entity_link('port', $pw['port_id']) .'</td>';
$out .= '<td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>';
if ($pw['peer_port_id'])
{
$out .= '<td class="entity">' . generate_entity_link('device', $pw['peer_device_id']) . '</td>';
$out .= '<td class="entity">' . generate_entity_link('port', $pw['peer_port_id']) . '</td>';
} else {
$out .= '<td class="entity">'. generate_popup_link('ip', $pw['peer_addr']) .'</td>';
$out .= '<td>'. $pw['pwRemoteIfString'] .'</td>';
}
$out .= '<td>' . generate_entity_link('pseudowire', $pw, $mini_graph, NULL, FALSE) . '</td>';
$out .= '<td style="white-space: nowrap">' . generate_tooltip_link(NULL, format_uptime(($config['time']['now'] - $pw['last_change']), 'short-2') . ' ago', format_unixtime($pw['last_change'])) . '</td>';
$out .= '<td style="text-align: right;"><strong>' . generate_tooltip_link('', $pw['event'], $pw['event_descr'], $pw['event_class']) . '</strong></td>';
$out .= '<td style="text-align: right;"><strong>' . generate_tooltip_link('', $pw['pwOperStatus'], $pw['event_descr'], $pw['event_class']) . '</strong></td>';
$out .= '<td>' . format_uptime($pw['pwUptime'], 'short-2') . '</td>';
$out .= '</tr>';
if ($vars['graph'] || $vars['view'] == "graphs" || $vars['id'] == $pw['pseudowire_id'])
{
// If id set in vars, display only specific graphs
$graph_array = array();
$graph_array['type'] = ($vars['graph'] ? $vars['graph'] : $pw['graph']);
$graph_array['id'] = $pw['pseudowire_id'];
$out .= '<tr class="' . $pw['row_class'] . '">';
$out .= ' <td class="state-marker"></td>';
$out .= ' <td colspan="'.$table_cols.'">';
$out .= generate_graph_row($graph_array, TRUE);
$out .= ' </td>';
$out = '<tr class="' . $pw['row_class'] . '"><td class="state-marker"></td>';
$out .= '<td class="entity" style="text-align: right;">' . generate_entity_link('pseudowire', $pw, NULL, NULL, TRUE, TRUE) . '</td>';
$out .= '<td>' . nicecase($pw['pwType']) . '/' . nicecase($pw['pwPsnType']) . '</td>';
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
$out .= '<td class="entity">' . generate_device_link($pw, NULL, ['tab' => 'pseudowires']) . '</td>';
$table_cols++;
}
$out .= '<td class="entity">' . generate_entity_link('port', $pw['port_id']) . '</td>';
$out .= '<td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>';
if ($pw['peer_port_id']) {
$out .= '<td class="entity">' . generate_entity_link('device', $pw['peer_device_id']) . '</td>';
$out .= '<td class="entity">' . generate_entity_link('port', $pw['peer_port_id']) . '</td>';
} else {
$out .= '<td class="entity">' . generate_popup_link('ip', $pw['peer_addr']) . '</td>';
$out .= '<td>' . $pw['pwRemoteIfString'] . '</td>';
}
$out .= '<td>' . generate_entity_link('pseudowire', $pw, $mini_graph, NULL, FALSE) . '</td>';
$out .= '<td style="white-space: nowrap">' . generate_tooltip_link(NULL, format_uptime((get_time('now') - $pw['last_change']), 'short-2') . ' ago', format_unixtime($pw['last_change'])) . '</td>';
$out .= '<td style="text-align: right;"><strong>' . generate_tooltip_link('', $pw['event'], $pw['event_descr'], $pw['event_class']) . '</strong></td>';
$out .= '<td style="text-align: right;"><strong>' . generate_tooltip_link('', $pw['pwOperStatus'], $pw['event_descr'], $pw['event_class']) . '</strong></td>';
$out .= '<td>' . format_uptime($pw['pwUptime'], 'short-2') . '</td>';
$out .= '</tr>';
}
return $out;
if ($vars['graph'] || $vars['view'] == "graphs" || $vars['id'] == $pw['pseudowire_id']) {
// If id set in vars, display only specific graphs
$graph_array = [];
$graph_array['type'] = ($vars['graph'] ? $vars['graph'] : $pw['graph']);
$graph_array['id'] = $pw['pseudowire_id'];
$out .= '<tr class="' . $pw['row_class'] . '">';
$out .= ' <td class="state-marker"></td>';
$out .= ' <td colspan="' . $table_cols . '">';
$out .= generate_graph_row($graph_array, TRUE);
$out .= ' </td>';
$out .= '</tr>';
}
return $out;
}
function print_pseudowire_form($vars, $single_device = FALSE)
{
//global $config;
$form = ['type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
$form_items = [];
if ($single_device) {
// Single device, just hidden field
$form['row'][0]['device_id'] = [
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%'];
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `pseudowires`'));
$form['row'][0]['device_id'] = [
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']];
}
// Ports
$form_items['ports'] = generate_form_values('ports', dbFetchColumn('SELECT DISTINCT `port_id` FROM `pseudowires`'));
$form['row'][0]['port_id'] = [
'type' => 'multiselect',
'name' => 'Local Port',
'value' => $vars['port_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['ports']];
// Peer Address
$form_items['ports'] = generate_form_values('port', dbFetchColumn('SELECT DISTINCT `peer_addr` FROM `pseudowires`'));
$form['row'][0]['port_id'] = [
'type' => 'multiselect',
'name' => 'Local Port',
'value' => $vars['port_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['ports']];
// Groups
foreach (get_type_groups('pseudowire') as $entry) {
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
$form['row'][0]['group'] = [
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']];
$form['row'][0]['search'] = [
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
];
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
// Custom panel form
$panel_form = ['type' => 'rows',
'title' => 'Search Processors',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) {
unset($form['row'][$row][$param]['grid']);
}
}
}
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['group'] = $form['row'][0]['group'];
$panel_form['row'][3]['processor_descr'] = $form['row'][0]['processor_descr'];
$panel_form['row'][5]['search'] = $form['row'][0]['search'];
// Register custom panel
register_html_panel(generate_form($panel_form));
}
// EOF

File diff suppressed because it is too large Load Diff

View File

@ -4,358 +4,330 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @package observium
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
function generate_sla_query($vars)
{
$sql = 'SELECT * FROM `slas` ';
$sql .= ' WHERE `deleted` = 0';
$sql = 'SELECT * FROM `slas` ';
$sql .= generate_where_clause($GLOBALS['cache']['where']['devices_permitted'], '`deleted` = 0');
// Build query
foreach($vars as $var => $value)
{
switch ($var)
{
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'slas.sla_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'storage.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'slas.device_id');
break;
case "id":
case "sla_id":
$sql .= generate_query_values_and($value, 'slas.sla_id');
break;
case "owner":
$sql .= generate_query_values_and($value, 'slas.sla_owner');
break;
case "target":
case "sla_target":
$sql .= generate_query_values_and($value, 'slas.sla_target', '%LIKE%');
break;
case "sla_tag":
$sql .= generate_query_values_and($value, 'slas.sla_tag');
break;
case "rtt_type":
case "rtt_sense":
$sql .= generate_query_values_and($value, 'slas.'.$var);
break;
case "event":
case "rtt_event":
$sql .= generate_query_values_and($value, 'slas.rtt_event');
break;
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'slas.sla_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'storage.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'slas.device_id');
break;
case "id":
case "sla_id":
$sql .= generate_query_values_and($value, 'slas.sla_id');
break;
case "owner":
$sql .= generate_query_values_and($value, 'slas.sla_owner');
break;
case "target":
case "sla_target":
$sql .= generate_query_values_and($value, 'slas.sla_target', '%LIKE%');
break;
case "sla_tag":
$sql .= generate_query_values_and($value, 'slas.sla_tag');
break;
case "rtt_type":
case "rtt_sense":
$sql .= generate_query_values_and($value, 'slas.' . $var);
break;
case "event":
case "rtt_event":
$sql .= generate_query_values_and($value, 'slas.rtt_event');
break;
}
}
}
$sql .= $GLOBALS['cache']['where']['devices_permitted'];
return $sql;
return $sql;
}
function print_sla_table_header($vars)
{
if ($vars['view'] == "graphs" || isset($vars['graph']) || isset($vars['id']))
{
$stripe_class = "table-striped-two";
} else {
$stripe_class = "table-striped";
}
if ($vars['view'] == "graphs" || isset($vars['graph']) || isset($vars['id'])) {
$stripe_class = "table-striped-two";
} else {
$stripe_class = "table-striped";
}
echo('<table class="table ' . $stripe_class . ' table-condensed ">' . PHP_EOL);
$cols = array(
array(NULL, 'class="state-marker"'),
'device' => array('Device', 'style="width: 250px;"'),
'descr' => array('Description'),
'owner' => array('Owner', 'style="width: 180px;"'),
'type' => array('Type', 'style="width: 100px;"'),
array('History', 'style="width: 100px;"'),
'last_change' => array('Last&nbsp;changed', 'style="width: 80px;"'),
'event' => array('Event', 'style="width: 60px; text-align: right;"'),
'sense' => array('Sense', 'style="width: 100px; text-align: right;"'),
'rtt' => array('RTT', 'style="width: 60px;"'),
);
echo('<table class="table ' . $stripe_class . ' table-condensed ">' . PHP_EOL);
$cols = [
[NULL, 'class="state-marker"'],
'device' => ['Device', 'style="width: 250px;"'],
'descr' => ['Description'],
'owner' => ['Owner', 'style="width: 180px;"'],
'type' => ['Type', 'style="width: 100px;"'],
['History', 'style="width: 100px;"'],
'last_change' => ['Last&nbsp;changed', 'style="width: 80px;"'],
'event' => ['Event', 'style="width: 60px; text-align: right;"'],
'sense' => ['Sense', 'style="width: 100px; text-align: right;"'],
'rtt' => ['RTT', 'style="width: 60px;"'],
];
if ($vars['page'] == "device" || $vars['popup'] == TRUE )
{
unset($cols['device']);
}
if ($vars['page'] == "device" || $vars['popup'] == TRUE) {
unset($cols['device']);
}
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
}
function print_sla_table($vars)
{
$sql = generate_sla_query($vars);
$sql = generate_sla_query($vars);
$slas = array();
foreach(dbFetchRows($sql) as $sla)
{
if (isset($GLOBALS['cache']['devices']['id'][$sla['device_id']]))
{
$sla['hostname'] = $GLOBALS['cache']['devices']['id'][$sla['device_id']]['hostname'];
$slas[] = $sla;
$slas = [];
foreach (dbFetchRows($sql) as $sla) {
if ($device = device_by_id_cache($sla['device_id'])) {
$sla['hostname'] = $device['hostname'];
$slas[] = $sla;
}
}
}
// Sorting
// FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
switch ($vars['sort_order'])
{
case 'desc':
$sort_order = SORT_DESC;
$sort_neg = SORT_ASC;
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = SORT_ASC;
$sort_neg = SORT_DESC;
}
switch ($vars['sort'])
{
case 'device':
$slas = array_sort_by($slas, 'hostname', $sort_order, SORT_STRING);
break;
case 'descr':
$slas = array_sort_by($slas, 'sla_index', $sort_order, SORT_STRING, 'sla_tag', $sort_order, SORT_STRING);
break;
case 'owner':
$slas = array_sort_by($slas, 'sla_owner', $sort_order, SORT_STRING);
break;
case 'type':
$slas = array_sort_by($slas, 'rtt_type', $sort_order, SORT_STRING);
break;
case 'event':
$slas = array_sort_by($slas, 'rtt_event', $sort_order, SORT_STRING);
break;
case 'sense':
$slas = array_sort_by($slas, 'rtt_sense', $sort_order, SORT_STRING);
break;
case 'last_change':
$slas = array_sort_by($slas, 'rtt_last_change', $sort_neg, SORT_NUMERIC);
break;
case 'rtt':
$slas = array_sort_by($slas, 'rtt_value', $sort_order, SORT_NUMERIC);
break;
default:
// Not sorted
}
$slas_count = count($slas);
// Sorting
// FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
switch ($vars['sort_order']) {
case 'desc':
$sort_order = SORT_DESC;
$sort_neg = SORT_ASC;
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = SORT_ASC;
$sort_neg = SORT_DESC;
}
switch ($vars['sort']) {
case 'device':
$slas = array_sort_by($slas, 'hostname', $sort_order, SORT_STRING);
break;
case 'descr':
$slas = array_sort_by($slas, 'sla_index', $sort_order, SORT_STRING, 'sla_tag', $sort_order, SORT_STRING);
break;
case 'owner':
$slas = array_sort_by($slas, 'sla_owner', $sort_order, SORT_STRING);
break;
case 'type':
$slas = array_sort_by($slas, 'rtt_type', $sort_order, SORT_STRING);
break;
case 'event':
$slas = array_sort_by($slas, 'rtt_event', $sort_order, SORT_STRING);
break;
case 'sense':
$slas = array_sort_by($slas, 'rtt_sense', $sort_order, SORT_STRING);
break;
case 'last_change':
$slas = array_sort_by($slas, 'rtt_last_change', $sort_neg, SORT_NUMERIC);
break;
case 'rtt':
$slas = array_sort_by($slas, 'rtt_value', $sort_order, SORT_NUMERIC);
break;
default:
// Not sorted
}
$slas_count = count($slas);
// Pagination
$pagination_html = pagination($vars, $slas_count);
echo $pagination_html;
// Pagination
$pagination_html = pagination($vars, $slas_count);
echo $pagination_html;
if ($vars['pageno'])
{
$slas = array_chunk($slas, $vars['pagesize']);
$slas = $slas[$vars['pageno'] - 1];
}
// End Pagination
if ($vars['pageno']) {
$slas = array_chunk($slas, $vars['pagesize']);
$slas = $slas[$vars['pageno'] - 1];
}
// End Pagination
echo generate_box_open();
echo generate_box_open();
print_sla_table_header($vars);
print_sla_table_header($vars);
foreach($slas as $sla)
{
print_sla_row($sla, $vars);
}
foreach ($slas as $sla) {
print_sla_row($sla, $vars);
}
echo '</tbody></table>';
echo '</tbody></table>';
echo generate_box_close();
echo generate_box_close();
echo $pagination_html;
echo $pagination_html;
}
function humanize_sla(&$sla)
{
global $config;
global $config;
if (isset($sla['humanized'])) { return; }
$sla['sla_descr'] = 'SLA #' . $sla['sla_index'];
if (!empty($sla['sla_target']) && ($sla['sla_target'] != $sla['sla_tag']))
{
if (get_ip_version($sla['sla_target']) === 6)
{
$sla_target = Net_IPv6::compress($sla['sla_target'], TRUE);
} else {
$sla_target = $sla['sla_target'];
if (isset($sla['humanized'])) {
return;
}
$sla['sla_descr'] .= ' (' . $sla['sla_tag'] . ': ' . $sla_target . ')';
} else {
$sla['sla_descr'] .= ' (' . $sla['sla_tag'] . ')';
}
if (isset($config['entity_events'][$sla['rtt_event']]))
{
$sla = array_merge($sla, $config['entity_events'][$sla['rtt_event']]);
} else {
$sla['event_class'] = 'label label-primary';
$sla['row_class'] = '';
}
if ($sla['sla_status'] != 'active')
{
$sla['row_class'] = 'ignore';
}
$device = &$GLOBALS['cache']['devices']['id'][$sla['device_id']];
if (isset($device['status']) && !$device['status'])
{
$sla['row_class'] = 'error';
}
else if (isset($device['disabled']) && $device['disabled'])
{
$sla['row_class'] = 'ignore';
}
if (!empty($sla['sla_graph']))
{
$sla['graph_type'] = "sla_" . $sla['sla_graph'];
} else {
if (stripos($sla['rtt_type'], 'jitter') !== FALSE)
{
$sla['graph_type'] = "sla_jitter";
$sla['sla_descr'] = 'SLA #' . $sla['sla_index'];
if (!empty($sla['sla_target']) && ($sla['sla_target'] != $sla['sla_tag'])) {
if (get_ip_version($sla['sla_target']) === 6) {
$sla_target = Net_IPv6 ::compress($sla['sla_target'], TRUE);
} else {
$sla_target = $sla['sla_target'];
}
$sla['sla_descr'] .= ' (' . $sla['sla_tag'] . ': ' . $sla_target . ')';
} else {
$sla['graph_type'] = "sla_echo";
$sla['sla_descr'] .= ' (' . $sla['sla_tag'] . ')';
}
}
if (isset($GLOBALS['config']['sla_type_labels'][$sla['rtt_type']]))
{
$sla['rtt_label'] = $GLOBALS['config']['sla_type_labels'][$sla['rtt_type']];
} else {
$sla['rtt_label'] = nicecase($sla['rtt_type']);
}
if (is_numeric($sla['rtt_value']))
{
if ($sla['rtt_value'] > 950)
{
$sla['human_value'] = round($sla['rtt_value'] / 1000, 2);
$sla['human_unit'] = 's';
if (isset($config['entity_events'][$sla['rtt_event']])) {
$sla = array_merge($sla, $config['entity_events'][$sla['rtt_event']]);
} else {
$sla['human_value'] = $sla['rtt_value'];
$sla['human_unit'] = 'ms';
$sla['event_class'] = 'label label-primary';
$sla['row_class'] = '';
}
if ($sla['sla_status'] != 'active') {
$sla['row_class'] = 'ignore';
}
$sla['human_value'] = str_replace('.00', '', $sla['human_value']);
}
/*
// FIXME, add table columns in discovery time 'rtt_high', 'rtt_warning'
if ($sla['rtt_value'] > 200)
{
$sla['sla_class'] = 'label label-error';
}
else if ($sla['rtt_value'] > 80)
{
$sla['sla_class'] = 'label label-warning';
} else {
$sla['sla_class'] = 'label';
}
*/
$device = device_by_id_cache($sla['device_id']);
if (isset($device['status']) && !$device['status']) {
$sla['row_class'] = 'error';
} elseif (isset($device['disabled']) && $device['disabled']) {
$sla['row_class'] = 'ignore';
}
if ($sla['rtt_event'] == 'ok')
{
$sla['sla_class'] = 'label';
//$sla['rtt_class'] = 'label label-success';
}
else if ($sla['rtt_event'] == 'alert')
{
$sla['sla_class'] = 'label label-error';
//$sla['rtt_class'] = 'label label-error';
}
else if ($sla['rtt_event'] == 'ignore')
{
$sla['sla_class'] = 'label';
//$sla['rtt_class'] = 'label';
} else {
$sla['sla_class'] = 'label label-warning';
//$sla['rtt_class'] = 'label label-warning';
}
if (!empty($sla['sla_graph'])) {
$sla['graph_type'] = "sla_" . $sla['sla_graph'];
} else {
if (stripos($sla['rtt_type'], 'jitter') !== FALSE) {
$sla['graph_type'] = "sla_jitter";
} else {
$sla['graph_type'] = "sla_echo";
}
}
$sla['humanized'] = TRUE;
if (isset($GLOBALS['config']['sla_type_labels'][$sla['rtt_type']])) {
$sla['rtt_label'] = $GLOBALS['config']['sla_type_labels'][$sla['rtt_type']];
} else {
$sla['rtt_label'] = nicecase($sla['rtt_type']);
}
if (is_numeric($sla['rtt_value'])) {
if ($sla['rtt_value'] > 950) {
$sla['human_value'] = round($sla['rtt_value'] / 1000, 2);
$sla['human_unit'] = 's';
} else {
$sla['human_value'] = $sla['rtt_value'];
$sla['human_unit'] = 'ms';
}
$sla['human_value'] = str_replace('.00', '', $sla['human_value']);
}
/*
// FIXME, add table columns in discovery time 'rtt_high', 'rtt_warning'
if ($sla['rtt_value'] > 200)
{
$sla['sla_class'] = 'label label-error';
}
else if ($sla['rtt_value'] > 80)
{
$sla['sla_class'] = 'label label-warning';
} else {
$sla['sla_class'] = 'label';
}
*/
if ($sla['rtt_event'] == 'ok') {
$sla['sla_class'] = 'label';
//$sla['rtt_class'] = 'label label-success';
} elseif ($sla['rtt_event'] == 'alert') {
$sla['sla_class'] = 'label label-error';
//$sla['rtt_class'] = 'label label-error';
} elseif ($sla['rtt_event'] == 'ignore') {
$sla['sla_class'] = 'label';
//$sla['rtt_class'] = 'label';
} else {
$sla['sla_class'] = 'label label-warning';
//$sla['rtt_class'] = 'label label-warning';
}
$sla['humanized'] = TRUE;
}
function print_sla_row($sla, $vars)
{
echo generate_sla_row($sla, $vars);
echo generate_sla_row($sla, $vars);
}
function generate_sla_row($sla, $vars)
{
global $config;
global $config;
humanize_sla($sla);
humanize_sla($sla);
$table_cols = "8";
$table_cols = "8";
$graph_array = array();
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $sla['sla_id'];
$graph_array['type'] = $sla['graph_type'];
$graph_array['legend'] = "no";
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = $config['time']['day'];
$graph_array = [];
$graph_array['to'] = get_time();
$graph_array['id'] = $sla['sla_id'];
$graph_array['type'] = $sla['graph_type'];
$graph_array['legend'] = "no";
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = get_time('day');
if ($sla['rtt_event'] && $sla['rtt_sense'])
{
$mini_graph = generate_graph_tag($graph_array);
} else {
// Do not show "Draw Error" minigraph
$mini_graph = '';
}
if ($sla['rtt_event'] && $sla['rtt_sense']) {
$mini_graph = generate_graph_tag($graph_array);
} else {
// Do not show "Draw Error" minigraph
$mini_graph = '';
}
$out = '<tr class="' . $sla['row_class'] . '"><td class="state-marker"></td>';
if ($vars['page'] != "device" && $vars['popup'] != TRUE )
{
$out .= '<td class="entity">' . generate_device_link($sla) . '</td>';
$table_cols++;
}
$out = '<tr class="' . $sla['row_class'] . '"><td class="state-marker"></td>';
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
$out .= '<td class="entity">' . generate_device_link($sla) . '</td>';
$table_cols++;
}
$out .= '<td class="entity">'. generate_entity_link('sla', $sla) .'</td>';
$out .= '<td>'. $sla['sla_owner'] .'</td>';
$out .= '<td>'. $sla['rtt_label'] .'</td>';
$out .= '<td>' . generate_entity_link('sla', $sla, $mini_graph, NULL, FALSE) . '</td>';
$out .= '<td style="white-space: nowrap">' . generate_tooltip_link(NULL, format_uptime(($config['time']['now'] - $sla['rtt_last_change']), 'short-2') . ' ago', format_unixtime($sla['rtt_last_change'])) . '</td>';
$out .= '<td style="text-align: right;"><strong>' . generate_tooltip_link('', $sla['rtt_event'], $sla['event_descr'], $sla['event_class']) . '</strong></td>';
$out .= '<td style="text-align: right;"><strong>' . generate_tooltip_link('', $sla['rtt_sense'], $sla['event_descr'], $sla['event_class']) . '</strong></td>';
$out .= '<td><span class="' . $sla['sla_class'] . '">' . $sla['human_value'] . $sla['human_unit'] . '</span></td>';
$out .= '</tr>';
if ($vars['graph'] || $vars['view'] == "graphs" || $vars['id'] == $sla['sla_id'])
{
// If id set in vars, display only specific graphs
$graph_array = array();
$graph_array['type'] = $sla['graph_type'];
$graph_array['id'] = $sla['sla_id'];
$out .= '<tr class="' . $sla['row_class'] . '">';
$out .= ' <td class="state-marker"></td>';
$out .= ' <td colspan="'.$table_cols.'">';
$out .= generate_graph_row($graph_array, TRUE);
$out .= ' </td>';
$out .= '<td class="entity">' . generate_entity_link('sla', $sla) . '</td>';
$out .= '<td>' . $sla['sla_owner'] . '</td>';
$out .= '<td>' . $sla['rtt_label'] . '</td>';
$out .= '<td>' . generate_entity_link('sla', $sla, $mini_graph, NULL, FALSE) . '</td>';
$out .= '<td style="white-space: nowrap">' . generate_tooltip_link(NULL, format_uptime((get_time('now') - $sla['rtt_last_change']), 'short-2') . ' ago', format_unixtime($sla['rtt_last_change'])) . '</td>';
$out .= '<td style="text-align: right;"><strong>' . generate_tooltip_link('', $sla['rtt_event'], $sla['event_descr'], $sla['event_class']) . '</strong></td>';
$out .= '<td style="text-align: right;"><strong>' . generate_tooltip_link('', $sla['rtt_sense'], $sla['event_descr'], $sla['event_class']) . '</strong></td>';
$out .= '<td><span class="' . $sla['sla_class'] . '">' . $sla['human_value'] . $sla['human_unit'] . '</span></td>';
$out .= '</tr>';
}
return $out;
if ($vars['graph'] || $vars['view'] == "graphs" || $vars['id'] == $sla['sla_id']) {
// If id set in vars, display only specific graphs
$graph_array = [];
$graph_array['type'] = $sla['graph_type'];
$graph_array['id'] = $sla['sla_id'];
$out .= '<tr class="' . $sla['row_class'] . '">';
$out .= ' <td class="state-marker"></td>';
$out .= ' <td colspan="' . $table_cols . '">';
$out .= generate_graph_row($graph_array, TRUE);
$out .= ' </td>';
$out .= '</tr>';
}
return $out;
}
// EOF

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
@ -18,505 +18,512 @@
* human_value, sensor_symbol, state_name, state_event, event_class
*
* @param array $status
*
* @return array $status
*
*/
// TESTME needs unit testing
function humanize_status(&$status)
{
global $config;
global $config;
// Exit if already humanized
if ($status['humanized']) { return; }
// Exit if already humanized
if ($status['humanized']) {
return;
}
if (isset($config['entity_events'][$status['status_event']]))
{
$status = array_merge($status, $config['entity_events'][$status['status_event']]);
} else {
$status['event_class'] = 'label label-primary';
$status['row_class'] = '';
}
if ($status['status_deleted'])
{
$status['row_class'] = 'disabled';
}
if (isset($config['entity_events'][$status['status_event']])) {
$status = array_merge($status, $config['entity_events'][$status['status_event']]);
} else {
$status['event_class'] = 'label label-primary';
$status['row_class'] = '';
}
if ($status['status_deleted']) {
$status['row_class'] = 'disabled';
}
$device = &$GLOBALS['cache']['devices']['id'][$status['device_id']];
if ((isset($device['status']) && !$device['status']) ||
(isset($device['disabled']) && $device['disabled'])) {
$status['row_class'] = $status['row_class'] !== 'disabled' ? 'error' : $status['row_class'];
}
// this is pseudo class only for js selectors
$status['row_class'] .= ' entity-status';
$device = device_by_id_cache($status['device_id']);
if ((isset($device['status']) && !$device['status']) ||
(isset($device['disabled']) && $device['disabled'])) {
$status['row_class'] = $status['row_class'] !== 'disabled' ? 'error' : $status['row_class'];
}
// this is pseudo class only for js selectors
$status['row_class'] .= ' entity-status';
// Set humanized entry in the array so we can tell later
$status['humanized'] = TRUE;
// Set humanized entry in the array so we can tell later
$status['humanized'] = TRUE;
}
function generate_status_query($vars, $query_count = FALSE) {
if ($query_count) {
$sql = "SELECT COUNT(*) FROM `status`";
} else {
$sql = "SELECT * FROM `status`";
if ($query_count) {
$sql = "SELECT COUNT(*) FROM `status`";
} else {
$sql = "SELECT * FROM `status`";
if ($vars['sort'] == 'hostname' || $vars['sort'] == 'device' || $vars['sort'] == 'device_id') {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
if ($vars['sort'] == 'hostname' || $vars['sort'] == 'device' || $vars['sort'] == 'device_id') {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
}
}
}
//$sql .= " WHERE 1";
$sql .= " WHERE `status_deleted` = 0";
// Build query
$where_array = [];
foreach ($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value, 'status');
$where_array[] = generate_query_values($values, 'status.status_id');
break;
// Build query
foreach($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value, 'status');
$sql .= generate_query_values_and($values, 'status.status_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'status.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'status.device_id');
break;
case "id":
case 'status_id':
$sql .= generate_query_values_and($value, 'status.status_id');
break;
case "entity_id":
$sql .= generate_query_values_and($value, 'measured_entity');
break;
case "entity_type":
$sql .= generate_query_values_and($value, 'measured_class');
break;
case 'entity_state':
case "measured_state":
$sql .= build_entity_measured_where('status', [ 'measured_state' => $value ]);
break;
case "class":
case 'entPhysicalClass':
$sql .= generate_query_values_and($value, 'entPhysicalClass');
break;
case "event":
case "status_event":
$sql .= generate_query_values_and($value, 'status_event');
break;
case "status":
case "status_name":
$sql .= generate_query_values_and($value, 'status_name');
break;
case "descr":
case "status_descr":
$sql .= generate_query_values_and($value, 'status_descr', '%LIKE%');
break;
case 'type':
case "status_type":
$sql .= generate_query_values_and($value, 'status_type', '%LIKE%');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$where_array[] = generate_query_values($values, 'status.device_id');
break;
case "device":
case "device_id":
$where_array[] = generate_query_values($value, 'status.device_id');
break;
case "id":
case 'status_id':
$where_array[] = generate_query_values($value, 'status.status_id');
break;
case "entity_id":
$where_array[] = generate_query_values($value, 'measured_entity');
break;
case "entity_type":
$where_array[] = generate_query_values($value, 'measured_class');
break;
case 'entity_state':
case "measured_state":
$where_array[] = generate_query_entity_measured('status', [ 'measured_state' => $value ]);
break;
case "class":
case 'entPhysicalClass':
$where_array[] = generate_query_values($value, 'entPhysicalClass');
break;
case "event":
case "status_event":
$where_array[] = generate_query_values($value, 'status_event');
break;
case "status":
case "status_name":
$where_array[] = generate_query_values($value, 'status_name');
break;
case "descr":
case "status_descr":
$where_array[] = generate_query_values($value, 'status_descr', '%LIKE%');
break;
case 'type':
case "status_type":
$where_array[] = generate_query_values($value, 'status_type', '%LIKE%');
break;
}
}
$where_array[] = '`status_deleted` = 0';
$sql .= generate_where_clause($where_array, generate_query_permitted_ng([ 'device', 'status' ]));
// If need count, just return sql without sorting
if ($query_count) {
return $sql;
}
if (isset($vars['sort'])) {
switch ($vars['sort']) {
case 'device':
$sql .= generate_query_sort('hostname', get_sort_order($vars));
break;
case 'descr':
$sql .= generate_query_sort('status_descr', get_sort_order($vars));
break;
case 'class':
case 'entPhysicalClass':
$sql .= generate_query_sort('entPhysicalClass', get_sort_order($vars));
break;
case 'event':
$sql .= generate_query_sort('status_event', get_sort_order($vars));
break;
case 'status':
$sql .= generate_query_sort('status_name', get_sort_order($vars));
break;
case 'last_change':
$sql .= generate_query_sort('status_last_change', get_sort_order($vars, TRUE));
break;
case 'mib':
$sql .= generate_query_sort([ 'status_mib', 'status_object', 'status_type', 'status_index:integer' ], get_sort_order($vars));
break;
default:
$sql .= generate_query_sort([ 'measured_entity_label', 'status_descr' ], get_sort_order($vars));
}
} else {
$sql .= generate_query_sort([ 'measured_entity_label', 'status_descr' ]);
}
if (isset($vars['pageno'])) {
//$sql .= generate_query_limit($vars);
}
}
//$sql .= $GLOBALS['cache']['where']['devices_permitted'];
$sql .= generate_query_permitted(array('device', 'status'));
// If need count, just return sql without sorting
if ($query_count) {
return $sql;
}
switch ($vars['sort_order']) {
case 'desc':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
}
switch($vars['sort']) {
case 'device':
$sql .= ' ORDER BY `hostname` '.$sort_order;
break;
case 'descr':
$sql .= ' ORDER BY `status_descr` '.$sort_order;
break;
case 'class':
$sql .= ' ORDER BY `entPhysicalClass` '.$sort_order;
break;
case 'event':
$sql .= ' ORDER BY `status_event` '.$sort_order;
break;
case 'status':
$sql .= ' ORDER BY `status_name` '.$sort_order;
break;
case 'last_change':
$sql .= ' ORDER BY `status_last_change` '.$sort_neg;
break;
default:
$sql .= ' ORDER BY `measured_entity_label`, `status_descr` '.$sort_order;
}
return $sql;
}
function print_status_table($vars)
{
pagination($vars, 0, TRUE); // Get default pagesize/pageno
pagination($vars, 0, TRUE); // Get default pagesize/pageno
$sql = generate_status_query($vars);
$sql = generate_status_query($vars);
$status_list = array();
foreach(dbFetchRows($sql) as $status) {
//if (isset($GLOBALS['cache']['devices']['id'][$status['device_id']]))
//{
$status['hostname'] = $GLOBALS['cache']['devices']['id'][$status['device_id']]['hostname'];
$status_list[] = $status;
//}
}
$status_list = [];
foreach (dbFetchRows($sql) as $status) {
$status['hostname'] = get_device_hostname_by_id($status['device_id']);
$status_list[] = $status;
}
//$status_count = count($status_list); // This is count incorrect, when pagination used!
$status_count = dbFetchCell(generate_status_query($vars, TRUE));
//$status_count = count($status_list); // This is count incorrect, when pagination used!
$status_count = dbFetchCell(generate_status_query($vars, TRUE));
// Pagination
$pagination_html = pagination($vars, $status_count);
echo $pagination_html;
// Pagination
$pagination_html = pagination($vars, $status_count);
echo $pagination_html;
if ($vars['pageno'])
{
$status_list = array_chunk($status_list, $vars['pagesize']);
$status_list = $status_list[$vars['pageno'] - 1];
}
// End Pagination
if ($vars['pageno']) {
$status_list = array_chunk($status_list, $vars['pagesize']);
$status_list = $status_list[$vars['pageno'] - 1];
}
// End Pagination
echo generate_box_open();
echo generate_box_open();
print_status_table_header($vars);
print_status_table_header($vars);
foreach($status_list as $status)
{
print_status_row($status, $vars);
}
foreach ($status_list as $status) {
print_status_row($status, $vars);
}
echo("</tbody></table>");
echo("</tbody></table>");
echo generate_box_close();
echo generate_box_close();
echo $pagination_html;
echo $pagination_html;
}
function print_status_table_header($vars)
{
if ($vars['view'] == "graphs" || isset($vars['id']))
{
$stripe_class = "table-striped-two";
} else {
$stripe_class = "table-striped";
}
if ($vars['view'] == "graphs" || isset($vars['id'])) {
$stripe_class = "table-striped-two";
} else {
$stripe_class = "table-striped";
}
echo('<table class="table ' . $stripe_class . ' table-condensed ">' . PHP_EOL);
$cols = array(
array(NULL, 'class="state-marker"'),
'device' => array('Device', 'style="width: 250px;"'),
//array(NULL, 'class="no-width"'), // Measure entity link
'descr' => array('Description'),
'mib' => array('MIB::Object'),
'class' => array('Physical&nbsp;Class', 'style="width: 100px;"'),
array('History', 'style="width: 90px;"'),
'last_change' => array('Last&nbsp;changed', 'style="width: 80px;"'),
'event' => array('Event', 'style="width: 60px; text-align: right;"'),
'status' => array('Status', 'style="width: 80px; text-align: right;"'),
);
echo('<table class="table ' . $stripe_class . ' table-condensed ">' . PHP_EOL);
$cols = [
[NULL, 'class="state-marker"'],
'device' => ['Device', 'style="width: 250px;"'],
//array(NULL, 'class="no-width"'), // Measure entity link
'descr' => ['Description'],
'mib' => ['MIB::Object'],
'entPhysicalClass' => ['Phys&nbsp;Class', 'style="width: 100px;"'],
['History', 'style="width: 90px;"'],
'last_change' => ['Last&nbsp;changed', 'style="width: 80px;"'],
'event' => ['Event', 'style="width: 60px; text-align: right;"'],
'status' => ['Status', 'style="width: 80px; text-align: right;"'],
];
if ($vars['page'] == "device") { unset($cols['device']); }
if ($vars['page'] != "device" || $vars['tab'] == "overview") { unset($cols['mib']); unset($cols['object']); }
if ($vars['page'] == "device") {
unset($cols['device']);
}
if ($vars['page'] != "device" || $vars['tab'] == "overview") {
unset($cols['mib']);
unset($cols['object']);
}
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
}
function print_status_row($status, $vars)
{
echo generate_status_row($status, $vars);
echo generate_status_row($status, $vars);
}
function generate_status_row($status, $vars) {
function generate_status_row($status, $vars)
{
$table_cols = 7;
$table_cols = 7;
humanize_status($status);
humanize_status($status);
// FIXME - make this "four graphs in popup" a function/include and "small graph" a function.
// FIXME - DUPLICATED IN device/overview/status
// FIXME - make this "four graphs in popup" a function/include and "small graph" a function.
// FIXME - DUPLICATED IN device/overview/status
$graph_array = array();
$graph_array['to'] = get_time();
$graph_array['id'] = $status['status_id'];
$graph_array['type'] = "status_graph";
$graph_array['legend'] = "no";
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = get_time('day');
$graph_array = [];
$graph_array['to'] = get_time();
$graph_array['id'] = $status['status_id'];
$graph_array['type'] = "status_graph";
$graph_array['legend'] = "no";
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = get_time('day');
//$status_misc = '<span class="label">' . $status['entPhysicalClass'] . '</span>';
$short = $vars['page'] === "device" && $vars['tab'] === "overview";
$hide_style = $status['status_event'] === 'ignore' && $short ? ' style="display: none;"' : '';
//$status_misc = '<span class="label">' . $status['entPhysicalClass'] . '</span>';
$short = $vars['page'] === "device" && $vars['tab'] === "overview";
$hide_style = $status['status_event'] === 'ignore' && $short ? ' style="display: none;"' : '';
$row = '<tr class="' . $status['row_class'] . '"'.$hide_style.'>
$row = '<tr class="' . $status['row_class'] . '"' . $hide_style . '>
<td class="state-marker"></td>';
if ($vars['page'] !== "device" && $vars['popup'] != TRUE)
{
$row .= '<td class="entity">' . generate_device_link($status) . '</td>';
if ($vars['page'] !== "device" && $vars['popup'] != TRUE) {
$row .= '<td class="entity">' . generate_device_link($status) . '</td>';
$table_cols++;
}
if ($status['status_event'] && $status['status_name']) {
$mini_graph = generate_graph_tag($graph_array);
} else {
// Do not show "Draw Error" minigraph
$mini_graph = '';
}
// Measured link & icon
/* Disabled because it breaks the overview table layout
$row .= ' <td style="padding-right: 0px;" class="no-width vertical-align">'; // minify column if empty
if ($status['measured_entity'] &&
(!isset($vars['measured_icon']) || $vars['measured_icon'])) // hide measured icon if not required
{
$row .= generate_entity_icon_link($status['measured_class'], $status['measured_entity']);
}
$row .= '</td>';
$table_cols++;
}
*/
if ($status['status_event'] && $status['status_name'])
{
$mini_graph = generate_graph_tag($graph_array);
} else {
// Do not show "Draw Error" minigraph
$mini_graph = '';
}
$row .= '<td class="entity">' . generate_entity_link('status', $status) . '</td>';
// Measured link & icon
/* Disabled because it breaks the overview table layout
$row .= ' <td style="padding-right: 0px;" class="no-width vertical-align">'; // minify column if empty
if ($status['measured_entity'] &&
(!isset($vars['measured_icon']) || $vars['measured_icon'])) // hide measured icon if not required
{
$row .= generate_entity_icon_link($status['measured_class'], $status['measured_entity']);
}
$row .= '</td>';
$table_cols++;
*/
// FIXME -- Generify this. It's not just for sensors.
if ($vars['page'] === "device" && $vars['tab'] !== "overview") {
$row .= ' <td><span class="label-group">' . (!safe_empty($status['status_mib']) ? '<span class="label label-primary"><a href="' . OBSERVIUM_MIBS_URL . '/' . $status['status_mib'] . '/" target="_blank">' . nicecase($status['status_mib']) . '</a></span>' : '') .
(!safe_empty($status['status_mib']) ? '<span class="label label-success"><a href="' . OBSERVIUM_MIBS_URL . '/' . $status['status_mib'] . '/#' . $status['status_object'] . '" target="_blank">' . $status['status_object'] . '</a></span>' : '') .
'<span class="label label-delayed">' . $status['status_index'] . '</span></span></td>' . PHP_EOL;
$table_cols++;
}
$row .= '<td class="entity">' . generate_entity_link('status', $status) . '</td>';
// FIXME -- Generify this. It's not just for sensors.
if ($vars['page'] === "device" && $vars['tab'] !== "overview")
{
$row .= ' <td>' . (!safe_empty($status['status_mib']) ? '<a href="'.OBSERVIUM_MIBS_URL.'/'.$status['status_mib'].'/" target="_blank">' .nicecase($status['status_mib']) .'</a>' : '') .
( ( !safe_empty($status['status_mib']) && !safe_empty($status['status_object'])) ? '::' : '') .
(!safe_empty($status['status_mib']) ? '<a href="'.OBSERVIUM_MIBS_URL.'/'.$status['status_mib'].'/#'.$status['status_object'].'" target="_blank">' . $status['status_object'] .'</a>' : '') .
'.'.$status['status_index'].'</td>' . PHP_EOL;
$table_cols++;
}
if ($vars['tab'] !== "overview")
{
$row .= '<td><span class="label">' . $status['entPhysicalClass'] . '</span></td>';
$table_cols++;
}
$row .= '<td style="width: 90px; text-align: right;">' . generate_entity_link('status', $status, $mini_graph, NULL, FALSE) . '</td>';
if ($vars['tab'] !== "overview")
{
$row .= '<td style="white-space: nowrap">' . generate_tooltip_time($status['status_last_change'], 'ago') . '</td>
if ($vars['tab'] !== "overview") {
$row .= '<td>' . get_type_class_label($status['entPhysicalClass'], 'physicalclass') . '</td>';
$table_cols++;
}
$row .= '<td style="width: 90px; text-align: right;">' . generate_entity_link('status', $status, $mini_graph, NULL, FALSE) . '</td>';
if ($vars['tab'] !== "overview") {
$row .= '<td style="white-space: nowrap">' . generate_tooltip_time($status['status_last_change'], 'ago') . '</td>
<td style="text-align: right;"><strong>' . generate_tooltip_link('', $status['status_event'], $status['event_descr'], $status['event_class']) . '</strong></td>';
$table_cols++;
$table_cols++;
}
$row .= '<td style="width: 80px; text-align: right;"><strong>' . generate_tooltip_link('', $status['status_name'], $status['event_descr'], $status['event_class']) . '</strong></td>
$table_cols++;
$table_cols++;
}
$row .= '<td style="width: 80px; text-align: right;"><strong>' . generate_tooltip_link('', $status['status_name'], $status['event_descr'], $status['event_class']) . '</strong></td>
</tr>' . PHP_EOL;
if ($vars['view'] === "graphs")
{
$vars['graph'] = "status";
}
if ($vars['view'] === "graphs") {
$vars['graph'] = "status";
}
if ($vars['graph'] || $vars['id'] == $status['status_id'])
{
// If id set in vars, display only specific graphs
$row .= '<tr class="' . $status['row_class'] . '">
if ($vars['graph'] || $vars['id'] == $status['status_id']) {
// If id set in vars, display only specific graphs
$row .= '<tr class="' . $status['row_class'] . '">
<td class="state-marker"></td>
<td colspan="' . $table_cols . '">';
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = get_time();
$graph_array['id'] = $status['status_id'];
$graph_array['type'] = "status_graph";
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = get_time();
$graph_array['id'] = $status['status_id'];
$graph_array['type'] = "status_graph";
$row .= generate_graph_row($graph_array, TRUE);
$row .= generate_graph_row($graph_array, TRUE);
$row .= '</td></tr>';
} # endif graphs
$row .= '</td></tr>';
} # endif graphs
return $row;
return $row;
}
function print_status_form($vars, $single_device = FALSE)
{
global $config;
global $config;
$form = array('type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
$form = ['type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
$form_items = array();
$form_items = [];
if ($single_device)
{
// Single device, just hidden field
$form['row'][0]['device_id'] = array(
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%');
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `status`'));
if ($single_device) {
// Single device, just hidden field
$form['row'][0]['device_id'] = [
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%'];
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `status`'));
$form['row'][0]['device_id'] = array(
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']);
}
$status_permitted = generate_query_permitted(array('device', 'status'));
foreach ([ 'entPhysicalClass' => 'Physical Class', 'status_event' => 'Status Event', 'status_name' => 'Status' ] as $param => $param_name) {
$sql = 'SELECT DISTINCT `'.$param.'` FROM `status` WHERE `status_deleted` = ?' . $status_permitted;
if ($entries = dbFetchColumn($sql, [ 0 ])) {
asort($entries);
$form['row'][0]['device_id'] = [
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']];
}
foreach ($entries as $entry) {
if (safe_empty($entry)) { $entry = OBS_VAR_UNSET; }
if ($param === 'entPhysicalClass')
{
$name = nicecase($entry);
if (isset($config['icon'][strtolower($entry)]))
{
$name = ['name' => $name, 'icon' => $config['icon'][strtolower($entry)]];
} else {
$name = ['name' => $name, 'icon' => $config['icon']['status']];
$status_permitted = generate_query_permitted(['device', 'status']);
foreach (['entPhysicalClass' => 'Physical Class', 'status_event' => 'Status Event', 'status_name' => 'Status'] as $param => $param_name) {
$sql = 'SELECT DISTINCT `' . $param . '` FROM `status` WHERE `status_deleted` = ?' . $status_permitted;
if ($entries = dbFetchColumn($sql, [0])) {
asort($entries);
}
} else {
$name = $entry;
}
$form_items[$param][$entry] = $name;
foreach ($entries as $entry) {
if (safe_empty($entry)) {
$entry = OBS_VAR_UNSET;
}
if ($param === 'entPhysicalClass') {
$name = nicecase($entry);
if (isset($config['icon'][strtolower($entry)])) {
$name = ['name' => $name, 'icon' => $config['icon'][strtolower($entry)]];
} else {
$name = ['name' => $name, 'icon' => $config['icon']['status']];
}
} else {
$name = $entry;
}
$form_items[$param][$entry] = $name;
}
// Alternative param name, ie event
$short_param = str_replace('status_', '', $param);
if (!isset($vars[$param]) && isset($vars[$short_param])) {
$vars[$param] = $vars[$short_param];
}
// Status specific forms
$form['row'][0][$param] = [
'type' => 'multiselect',
'name' => $param_name,
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars[$param],
'values' => $form_items[$param]];
}
// Alternative param name, ie event
$short_param = str_replace('status_', '', $param);
if (!isset($vars[$param]) && isset($vars[$short_param]))
{
$vars[$param] = $vars[$short_param];
}
// Measured entities
$form['row'][0]['measured_state'] = [
'type' => 'multiselect',
'name' => 'Measured State',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['measured_state'],
'values' => ['none' => ['name' => 'Without Measure', 'icon' => $config['icon']['filter']],
'up' => ['name' => 'Measured UP', 'icon' => $config['icon']['up']],
'down' => ['name' => 'Measured DOWN', 'icon' => $config['icon']['down']],
'shutdown' => ['name' => 'Measured SHUTDOWN', 'icon' => $config['icon']['shutdown']]]];
// Status specific forms
$form['row'][0][$param] = array(
'type' => 'multiselect',
'name' => $param_name,
$form['row'][1]['status_descr'] = [
'type' => 'text',
'placeholder' => 'Status description',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars[$param],
'values' => $form_items[$param]);
}
'grid' => 4,
'value' => $vars['status_descr']];
// Measured entities
$form['row'][0]['measured_state'] = array(
'type' => 'multiselect',
'name' => 'Measured State',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['measured_state'],
'values' => ['none' => ['name' => 'Without Measure', 'icon' => $config['icon']['filter']],
'up' => ['name' => 'Measured UP', 'icon' => $config['icon']['up']],
'down' => ['name' => 'Measured DOWN', 'icon' => $config['icon']['down']],
'shutdown' => ['name' => 'Measured SHUTDOWN', 'icon' => $config['icon']['shutdown']]]);
$form['row'][1]['status_type'] = [
'type' => 'text',
'placeholder' => 'Status type',
'width' => '100%', //'180px',
'grid' => 4,
'value' => $vars['status_descr']];
$form['row'][1]['status_descr'] = array(
'type' => 'text',
'placeholder' => 'Status description',
'width' => '100%', //'180px',
'grid' => 4,
'value' => $vars['status_descr']);
$form['row'][1]['status_type'] = array(
'type' => 'text',
'placeholder' => 'Status type',
'width' => '100%', //'180px',
'grid' => 4,
'value' => $vars['status_descr']);
// Groups
foreach (get_type_groups('status') as $entry)
{
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
$form['row'][1]['group'] = array(
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']);
$form['row'][1]['search'] = array(
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
);
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
// Custom panel form
$panel_form = array('type' => 'rows',
'title' => 'Search Statuses',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) { unset($form['row'][$row][$param]['grid']); }
// Groups
foreach (get_type_groups('status') as $entry) {
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
}
$form['row'][1]['group'] = [
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']];
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['entPhysicalClass'] = $form['row'][0]['entPhysicalClass'];
$form['row'][1]['search'] = [
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
];
$panel_form['row'][1]['status_event'] = $form['row'][0]['status_event'];
$panel_form['row'][1]['status_name'] = $form['row'][0]['status_name'];
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
$panel_form['row'][2]['measured_state'] = $form['row'][0]['measured_state'];
$panel_form['row'][2]['group'] = $form['row'][1]['group'];
// Custom panel form
$panel_form = ['type' => 'rows',
'title' => 'Search Statuses',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
$panel_form['row'][3]['status_type'] = $form['row'][1]['status_type'];
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) {
unset($form['row'][$row][$param]['grid']);
}
}
}
$panel_form['row'][4]['status_descr'] = $form['row'][1]['status_descr'];
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['entPhysicalClass'] = $form['row'][0]['entPhysicalClass'];
//$panel_form['row'][5]['sort'] = $form['row'][0]['sort'];
$panel_form['row'][5]['search'] = $form['row'][1]['search'];
$panel_form['row'][1]['status_event'] = $form['row'][0]['status_event'];
$panel_form['row'][1]['status_name'] = $form['row'][0]['status_name'];
// Register custom panel
register_html_panel(generate_form($panel_form));
$panel_form['row'][2]['measured_state'] = $form['row'][0]['measured_state'];
$panel_form['row'][2]['group'] = $form['row'][1]['group'];
$panel_form['row'][3]['status_type'] = $form['row'][1]['status_type'];
$panel_form['row'][4]['status_descr'] = $form['row'][1]['status_descr'];
//$panel_form['row'][5]['sort'] = $form['row'][0]['sort'];
$panel_form['row'][5]['search'] = $form['row'][1]['search'];
// Register custom panel
register_html_panel(generate_form($panel_form));
}
// EOF

View File

@ -6,113 +6,98 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
function generate_storage_query($vars)
{
$sql = "SELECT * FROM `storage`";
$sql = "SELECT * FROM `storage`";
if (in_array($vars['sort'], [ 'hostname', 'device', 'device_id' ]))
{
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
if (in_array($vars['sort'], ['hostname', 'device', 'device_id'])) {
$sql .= ' LEFT JOIN `devices` USING(`device_id`)';
}
$sql .= ' WHERE 1' . generate_query_permitted(array('device'));
$sql .= ' WHERE 1' . generate_query_permitted(['device']);
// Build query
if (!isset($vars['ignored'])) { $vars['ignored'] = 0; }
foreach($vars as $var => $value)
{
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'storage.storage_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'storage.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'storage.device_id');
break;
case "descr":
case "storage_descr";
$sql .= generate_query_values_and($value, 'storage_descr', '%LIKE%');
break;
case 'ignored':
$sql .= generate_query_values_and($value, 'storage.storage_ignore');
break;
}
if (!isset($vars['ignored'])) {
$vars['ignored'] = 0;
}
foreach ($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'storage.storage_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'storage.device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'storage.device_id');
break;
case "descr":
case "storage_descr";
$sql .= generate_query_values_and($value, 'storage_descr', '%LIKE%');
break;
case 'ignored':
$sql .= generate_query_values_and($value, 'storage.storage_ignore');
break;
}
}
switch ($vars['sort_order'])
{
case 'desc':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
switch ($vars['sort_order']) {
case 'desc':
$sort_order = 'DESC';
$sort_neg = 'ASC';
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
default:
$sort_order = 'ASC';
$sort_neg = 'DESC';
}
switch($vars['sort'])
{
case 'usage':
$sql .= ' ORDER BY `storage_perc` '.$sort_neg;
break;
case 'descr':
case 'mountpoint':
$sql .= ' ORDER BY `storage_descr` '.$sort_order;
break;
case 'size':
case 'free':
case 'used':
$sql .= ' ORDER BY `storage_'.$vars['sort'].'` '.$sort_order;
break;
case 'device':
case 'hostname':
$sql .= ' ORDER BY `hostname` '.$sort_order;
break;
default:
$sql .= ' ORDER BY `storage_descr` '.$sort_order;
break;
switch ($vars['sort']) {
case 'usage':
$sql .= ' ORDER BY `storage_perc` ' . $sort_neg;
break;
case 'descr':
case 'mountpoint':
$sql .= ' ORDER BY `storage_descr` ' . $sort_order;
break;
case 'size':
case 'free':
case 'used':
$sql .= ' ORDER BY `storage_' . $vars['sort'] . '` ' . $sort_order;
break;
case 'device':
case 'hostname':
$sql .= ' ORDER BY `hostname` ' . $sort_order;
break;
default:
$sql .= ' ORDER BY `storage_descr` ' . $sort_order;
break;
}
return $sql;
}
function print_storage_table($vars) {
global $cache, $config;
function print_storage_table($vars)
{
$graph_type = "storage_usage";
$sql = generate_storage_query($vars);
$storages = [];
foreach (dbFetchRows($sql) as $storage)
{
if (isset($cache['devices']['id'][$storage['device_id']]))
{
$storage['hostname'] = $cache['devices']['id'][$storage['device_id']]['hostname'];
$storage['html_row_class'] = $cache['devices']['id'][$storage['device_id']]['html_row_class'];
// FIXME. Should be part of humanize_storage()
$storage['human_type'] = array_preg_replace($config['rewrites']['storage_type_regexp'], $storage['storage_type']);
$storages[] = $storage;
}
}
$storages = dbFetchRows($sql);
$storages_count = count($storages);
@ -120,10 +105,9 @@ function print_storage_table($vars) {
$pagination_html = pagination($vars, $storages_count);
echo $pagination_html;
if ($vars['pageno'])
{
if ($vars['pageno']) {
$storages = array_chunk($storages, $vars['pagesize']);
$storages = $storages[$vars['pageno']-1];
$storages = $storages[$vars['pageno'] - 1];
}
// End Pagination
@ -131,9 +115,8 @@ function print_storage_table($vars) {
print_storage_table_header($vars);
foreach ($storages as $storage)
{
print_storage_row($storage, $vars);
foreach ($storages as $storage) {
print_storage_row($storage, $vars);
}
echo("</tbody></table>");
@ -146,228 +129,233 @@ function print_storage_table($vars) {
function print_storage_table_header($vars)
{
if ($vars['view'] === "graphs" || isset($vars['graph']))
{
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
if ($vars['view'] === "graphs" || isset($vars['graph'])) {
$table_class = OBS_CLASS_TABLE_STRIPED_TWO;
} else {
$table_class = OBS_CLASS_TABLE_STRIPED;
}
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = [
[ NULL, 'class="state-marker"' ],
'device' => [ 'Device', 'style="width: 250px;"' ],
'mountpoint' => [ 'Mountpoint' ],
'fstype' => [ 'FS Type', 'style="width: 90px;"' ],
'size' => [ 'Size', 'style="width: 100px;"' ],
'used' => [ 'Used', 'style="width: 100px;"' ],
'free' => [ 'Free', 'style="width: 100px;"' ],
[ '', 'style="width: 100px;"' ],
'usage' => [ 'Usage %', 'style="width: 200px;"' ],
];
echo('<table class="' . $table_class . '">' . PHP_EOL);
$cols = [
[NULL, 'class="state-marker"'],
'device' => ['Device', 'style="width: 250px;"'],
'mountpoint' => ['Mountpoint'],
'fstype' => ['FS Type', 'style="width: 90px;"'],
'size' => ['Size', 'style="width: 100px;"'],
'used' => ['Used', 'style="width: 100px;"'],
'free' => ['Free', 'style="width: 100px;"'],
['', 'style="width: 100px;"'],
'usage' => ['Usage %', 'style="width: 200px;"'],
];
if ($vars['page'] === "device") {
unset($cols['device']);
}
if ($vars['page'] === "device") {
unset($cols['device']);
}
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
}
function print_storage_row($storage, $vars) {
function print_storage_row($storage, $vars)
{
echo generate_storage_row($storage, $vars);
echo generate_storage_row($storage, $vars);
}
function generate_storage_row($storage, $vars) {
function generate_storage_row($storage, $vars)
{
global $config;
global $config;
$table_cols = 9;
if ($vars['page'] !== "device" && $vars['popup'] != TRUE) { $table_cols++; } // Add a column for device.
$table_cols = 9;
if ($vars['page'] !== "device" && $vars['popup'] != TRUE) {
$table_cols++;
} // Add a column for device.
if(isset($vars['graph_type']) && $vars['graph_type'] === "perc")
if (isset($vars['graph_type']) && $vars['graph_type'] === "perc") {
$graph_array = [];
}
$graph_array['to'] = get_time();
$graph_array['id'] = $storage['storage_id'];
$graph_array['type'] = 'storage_usage';
$graph_array['legend'] = "no";
$graph_array = array();
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $storage['storage_id'];
$graph_array['type'] = 'storage_usage';
$graph_array['legend'] = "no";
$link_array = $graph_array;
$link_array['page'] = "graphs";
unset($link_array['height'], $link_array['width'], $link_array['legend']);
$link_graph = generate_url($link_array);
$link_array = $graph_array;
$link_array['page'] = "graphs";
unset($link_array['height'], $link_array['width'], $link_array['legend']);
$link_graph = generate_url($link_array);
$link = generate_url(["page" => "device", "device" => $storage['device_id'], "tab" => "health", "metric" => 'storage']);
$link = generate_url( array("page" => "device", "device" => $storage['device_id'], "tab" => "health", "metric" => 'storage'));
$overlib_content = generate_overlib_content($graph_array, $storage['hostname'] . ' - ' . $storage['storage_descr']);
$overlib_content = generate_overlib_content($graph_array, $storage['hostname'] . ' - ' . $storage['storage_descr']);
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = get_time('day');
$mini_graph = generate_graph_tag($graph_array);
$graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00';
$graph_array['from'] = $config['time']['day'];
$mini_graph = generate_graph_tag($graph_array);
$total = format_bytes($storage['storage_size']);
$used = format_bytes($storage['storage_used']);
$free = format_bytes($storage['storage_free']);
$total = formatStorage($storage['storage_size']);
$used = formatStorage($storage['storage_used']);
$free = formatStorage($storage['storage_free']);
$background = get_percentage_colours($storage['storage_perc']);
$background = get_percentage_colours($storage['storage_perc']);
if ($storage['storage_ignore']) {
$storage['row_class'] = 'suppressed';
} else {
$storage['row_class'] = $background['class'];
}
if ($storage['storage_ignore'])
{
$storage['row_class'] = 'suppressed';
} else {
$storage['row_class'] = $background['class'];
}
$row = '<tr class="ports ' . $storage['row_class'] . '">
$row = '<tr class="ports ' . $storage['row_class'] . '">
<td class="state-marker"></td>';
if ($vars['page'] !== "device" && $vars['popup'] != TRUE) { $row .= '<td class="entity">' . generate_device_link($storage) . '</td>'; }
if ($vars['page'] !== "device" && $vars['popup'] != TRUE) {
$row .= '<td class="entity">' . generate_device_link($storage) . '</td>';
}
$row .= ' <td class="entity">'.generate_entity_link('storage', $storage).'</td>
<td>'.$storage['human_type'].'</td>
<td>'.$total.'</td>
<td>'.$used.'</td>
<td>'.$free.'</td>
<td>'.overlib_link($link_graph, $mini_graph, $overlib_content).'</td>
<td><a href="'.$link_graph.'">
' . print_percentage_bar(400, 20, $storage['storage_perc'], $storage['storage_perc'].'%', "ffffff", $background['left'], 100-$storage['storage_perc']."%" , "ffffff", $background['right']).'
$row .= ' <td class="entity">' . generate_entity_link('storage', $storage) . '</td>
<td>' . $storage['human_type'] . '</td>
<td>' . $total . '</td>
<td>' . $used . '</td>
<td>' . $free . '</td>
<td>' . overlib_link($link_graph, $mini_graph, $overlib_content) . '</td>
<td><a href="' . $link_graph . '">
' . print_percentage_bar(400, 20, $storage['storage_perc'], $storage['storage_perc'] . '%', "ffffff", $background['left'], 100 - $storage['storage_perc'] . "%", "ffffff", $background['right']) . '
</a>
</td>
</tr>
';
if ($vars['view'] === "graphs" && !isset($vars['graph'])) { $vars['graph'] = "bytes,perc"; }
if ($vars['view'] === "graphs" && !isset($vars['graph'])) {
$vars['graph'] = "bytes,perc";
}
if (isset($vars['graph'])) {
$graph_types = explode(',', $vars['graph']);
foreach ($graph_types as $graph_type) {
$graph_type = 'storage_' . $graph_type;
if (isset($vars['graph']))
{
$graph_types = explode(',', $vars['graph']);
$row .= '<tr class="' . $storage['row_class'] . '">';
$row .= '<td class="state-marker"></td>';
$row .= '<td colspan="' . $table_cols . '">';
foreach ($graph_types AS $graph_type) {
$graph_type = 'storage_'.$graph_type;
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = get_time();
$graph_array['id'] = $storage['storage_id'];
$graph_array['type'] = $graph_type;
$row .= '<tr class="' . $storage['row_class'] . '">';
$row .= '<td class="state-marker"></td>';
$row .= '<td colspan="' . $table_cols . '">';
$row .= generate_graph_row($graph_array, TRUE);
unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $storage['storage_id'];
$graph_array['type'] = $graph_type;
$row .= '</td></tr>';
}
} # endif graphs
$row .= generate_graph_row($graph_array, TRUE);
$row .= '</td></tr>';
}
} # endif graphs
return $row;
return $row;
}
function print_storage_form($vars, $single_device = FALSE)
{
//global $config;
//global $config;
$form = array('type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
$form = ['type' => 'rows',
'space' => '10px',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
$form_items = array();
$form_items = [];
if ($single_device)
{
// Single device, just hidden field
$form['row'][0]['device_id'] = array(
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%');
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `storage`'));
if ($single_device) {
// Single device, just hidden field
$form['row'][0]['device_id'] = [
'type' => 'hidden',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%'];
} else {
$form_items['devices'] = generate_form_values('device', dbFetchColumn('SELECT DISTINCT `device_id` FROM `storage`'));
$form['row'][0]['device_id'] = array(
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']);
}
//$sensor_permitted = generate_query_permitted(array('device', 'sensor'));
$form['row'][0]['storage_descr'] = array(
'type' => 'text',
'placeholder' => 'Storage',
'width' => '100%', //'180px',
'grid' => 6,
'value' => $vars['storage_descr']);
// Groups
foreach (get_type_groups('storage') as $entry)
{
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
$form['row'][0]['group'] = array(
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']);
$form['row'][0]['search'] = array(
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
);
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
// Custom panel form
$panel_form = array('type' => 'rows',
'title' => 'Search Storage',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars));
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) { unset($form['row'][$row][$param]['grid']); }
$form['row'][0]['device_id'] = [
'type' => 'multiselect',
'name' => 'Device',
'value' => $vars['device_id'],
'grid' => 2,
'width' => '100%', //'180px',
'values' => $form_items['devices']];
}
}
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['group'] = $form['row'][0]['group'];
//$sensor_permitted = generate_query_permitted(array('device', 'sensor'));
$form['row'][0]['storage_descr'] = [
'type' => 'text',
'placeholder' => 'Storage',
'width' => '100%', //'180px',
'grid' => 6,
'value' => $vars['storage_descr']];
//$panel_form['row'][1]['supply_colour'] = $form['row'][0]['supply_colour'];
//$panel_form['row'][1]['supply_type'] = $form['row'][0]['supply_type'];
// Groups
foreach (get_type_groups('storage') as $entry) {
$form_items['group'][$entry['group_id']] = $entry['group_name'];
}
$form['row'][0]['group'] = [
'community' => FALSE,
'type' => 'multiselect',
'name' => 'Select Groups',
'width' => '100%', //'180px',
'grid' => 2,
'value' => $vars['group'],
'values' => $form_items['group']];
//$panel_form['row'][2]['measured_state'] = $form['row'][0]['measured_state'];
//$panel_form['row'][2]['group'] = $form['row'][1]['group'];
$form['row'][0]['search'] = [
'type' => 'submit',
'grid' => 2,
//'name' => 'Search',
//'icon' => 'icon-search',
'right' => TRUE,
];
$panel_form['row'][3]['storage_descr'] = $form['row'][0]['storage_descr'];
// Show search form
echo '<div class="hidden-xl">';
print_form($form);
echo '</div>';
//$panel_form['row'][5]['sort'] = $form['row'][0]['sort'];
$panel_form['row'][5]['search'] = $form['row'][0]['search'];
// Custom panel form
$panel_form = ['type' => 'rows',
'title' => 'Search Storage',
'space' => '10px',
//'brand' => NULL,
//'class' => '',
'submit_by_key' => TRUE,
'url' => generate_url($vars)];
// Register custom panel
register_html_panel(generate_form($panel_form));
// Clean grids
foreach ($form['row'] as $row => $rows) {
foreach (array_keys($rows) as $param) {
if (isset($form['row'][$row][$param]['grid'])) {
unset($form['row'][$row][$param]['grid']);
}
}
}
// Copy forms
$panel_form['row'][0]['device_id'] = $form['row'][0]['device_id'];
$panel_form['row'][0]['group'] = $form['row'][0]['group'];
//$panel_form['row'][1]['supply_colour'] = $form['row'][0]['supply_colour'];
//$panel_form['row'][1]['supply_type'] = $form['row'][0]['supply_type'];
//$panel_form['row'][2]['measured_state'] = $form['row'][0]['measured_state'];
//$panel_form['row'][2]['group'] = $form['row'][1]['group'];
$panel_form['row'][3]['storage_descr'] = $form['row'][0]['storage_descr'];
//$panel_form['row'][5]['sort'] = $form['row'][0]['sort'];
$panel_form['row'][5]['search'] = $form['row'][0]['search'];
// Register custom panel
register_html_panel(generate_form($panel_form));
}
// EOF

View File

@ -6,201 +6,184 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
function generate_vm_query($vars)
{
$sql = 'SELECT * FROM `vminfo` WHERE 1 ';
$sql = 'SELECT * FROM `vminfo` ';
// Build query
foreach($vars as $var => $value)
{
switch ($var)
{
case "group":
case "group_id":
$values = get_group_entities($value);
$sql .= generate_query_values_and($values, 'vm_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$sql .= generate_query_values_and($values, 'device_id');
break;
case "device":
case "device_id":
$sql .= generate_query_values_and($value, 'device_id');
break;
case "os":
$sql .= generate_query_values_and($value, 'vm_guestos');
break;
case "state":
$sql .= generate_query_values_and($value, 'vm_state');
break;
case "memory":
$sql .= generate_query_values_and($value, 'vm_memory');
break;
case "cpu":
$sql .= generate_query_values_and($value, 'vm_cpucount');
break;
$where = [];
// Build query
foreach ($vars as $var => $value) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$where[] = generate_query_values($values, 'vm_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$where[] = generate_query_values($values, 'device_id');
break;
case "device":
case "device_id":
$where[] = generate_query_values($value, 'device_id');
break;
case "os":
$where[] = generate_query_values($value, 'vm_guestos');
break;
case "state":
$where[] = generate_query_values($value, 'vm_state');
break;
case "memory":
$where[] = generate_query_values($value, 'vm_memory');
break;
case "cpu":
$where[] = generate_query_values($value, 'vm_cpucount');
break;
}
}
}
$sql .= $GLOBALS['cache']['where']['devices_permitted'];
return $sql;
$where[] = $GLOBALS['cache']['where']['devices_permitted'];
$sql .= generate_where_clause($where);
return $sql;
}
function print_vm_table_header($vars)
{
$stripe_class = "table-striped";
$stripe_class = "table-striped";
echo('<table class="table ' . $stripe_class . ' table-condensed ">' . PHP_EOL);
$cols = array(
// array(NULL, 'class="state-marker"'), // FIXME useful when we start polling VM status
'device' => array('Device', 'style="width: 250px;"'),
'name' => array('Name'),
'state' => array('State'),
'os' => array('Operating System'),
'memory' => array('Memory'),
'cpu' => array('CPU'),
);
echo('<table class="table ' . $stripe_class . ' table-condensed ">' . PHP_EOL);
$cols = [ // [ NULL, 'class="state-marker"' ], // FIXME useful when we start polling VM status
'device' => ['Device', 'style="width: 250px;"'],
'name' => ['Name'],
'state' => ['State'],
'os' => ['Operating System'],
'type' => ['Guest Type', 'style="width: 80px;"'],
'memory' => ['Memory'],
'cpu' => ['CPU'],
];
if ($vars['page'] == "device" || $vars['popup'] == TRUE )
{
unset($cols['device']);
}
if ($vars['page'] === "device" || get_var_true($vars['popup'])) {
unset($cols['device']);
}
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
echo(get_table_header($cols, $vars));
echo('<tbody>' . PHP_EOL);
}
function print_vm_table($vars)
{
$sql = generate_vm_query($vars);
$sql = generate_vm_query($vars);
$vms = array();
foreach(dbFetchRows($sql) as $vm)
{
if (isset($GLOBALS['cache']['devices']['id'][$vm['device_id']]))
{
$vm['hostname'] = $GLOBALS['cache']['devices']['id'][$vm['device_id']]['hostname'];
$vms[] = $vm;
$vms = [];
foreach (dbFetchRows($sql) as $vm) {
if ($device = device_by_id_cache($vm['device_id'])) {
$vm['hostname'] = $device['hostname'];
$vms[] = $vm;
}
}
}
// Sorting
// FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
switch ($vars['sort_order'])
{
case 'desc':
$sort_order = SORT_DESC;
$sort_neg = SORT_ASC;
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = SORT_ASC;
$sort_neg = SORT_DESC;
}
switch ($vars['sort'])
{
case 'name':
$vms = array_sort_by($vms, 'vm_name', $sort_order, SORT_STRING);
break;
case 'os':
$vms = array_sort_by($vms, 'vm_os', $sort_order, SORT_STRING);
break;
case 'state':
$vms = array_sort_by($vms, 'vm_state', $sort_order, SORT_STRING);
break;
case 'memory':
$vms = array_sort_by($vms, 'vm_memory', $sort_order, SORT_NUMERIC);
break;
case 'cpu':
$vms = array_sort_by($vms, 'vm_cpucount', $sort_order, SORT_NUMERIC);
break;
default:
// Not sorted
}
$vms_count = count($vms);
// Sorting
// FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
switch ($vars['sort_order']) {
case 'desc':
$sort_order = SORT_DESC;
$sort_neg = SORT_ASC;
break;
case 'reset':
unset($vars['sort'], $vars['sort_order']);
// no break here
default:
$sort_order = SORT_ASC;
$sort_neg = SORT_DESC;
}
switch ($vars['sort']) {
case 'name':
$vms = array_sort_by($vms, 'vm_name', $sort_order, SORT_STRING);
break;
case 'os':
$vms = array_sort_by($vms, 'vm_os', $sort_order, SORT_STRING);
break;
case 'state':
$vms = array_sort_by($vms, 'vm_state', $sort_order, SORT_STRING);
break;
case 'memory':
$vms = array_sort_by($vms, 'vm_memory', $sort_order, SORT_NUMERIC);
break;
case 'cpu':
$vms = array_sort_by($vms, 'vm_cpucount', $sort_order, SORT_NUMERIC);
break;
default:
// Not sorted
}
$vms_count = count($vms);
// Pagination
$pagination_html = pagination($vars, $vms_count);
echo $pagination_html;
// Pagination
$pagination_html = pagination($vars, $vms_count);
echo $pagination_html;
if ($vars['pageno'])
{
$vms = array_chunk($vms, $vars['pagesize']);
$vms = $vms[$vars['pageno'] - 1];
}
// End Pagination
if ($vars['pageno']) {
$vms = array_chunk($vms, $vars['pagesize']);
$vms = $vms[$vars['pageno'] - 1];
}
// End Pagination
echo generate_box_open();
echo generate_box_open();
print_vm_table_header($vars);
print_vm_table_header($vars);
foreach($vms as $vm)
{
print_vm_row($vm, $vars);
}
foreach ($vms as $vm) {
print_vm_row($vm, $vars);
}
echo '</tbody></table>';
echo '</tbody></table>';
echo generate_box_close();
echo generate_box_close();
echo $pagination_html;
echo $pagination_html;
}
function print_vm_row($vm, $vars)
{
echo generate_vm_row($vm, $vars);
echo generate_vm_row($vm, $vars);
}
function generate_vm_row($vm, $vars)
{
global $config;
global $config;
$table_cols = "8";
//print_vars($vm);
$out = '<tr class="' . $vm['row_class'] . '">'; // <td class="state-marker"></td>'; // FIXME useful when we start polling VM state
if ($vars['page'] != "device" && $vars['popup'] != TRUE )
{
$out .= '<td class="entity">' . generate_device_link($vm) . '</td>';
$table_cols++;
}
$out .= '<td class="entity">'. generate_entity_link('virtualmachine', $vm) .'</td>';
$out .= '<td>'. nicecase($vm['vm_state']) .'</td>';
$table_cols = "8";
switch ($vm['vm_guestos'])
{
case 'E: tools not installed':
$out .= ' <td class="small">Unknown (VMware Tools not installed)</td>';
break;
case 'E: tools not running':
$out .= ' <td class="small">Unknown (VMware Tools not running)</td>';
break;
case '':
$out .= ' <td class="small"><i>(Unknown)</i></td>';
break;
default:
if (isset($config['vmware_guestid'][$vm['vm_guestos']]))
{
$out .= ' <td>' . $config['vmware_guestid'][$vm['vm_guestos']] . '</td>';
} else {
$out .= ' <td>' . $vm['vm_guestos'] . '</td>';
}
break;
}
$out = '<tr class="' . $vm['row_class'] . '">'; // <td class="state-marker"></td>'; // FIXME useful when we start polling VM state
if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
$out .= '<td class="entity">' . generate_device_link($vm) . '</td>';
$table_cols++;
}
$out .= '<td class="entity">' . generate_entity_link('virtualmachine', $vm) . '</td>';
$out .= '<td>' . nicecase($vm['vm_state']) . '</td>';
$out .= '<td>'. format_bi($vm['vm_memory'] * 1024 * 1024, 3, 3) .'B</td>';
$out .= '<td>'. $vm['vm_cpucount'] .'</td>';
$out .= '</tr>';
$guestos = rewrite_vm_guestos($vm['vm_guestos'], $vm['vm_type']);
if (str_starts_with($guestos, 'Unknown')) {
$out .= ' <td class="small">'.$guestos.'</td>';
} else {
$out .= ' <td>' . $guestos . '</td>';
}
return $out;
$out .= '<td>' . nicecase($vm['vm_type']) . '</td>';
$out .= '<td>' . format_bi($vm['vm_memory'] * 1024 * 1024, 3, 3) . 'B</td>';
$out .= '<td>' . $vm['vm_cpucount'] . '</td>';
$out .= '</tr>';
return $out;
}
// EOF