From 5ca7379aafd7cf9e782cea6300179cb3d1066155 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Thu, 3 May 2012 15:18:02 +0000 Subject: [PATCH] GOGO git-svn-id: http://www.observium.org/svn/observer/trunk@3129 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/map.php | 8 +- .../polling/unix-agent/munin-plugins.inc.php | 120 +++++++++++++++ includes/polling/unix-agent/packages.inc.php | 144 ++++++++++++++++++ 3 files changed, 271 insertions(+), 1 deletion(-) create mode 100755 includes/polling/unix-agent/munin-plugins.inc.php create mode 100755 includes/polling/unix-agent/packages.inc.php diff --git a/html/map.php b/html/map.php index 124631d6f..891ad3d99 100755 --- a/html/map.php +++ b/html/map.php @@ -14,6 +14,8 @@ include_once("../includes/dbFacile.php"); include_once("includes/functions.inc.php"); include_once("includes/authenticate.inc.php"); +if (strpos($_SERVER['REQUEST_URI'], "anon")) { $anon = 1; } + if (is_array($config['branding'])) { if ($config['branding'][$_SERVER['SERVER_NAME']]) @@ -58,6 +60,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) $links = dbFetch("SELECT * from ports AS I, links AS L WHERE I.device_id = ? AND L.local_interface_id = I.interface_id ORDER BY L.remote_hostname", array($device['device_id'])); if (count($links)) { + if($anon) { $device['hostname'] = md5($device['hostname']); } if (!isset($locations[$device['location']])) { $locations[$device['location']] = $loc_count; $loc_count++; } $loc_id = $locations[$device['location']]; @@ -92,15 +95,18 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) } $src = $device['hostname']; + if($anon) { $src = md5($src); } if ($remote_interface_id) { - $dst = dbFetchCell("SELECT `hostname` FROM `devices` AS D, `ports` AS I WHERE I.interface_id = ? AND D.device_id = I.device_id", array($remote_interface_id)); + $dst = dbFetchCell("SELECT `hostname` FROM `devices` AS D, `ports` AS I WHERE I.interface_id = ? AND D.device_id = I.device_id", array($remote_interface_id)); $dst_host = dbFetchCell("SELECT D.device_id FROM `devices` AS D, `ports` AS I WHERE I.interface_id = ? AND D.device_id = I.device_id", array($remote_interface_id)); } else { unset($dst_host); $dst = $link['remote_hostname']; } + if($anon) { $dst = md5($dst); $src = md5($src);} + $sif = ifNameDescr(dbFetchRow("SELECT * FROM ports WHERE `interface_id` = ?", array($link['local_interface_id'])),$device); if ($remote_interface_id) { diff --git a/includes/polling/unix-agent/munin-plugins.inc.php b/includes/polling/unix-agent/munin-plugins.inc.php new file mode 100755 index 000000000..ac7efc094 --- /dev/null +++ b/includes/polling/unix-agent/munin-plugins.inc.php @@ -0,0 +1,120 @@ + $plugin_data) + { + $plugin = array(); +# list($plugin_type, $instance) = explode("_", $plugin_type); + +# if(!empty($instance)) +# { +# echo("\nPlugin: $plugin_type ($instance)"); +# $plugin_rrd = $plugins_rrd_dir . "/" . $plugin_type."_".$instance; +# $plugin_uniq = $plugin_type."_".$instance; +# } else { + echo("\nPlugin: $plugin_type"); + $plugin_rrd = $plugins_rrd_dir . "/".$plugin_type; + $plugin_uniq = $plugin_type."_"; +# } + + if($debug) { echo("\n[$plugin_data]\n"); } + + foreach(explode("\n", $plugin_data) as $line) + { + list($key, $value) = explode(" ", $line, 2); + if(preg_match("/^graph_/", $key)) + { + list(,$key) = explode("_", $key); + $plugin['graph'][$key] = $value; + } else { + list($metric,$key) = explode(".", $key); + $plugin['values'][$metric][$key] = $value; + } + } + + if(!is_array($plugins_db[$plugin_type])) + { + $insert = array('device_id' => $device['device_id'], 'mplug_type' => $plugin_type, + 'mplug_instance' => ($instance == NULL ? array('NULL') : $instance), + 'mplug_category' => ($plugin['graph']['category'] == NULL ? 'general' : strtolower($plugin['graph']['category'])), + 'mplug_title' => ($plugin['graph']['title'] == NULL ? array('NULL') : $plugin['graph']['title']), + 'mplug_vlabel' => ($plugin['graph']['vlabel'] == NULL ? array('NULL') : $plugin['graph']['vlabel']), + 'mplug_args' => ($plugin['graph']['args'] == NULL ? array('NULL') : $plugin['graph']['args']), + 'mplug_info' => ($plugin['graph']['info'] == NULL ? array('NULL') : $plugin['graph']['info']), + ); + $mplug_id = dbInsert($insert, 'munin_plugins'); + } else { + $mplug_id = $plugins_db[$plugin_type]['id']; + } + + if($mplug_id) + { + + echo(" ID: $mplug_id"); + + $dbq = dbFetchRows("SELECT * FROM `munin_plugins_ds` WHERE `mplug_id` = ?", array($mplug_id)); + foreach ($dbq as $v) + { + $vu = $v['mplug_id']."_".$v['ds_name']; + $ds_list[$vu] = 1; + } + unset($dbq); unset($v); + + foreach($plugin['values'] as $name => $data) + { + echo(" $name"); + if(empty($data['type'])) { $data['type'] = "GAUGE"; } + if(empty($data['graph'])) { $data['graph'] = "yes"; } + if(empty($data['label'])) { $data['label'] = $name; } + if(empty($data['draw'])) { $data['draw'] = "LINE1.5"; } + + $cmd = "--step 300 DS:val:".$data['type'].":600:0:U "; + $cmd .= $config['rrd_rra']; + $ds_uniq = $mplug_id."_".$name; + $filename = $plugin_rrd."_".$name.".rrd"; + if (!is_file($filename)) + { + rrdtool_create($filename, $cmd); + } + rrdtool_update($filename,"N:".$data['value']); + + if(empty($ds_list[$ds_uniq])) + { + $insert = array('mplug_id' => $mplug_id, 'ds_name' => $name, + 'ds_type' => $data['type'], 'ds_label' => $data['label'], + 'ds_cdef' => $data['cdef'], 'ds_draw' => $data['draw'], + 'ds_info' => $data['info'], 'ds_extinfo' => $data['extinfo'], + 'ds_min' => $data['min'], 'ds_max' => $data['max'], + 'ds_graph' => $data['graph'], 'ds_negative' => $data['negative'], + 'ds_warning' => $data['warning'], 'ds_critical' => $data['critical'], + 'ds_colour' => $data['colour'], 'ds_sum' => $data['sum'], + 'ds_stack' => $data['stack'], 'ds_line' => $data['line'], + ); + $ds_id = dbInsert($insert, 'munin_plugins_ds'); + } + + } + } else { + echo("No ID!\n"); + } + } + } + +?> diff --git a/includes/polling/unix-agent/packages.inc.php b/includes/polling/unix-agent/packages.inc.php new file mode 100755 index 000000000..8cb1a1cdf --- /dev/null +++ b/includes/polling/unix-agent/packages.inc.php @@ -0,0 +1,144 @@ + "10" || count($pkgs_db[$manager][$name][$arch], 1) == '0') + { + dbInsert(array('device_id' => $device['device_id'], 'name' => $name, 'manager' => $manager, + 'status' => 1, 'version' => $version, 'build' => $build, 'arch' => $arch, 'size' => $size), 'packages'); + if ($build != "") { $dbuild = '-' . $build; } else { $dbuild = ''; } + echo("+".$name."-".$version.$dbuild."-".$arch); + log_event('Package installed: '.$name.' ('.$arch.') version '.$version.$dbuild, $device, 'package'); + } elseif(count($pkgs_db[$manager][$name][$arch], 1)) { + $pkg_c = dbFetchRow("SELECT * FROM `packages` WHERE `device_id` = ? AND `manager` = ? AND `name` = ? and `arch` = ? ORDER BY version DESC, build DESC", array($device['device_id'], $manager, $name, $arch)); + if ($pkg_c['build'] != "") { $pkg_c_dbuild = '-'.$pkg_c['build']; } else { $pkg_c_dbuild = ''; } + echo("U(".$pkg_c['name']."-".$pkg_c['version'].$pkg_c_dbuild."|".$name."-".$version.$dbuild.")"); + $pkg_update = array('version' => $version, 'build' => $build, 'status' => '1', 'size' => $size); + dbUpdate($pkg_update, 'packages', '`pkg_id` = ?', array($pkg_c['pkg_id'])); + log_event('Package updated: '.$name.' ('.$arch.') from '.$pkg_c['version'].$pkg_c_dbuild .' to '.$version.$dbuild, $device, 'package'); + unset($pkgs_db_id[$pkg_c['pkg_id']]); + } + } + unset($pkg_update); + } + + ## Packages + foreach ($pkgs_db_id as $id => $pkg) + { + dbDelete('packages', "`pkg_id` = ?", array($id)); + echo("-".$pkg['text']); + log_event('Package removed: '.$pkg['name'].' '.$pkg['arch'].' '.$pkg['version'].'-'.$pkg['build'], $device, 'package'); + } + + unset($pkg); + unset($pkgs_db_id); + unset($pkg_c); + unset($pkgs); + unset($pkgs_db); + unset($pkgs_db_db); + +?>