From 130d1c452a2bd36b31560a5e74e6ed1646daa866 Mon Sep 17 00:00:00 2001 From: Daniel Preussker Date: Mon, 7 Sep 2015 19:29:30 +0100 Subject: [PATCH 1/4] Added application and munin search operations --- html/ajax_search.php | 108 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 99 insertions(+), 9 deletions(-) diff --git a/html/ajax_search.php b/html/ajax_search.php index 791513972c..e42655ee90 100644 --- a/html/ajax_search.php +++ b/html/ajax_search.php @@ -96,23 +96,22 @@ if (isset($_REQUEST['search'])) { }//end if $json = json_encode($device); - print_r($json); - exit; + die($json); } else if ($_REQUEST['type'] == 'ports') { // Search ports if (is_admin() === true || is_read() === true) { - $results = dbFetchRows("SELECT `ports`.*,`devices`.* FROM `ports` LEFT JOIN `devices` ON `ports`.`device_id` = `devices`.`device_id` WHERE `ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%' ORDER BY ifDescr LIMIT 8"); + $results = dbFetchRows("SELECT `ports`.*,`devices`.* FROM `ports` LEFT JOIN `devices` ON `ports`.`device_id` = `devices`.`device_id` WHERE `ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%' OR `ifName` LIKE '%".$search."%' ORDER BY ifDescr LIMIT 8"); } else { - $results = dbFetchRows("SELECT DISTINCT(`I`.`port_id`), `I`.*, `D`.`hostname` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` AND (`ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%') ORDER BY ifDescr LIMIT 8", array($_SESSION['user_id'], $_SESSION['user_id'])); + $results = dbFetchRows("SELECT DISTINCT(`I`.`port_id`), `I`.*, `D`.`hostname` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` AND (`ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%' OR `ifName` LIKE '%".$search."%') ORDER BY ifDescr LIMIT 8", array($_SESSION['user_id'], $_SESSION['user_id'])); } if (count($results)) { $found = 1; foreach ($results as $result) { - $name = $result['ifDescr']; + $name = $result['ifDescr'] == $result['ifAlias'] ? $result['ifName'] : $result['ifDescr']; $description = $result['ifAlias']; if ($result['deleted'] == 0 && ($result['ignore'] == 0 || $result['ignore'] == 0) && ($result['ifInErrors_delta'] > 0 || $result['ifOutErrors_delta'] > 0)) { @@ -143,13 +142,13 @@ if (isset($_REQUEST['search'])) { 'description' => $description, 'colours' => $highlight_colour, 'hostname' => $result['hostname'], + 'port_id' => $result['port_id'], ); }//end foreach }//end if $json = json_encode($ports); - print_r($json); - exit; + die($json); } else if ($_REQUEST['type'] == 'bgp') { // Search bgp peers @@ -204,8 +203,99 @@ if (isset($_REQUEST['search'])) { }//end if $json = json_encode($bgp); - print_r($json); - exit; + die($json); + } + else if ($_REQUEST['type'] == 'applications') { + // Device search + if (is_admin() === true || is_read() === true) { + $results = dbFetchRows("SELECT * FROM `applications` INNER JOIN `devices` ON devices.device_id = applications.device_id WHERE `app_type` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%' ORDER BY hostname LIMIT 8"); + } + else { + $results = dbFetchRows("SELECT * FROM `applications` INNER JOIN `devices` AS `D` ON `D`.`device_id` = `applications`.`device_id` INNER JOIN `devices_perms` AS `P` ON `P`.`device_id` = `D`.`device_id` WHERE `P`.`user_id` = ? AND (`app_type` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%') ORDER BY hostname LIMIT 8", array($_SESSION['user_id'])); + } + + if (count($results)) { + $found = 1; + $devices = count($results); + + foreach ($results as $result) { + $name = $result['app_type']; + if ($result['disabled'] == 1) { + $highlight_colour = '#808080'; + } + else if ($result['ignored'] == 1 && $result['disabled'] == 0) { + $highlight_colour = '#000000'; + } + else if ($result['status'] == 0 && $result['ignore'] == 0 && $result['disabled'] == 0) { + $highlight_colour = '#ff0000'; + } + else if ($result['status'] == 1 && $result['ignore'] == 0 && $result['disabled'] == 0) { + $highlight_colour = '#008000'; + } + + $device[] = array( + 'name' => $name, + 'hostname' => $result['hostname'], + 'app_id' => $result['app_id'], + 'device_id' => $result['device_id'], + 'colours' => $highlight_colour, + 'device_image' => getImageSrc($result), + 'device_hardware' => $result['hardware'], + 'device_os' => $config['os'][$result['os']]['text'], + 'version' => $result['version'], + 'location' => $result['location'], + ); + }//end foreach + }//end if + + $json = json_encode($device); + die($json); + } + else if ($_REQUEST['type'] == 'munin') { + // Device search + if (is_admin() === true || is_read() === true) { + $results = dbFetchRows("SELECT * FROM `munin_plugins` INNER JOIN `devices` ON devices.device_id = munin_plugins.device_id WHERE `mplug_type` LIKE '%".$search."%' OR `mplug_title` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%' ORDER BY hostname LIMIT 8"); + } + else { + $results = dbFetchRows("SELECT * FROM `munin_plugins` INNER JOIN `devices` AS `D` ON `D`.`device_id` = `munin_plugins`.`device_id` INNER JOIN `devices_perms` AS `P` ON `P`.`device_id` = `D`.`device_id` WHERE `P`.`user_id` = ? AND (`mplug_type` LIKE '%".$search."%' OR `mplug_title` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%') ORDER BY hostname LIMIT 8", array($_SESSION['user_id'])); + } + + if (count($results)) { + $found = 1; + $devices = count($results); + + foreach ($results as $result) { + $name = $result['mplug_title']; + if ($result['disabled'] == 1) { + $highlight_colour = '#808080'; + } + else if ($result['ignored'] == 1 && $result['disabled'] == 0) { + $highlight_colour = '#000000'; + } + else if ($result['status'] == 0 && $result['ignore'] == 0 && $result['disabled'] == 0) { + $highlight_colour = '#ff0000'; + } + else if ($result['status'] == 1 && $result['ignore'] == 0 && $result['disabled'] == 0) { + $highlight_colour = '#008000'; + } + + $device[] = array( + 'name' => $name, + 'hostname' => $result['hostname'], + 'device_id' => $result['device_id'], + 'colours' => $highlight_colour, + 'device_image' => getImageSrc($result), + 'device_hardware' => $result['hardware'], + 'device_os' => $config['os'][$result['os']]['text'], + 'version' => $result['version'], + 'location' => $result['location'], + 'plugin' => $result['mplug_type'], + ); + }//end foreach + }//end if + + $json = json_encode($device); + die($json); }//end if }//end if }//end if From e8f7f3b6f83918060672402189de50000e6eb098 Mon Sep 17 00:00:00 2001 From: Daniel Preussker Date: Mon, 7 Sep 2015 19:30:22 +0100 Subject: [PATCH 2/4] Add reload lock if widget is in settings mode --- html/pages/front/tiles.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/html/pages/front/tiles.php b/html/pages/front/tiles.php index e679f5079e..9c7c5c933e 100644 --- a/html/pages/front/tiles.php +++ b/html/pages/front/tiles.php @@ -202,7 +202,7 @@ foreach (dbFetchRows("SELECT * FROM `widgets` ORDER BY `widget_title`") as $widg }); function widget_dom(data) { - dom = '
  • '+ + dom = '
  • '+ '
    '+data.title+''+ ''+ ''+ @@ -273,8 +273,10 @@ foreach (dbFetchRows("SELECT * FROM `widgets` ORDER BY `widget_title`") as $widg } function grab_data(id,refresh,data_type) { + if( $("#widget_body_"+id).parent().data('settings') == 0 ) { + widget_reload(id,data_type); + } new_refresh = refresh * 1000; - widget_reload(id,data_type); setTimeout(function() { grab_data(id,refresh,data_type); }, From e67ccd9463f08394f41678c8d70b448edd41ccdd Mon Sep 17 00:00:00 2001 From: Daniel Preussker Date: Mon, 7 Sep 2015 19:30:37 +0100 Subject: [PATCH 3/4] Added multiple graph type support for the graph widget --- html/includes/common/generic-graph.inc.php | 288 ++++++++++++++++++--- 1 file changed, 246 insertions(+), 42 deletions(-) diff --git a/html/includes/common/generic-graph.inc.php b/html/includes/common/generic-graph.inc.php index 3ac02ab698..4e75b16ca1 100644 --- a/html/includes/common/generic-graph.inc.php +++ b/html/includes/common/generic-graph.inc.php @@ -26,35 +26,107 @@ if( defined('show_settings') || empty($widget_settings) ) { $common_output[] = '
    - -
    - +
    +
    -
    -
    -
    -
    -
    - +
    +
    +
    + +
    +
    + +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    + +
    +
    -'; } else { - $widget_settings['device_id'] = dbFetchCell('select device_id from devices where hostname = ?',array($widget_settings['graph_device'])); - $widget_settings['title'] = $widget_settings['graph_device']." / ".$widget_settings['graph_type']; - $common_output[] = generate_minigraph_image( - array('device_id'=>(int) $widget_settings['device_id']), - $config['time']['day'], - $config['time']['now'], - $widget_settings['graph_type'], - $widget_settings['graph_legend'] == 1 ? 'yes' : 'no', - $widget_dimensions['x'], - $widget_dimensions['y'], - '&', - 'minigraph-image', - 1 - ); + $widget_settings['title'] = ""; + $type = array_shift(explode('_',$widget_settings['graph_type'],2)); + $widget_settings['graph_'.$type] = json_decode($widget_settings['graph_'.$type],true); + if ($type == 'device') { + $widget_settings['title'] = $widget_settings['graph_device']['name']." / ".$widget_settings['graph_type']; + $param = 'device='.$widget_settings['graph_device']['device_id']; + } + elseif ($type == 'application') { + $param = 'id='.$widget_settings['graph_'.$type]['app_id']; + } + elseif ($type == 'munin') { + $param = 'device='.$widget_settings['graph_'.$type]['device_id'].'&plugin='.$widget_settings['graph_'.$type]['name']; + } + else { + $param = 'id='.$widget_settings['graph_'.$type][$type.'_id']; + } + if (empty($widget_settings['title'])) { + $widget_settings['title'] = $widget_settings['graph_'.$type]['hostname']." / ".$widget_settings['graph_'.$type]['name']." / ".$widget_settings['graph_type']; + } + $common_output[] = ''; } - From a4d27d3eba3e26bdf34ab9e4f640b5689f046c18 Mon Sep 17 00:00:00 2001 From: Daniel Preussker Date: Mon, 7 Sep 2015 19:52:22 +0100 Subject: [PATCH 4/4] scrut fixes --- html/includes/common/generic-graph.inc.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/html/includes/common/generic-graph.inc.php b/html/includes/common/generic-graph.inc.php index 4e75b16ca1..81776efe1c 100644 --- a/html/includes/common/generic-graph.inc.php +++ b/html/includes/common/generic-graph.inc.php @@ -41,7 +41,8 @@ if( defined('show_settings') || empty($widget_settings) ) { foreach (get_graph_subtypes($type) as $avail_type) { $display_type = is_mib_graph($type, $avail_type) ? $avail_type : nicecase($avail_type); if( strstr($display_type,'_') ) { - $sub = array_shift(explode('_',$display_type,2)); + $sub = explode('_',$display_type,2); + $sub = array_shift($sub); if( $sub != $old ) { $old = $sub; $common_output[] = ''; @@ -304,7 +305,8 @@ $(function() { } else { $widget_settings['title'] = ""; - $type = array_shift(explode('_',$widget_settings['graph_type'],2)); + $type = explode('_',$widget_settings['graph_type'],2); + $type = array_shift($type); $widget_settings['graph_'.$type] = json_decode($widget_settings['graph_'.$type],true); if ($type == 'device') { $widget_settings['title'] = $widget_settings['graph_device']['name']." / ".$widget_settings['graph_type'];