diff --git a/discovery.php b/discovery.php index 088bff22b8..dc2ceebaa2 100755 --- a/discovery.php +++ b/discovery.php @@ -70,12 +70,12 @@ if (file_exists('.svn')) list(,$dbu_rev) = preg_split('/: /',@shell_exec('svn info database-update.sql|grep ^Revision')); $device_query = mysql_query("SELECT revision FROM `dbSchema`"); - if ($rev = @mysql_fetch_array($device_query)) + if ($rev = @mysql_fetch_array($device_query)) { $db_rev = $rev['revision']; - } - else - { + } + else + { $db_rev = 0; } diff --git a/includes/functions.php b/includes/functions.php index 67ada4f355..80bd2aa9fe 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -40,7 +40,7 @@ function zeropad_lineno($num, $length) { $num = '0'.$num; } - + return $num; } @@ -61,7 +61,7 @@ function logfile($string) function set_dev_attrib($device, $attrib_type, $attrib_value) { $count_sql = "SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; - if (mysql_result(mysql_query($count_sql),0)) + if (mysql_result(mysql_query($count_sql),0)) { $update_sql = "UPDATE devices_attribs SET attrib_value = '$attrib_value' WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; mysql_query($update_sql); @@ -71,14 +71,14 @@ function set_dev_attrib($device, $attrib_type, $attrib_value) $insert_sql = "INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . mres($device['device_id'])."', '$attrib_type', '$attrib_value')"; mysql_query($insert_sql); } - + return mysql_affected_rows(); } function get_dev_attrib($device, $attrib_type) { $sql = "SELECT attrib_value FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; - if ($row = mysql_fetch_assoc(mysql_query($sql))) + if ($row = mysql_fetch_assoc(mysql_query($sql))) { return $row['attrib_value']; } @@ -118,7 +118,7 @@ function device_array($device_id) function getHostOS($device) { global $config; - + $sysDescr = snmp_get ($device, "SNMPv2-MIB::sysDescr.0", "-Ovq"); $sysObjectId = snmp_get ($device, "SNMPv2-MIB::sysObjectID.0", "-Ovqn"); @@ -127,13 +127,13 @@ function getHostOS($device) $dir_handle = @opendir($config['install_dir'] . "/includes/discovery/os") or die("Unable to open $path"); while ($file = readdir($dir_handle)) { - if ( preg_match("/.php$/", $file) ) + if (preg_match("/.php$/", $file) ) { include($config['install_dir'] . "/includes/discovery/os/" . $file); } } closedir($dir_handle); - + if ($os) { return $os; } else { return "generic"; } } @@ -142,15 +142,15 @@ function formatRates($rate) { return $rate; } -function formatstorage($rate, $round = '2') +function formatstorage($rate, $round = '2') { $rate = format_bi($rate, $round) . "B"; return $rate; } -function format_si($rate) +function format_si($rate) { - if($rate >= "0.1") { + if ($rate >= "0.1") { $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); $round = Array('2','2','2','2','2','2','2','2','2'); $ext = $sizes[0]; @@ -165,7 +165,7 @@ function format_si($rate) return round($rate, $round[$i]).$ext; } -function format_bi($size, $round = '2') +function format_bi($size, $round = '2') { $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); $ext = $sizes[0]; @@ -178,17 +178,18 @@ function percent_colour($perc) $r = min(255, 5 * ($perc - 25)); $b = max(0, 255 - (5 * ($perc + 25))); return sprintf('#%02x%02x%02x', $r, $b, $b); -} +} function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/out errors value in RRD { global $config; $cmd = $config['rrdtool']." fetch -s $period -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5"; $data = trim(shell_exec($cmd)); - foreach( explode("\n", $data) as $entry) { - list($in, $out) = explode(" ", $entry); - $in_errors += ($in * 300); - $out_errors += ($out * 300); + foreach (explode("\n", $data) as $entry) + { + list($in, $out) = explode(" ", $entry); + $in_errors += ($in * 300); + $out_errors += ($out * 300); } $errors['in'] = round($in_errors); $errors['out'] = round($out_errors); @@ -196,23 +197,23 @@ function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/ou } # FIXME: below function is unused, only commented out in html/pages/device/overview/ports.inc.php - do we still need it? -function device_traffic_image($device, $width, $height, $from, $to) +function device_traffic_image($device, $width, $height, $from, $to) { return ""; } -function getImage($host) +function getImage($host) { global $config; $sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'"; $data = mysql_fetch_array(mysql_query($sql)); $type = strtolower($data['os']); if ($config['os'][$type]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$type]['icon'] . ".png")) - { + { $image = ''; } elseif ($config['os'][$type]['icon'] && file_exists($config['html_dir'] . "/images/os/". $config['os'][$type]['icon'] . ".gif")) - { - $image = ''; + { + $image = ''; } else { if (file_exists($config['html_dir'] . "/images/os/$type" . ".png")){ $image = ''; } elseif (file_exists($config['html_dir'] . "/images/os/$type" . ".gif")){ $image = ''; } @@ -234,7 +235,7 @@ function renamehost($id, $new) { eventlog("Hostname changed -> $new (console)", $id); } -function delete_port($int_id) +function delete_port($int_id) { $interface = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` AS P, `devices` AS D WHERE P.interface_id = '".$int_id."' AND D.device_id = P.device_id")); mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '$int_id'"); @@ -250,7 +251,7 @@ function delete_port($int_id) shell_exec("rm -rf ".trim($config['rrd_dir'])."/".trim($interface['hostname'])."/".$interface['ifIndex'].".rrd"); } -function delete_device($id) +function delete_device($id) { global $config; $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); @@ -266,7 +267,7 @@ function delete_device($id) mysql_query("DELETE FROM `devices_attribs` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `devices_perms` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `bgpPeers` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `vlans` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `vlans` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `vrfs` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `storage` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'"); @@ -284,15 +285,19 @@ function delete_device($id) return $ret; } -function addHost($host, $community, $snmpver, $port = 161) +function addHost($host, $community, $snmpver, $port = 161) { global $config; list($hostshort) = explode(".", $host); - if ( isDomainResolves($host)) { - if ( isPingable($host)) { - if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' ) { + if (isDomainResolves($host)) + { + if (isPingable($host)) + { + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' ) + { $snmphost = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0"); - if ($snmphost == $host || $hostshort = $host) { + if ($snmphost == $host || $hostshort = $host) + { createHost ($host, $community, $snmpver, $port); } else { echo("Given hostname does not match SNMP-read hostname!\n"); } } else { echo("Already got host $host\n"); } @@ -300,35 +305,35 @@ function addHost($host, $community, $snmpver, $port = 161) } else { echo("Could not resolve $host\n"); } } -function scanUDP ($host, $port, $timeout) -{ - $handle = fsockopen($host, $port, $errno, $errstr, 2); - if (!$handle) { - } - socket_set_timeout ($handle, $timeout); - $write = fwrite($handle,"\x00"); - if (!$write) { next; } - $startTime = time(); - $header = fread($handle, 1); - $endTime = time(); - $timeDiff = $endTime - $startTime; - if ($timeDiff >= $timeout) { - fclose($handle); return 1; - } else { fclose($handle); return 0; } +function scanUDP ($host, $port, $timeout) +{ + $handle = fsockopen($host, $port, $errno, $errstr, 2); + if (!$handle) { + } + socket_set_timeout ($handle, $timeout); + $write = fwrite($handle,"\x00"); + if (!$write) { next; } + $startTime = time(); + $header = fread($handle, 1); + $endTime = time(); + $timeDiff = $endTime - $startTime; + if ($timeDiff >= $timeout) { + fclose($handle); return 1; + } else { fclose($handle); return 0; } } -function netmask2cidr($netmask) +function netmask2cidr($netmask) { list ($network, $cidr) = explode("/", trim(`ipcalc $address/$mask | grep Network | cut -d" " -f 4`)); return $cidr; } -function cidr2netmask() +function cidr2netmask() { return (long2ip(ip2long("255.255.255.255") << (32-$netmask))); } -function formatUptime($diff, $format="long") +function formatUptime($diff, $format="long") { $yearsDiff = floor($diff/31536000); $diff -= $yearsDiff*31536000; @@ -339,9 +344,9 @@ function formatUptime($diff, $format="long") $minsDiff = floor($diff/60); $diff -= $minsDiff*60; $secsDiff = $diff; - + $uptime = ""; - + if ($format == "short") { if ($yearsDiff > '0') { $uptime .= $yearsDiff . "y "; } if ($daysDiff > '0') { $uptime .= $daysDiff . "d "; } @@ -358,7 +363,7 @@ function formatUptime($diff, $format="long") return trim($uptime); } -function isSNMPable($hostname, $community, $snmpver, $port) +function isSNMPable($hostname, $community, $snmpver, $port) { global $config; $pos = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -$snmpver -c $community -t 1 $hostname:$port sysObjectID.0"); @@ -379,8 +384,8 @@ function isPingable($hostname) { } } -function is_odd($number) { - return $number & 1; // 0 = even, 1 = odd +function is_odd($number) { + return $number & 1; // 0 = even, 1 = odd } function isValidInterface($if) { @@ -400,9 +405,9 @@ function isValidInterface($if) { } else { return 0; } } -function utime() +function utime() { - $time = explode( " ", microtime()); + $time = explode(" ", microtime()); $usec = (double)$time[0]; $sec = (double)$time[1]; return $sec + $usec; @@ -465,7 +470,7 @@ function createHost ($host, $community, $snmpver, $port = 161) { $host = trim(strtolower($host)); $device = array('hostname' => $host, 'community' => $community, 'snmpver' => $snmpver, 'port' => $port); - $host_os = getHostOS($device); + $host_os = getHostOS($device); if ($host_os) { $sql = mysql_query("INSERT INTO `devices` (`hostname`, `sysName`, `community`, `port`, `os`, `status`,`snmpver`) VALUES ('$host', '$host', '$community', '$port', '$host_os', '1','$snmpver')"); @@ -475,9 +480,9 @@ function createHost ($host, $community, $snmpver, $port = 161) # vv FIXME set_dev_attrib() mysql_query("INSERT INTO devices_attribs (attrib_type, attrib_value, device_id) VALUES ('discover','1','$device_id')"); return("Created host : $host (id:$device_id) (os:$host_os)"); - } - else - { + } + else + { return FALSE; } } @@ -492,11 +497,11 @@ function isDomainResolves($domain) return gethostbyname($domain) != $domain; } -function hoststatus($id) +function hoststatus($id) { $sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'"); $result = @mysql_result($sql, 0); - + return $result; } @@ -519,7 +524,7 @@ function match_network ($nets, $ip, $first=false) if ($first && $return) return true; } } - + return $return; } @@ -528,7 +533,7 @@ function snmp2ipv6($ipv6_snmp) $ipv6 = explode('.',$ipv6_snmp); for ($i = 0;$i <= 15;$i++) { $ipv6[$i] = zeropad(dechex($ipv6[$i])); } for ($i = 0;$i <= 15;$i+=2) { $ipv6_2[] = $ipv6[$i] . $ipv6[$i+1]; } - + return implode(':',$ipv6_2); } @@ -538,7 +543,7 @@ function ipv62snmp($ipv6) for ($i = 0;$i < 8;$i++) { $ipv6_ex[$i] = zeropad_lineno($ipv6_ex[$i],4); } $ipv6_ip = implode('',$ipv6_ex); for ($i = 0;$i < 32;$i+=2) $ipv6_split[] = hexdec(substr($ipv6_ip,$i,2)); - + return implode('.',$ipv6_split); } @@ -548,13 +553,14 @@ function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_orig $ipv6_network = trim(shell_exec($config['sipcalc']." $ipv6_address/$ipv6_prefixlen | grep Subnet | cut -f 2 -d '-'")); $ipv6_compressed = trim(shell_exec($config['sipcalc']." $ipv6_address/$ipv6_prefixlen | grep Compressed | cut -f 2 -d '-'")); - + $ipv6_type = trim(shell_exec($config['sipcalc']." $ipv6_address/$ipv6_prefixlen | grep \"Address type\" | cut -f 2- -d '-'")); - + if ($ipv6_type == "Link-Local Unicast Addresses") return; # ignore link-locals (coming from IPV6-MIB) if (mysql_result(mysql_query("SELECT count(*) FROM `ports` - WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') { + WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') + { $i_query = "SELECT interface_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"; $interface_id = mysql_result(mysql_query($i_query), 0); if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') { @@ -573,7 +579,11 @@ function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_orig mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `interface_id`) VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$interface_id')"); echo("+"); - } else { echo("."); } + } + else + { + echo("."); + } $full_address = "$ipv6_address/$ipv6_prefixlen"; $valid = $full_address . "-" . $interface_id; $valid_v6[$valid] = 1; @@ -614,36 +624,36 @@ function eventlog($eventtext,$device_id = "", $interface_id = "") } # Use this function to write to the eventlog table -function log_event($text, $device = NULL, $type = NULL, $reference = NULL) +function log_event($text, $device = NULL, $type = NULL, $reference = NULL) { global $debug; - if(!is_array($device)) { $device = device_by_id_cache($device); } + if (!is_array($device)) { $device = device_by_id_cache($device); } $event_query = "INSERT INTO eventlog (host, reference, type, datetime, message) VALUES (" . ($device['device_id'] ? $device['device_id'] : "NULL"); $event_query .= ", '" . ($reference ? $reference : "NULL") . "', '" . ($type ? $type : "NULL") . "', NOW(), '" . mres($text) . "')"; if ($debug) { echo($event_query . "\n"); } mysql_query($event_query); -} +} function notify($device,$title,$message) { global $config; - if($config['alerts']['email']['enable']) + if ($config['alerts']['email']['enable']) { - if($config['alerts']['email']['default_only']) + if ($config['alerts']['email']['default_only']) { $email = $config['alerts']['email']['default']; } else { - if ($device['sysContact']) - { - $email = $device['sysContact']; - } else { - $email = $config['alerts']['email']['default']; + if ($device['sysContact']) + { + $email = $device['sysContact']; + } else { + $email = $config['alerts']['email']['default']; } } - if($email) + if ($email) { mail($email, $title, $message, $config['email_headers']); } @@ -701,14 +711,14 @@ function isHexString($str) function include_dir($dir, $regex = "") { global $device, $config, $debug; - if ( $regex == "") + if ($regex == "") { $regex = "/\.inc\.php$/"; } - if ($handle = opendir($config['install_dir'] . '/' . $dir)) + if ($handle = opendir($config['install_dir'] . '/' . $dir)) { - while (false !== ($file = readdir($handle))) + while (false !== ($file = readdir($handle))) { if (filetype($config['install_dir'] . '/' . $dir . '/' . $file) == 'file' && preg_match($regex, $file)) { diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 895a5a341a..0c3ff860e8 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -1,11 +1,5 @@ ms - php snmp extension requires the timeout in microseconds. - if(isset($timeout)) { $timeout = $timeout*1000*1000; } - if ($device['snmpver'] == "v2c") - { - $data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); - } elseif ( $device['snmpver'] == "v1") { - $data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); - } - if ($debug) { print "DEBUG: $oid: $data\n"; } - } else { - $cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; - if ($options) { $cmd .= " " . $options; } - if ($mib) { $cmd .= " -m " . $mib; } - if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } + global $debug,$config,$runtime_stats,$mibs_loaded; - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - - $cmd .= " ".$device['hostname'].":".$device['port']." ".$oid; - if (!$debug) { $cmd .= " 2>/dev/null"; } - if ($debug) { echo("$cmd\n"); } - $data = trim(shell_exec($cmd)); - if ($debug) { echo("$data\n"); } - } - $runtime_stats['snmpget']++; - if (is_string($data) && (preg_match("/No Such Instance/i", $data) || preg_match("/No Such Object/i", $data) || preg_match("/No more variables left/i", $data))) { return false; } - elseif ($data) { return $data; } - else { return false; } -} - -function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL) { - global $debug,$config,$runtime_stats; if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } - // php has no bulkwalk functionality, so use binary for this. - if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { - $snmpcommand = $config['snmpwalk']; - } - else { - $snmpcommand = $config['snmpbulkwalk']; - } - $cmd = $snmpcommand . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; - if ($options) { $cmd .= " $options "; } - if ($mib) { $cmd .= " -m $mib"; } - if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - $cmd .= " ".$device['hostname'].":".$device['port']." ".$oid; - if (!$debug) { $cmd .= " 2>/dev/null"; } - if ($debug) { echo("$cmd\n"); } - $data = trim(shell_exec($cmd)); - if ($debug) { echo("$data\n"); } - if (is_string($data) && (preg_match("/No Such (Object|Instance)/i", $data))) - { - $data = false; - } - else { - if (preg_match("/No more variables left in this MIB View \(It is past the end of the MIB tree\)$/",$data)) { - # Bit ugly :-( - $d_ex = explode("\n",$data); - unset($d_ex[count($d_ex)-1]); - $data = implode("\n",$d_ex); - } - } - $runtime_stats['snmpwalk']++; - return $data; + + if ($config['snmp']['internal'] == true) + { + if ($mib && $mibdir && !$mibs_loaded[$mib]) + { + @snmp_read_mib($mibdir."/".$mib); + $mibs_loaded[$mib] = TRUE; + } + snmp_set_quick_print(1); + // s->ms - php snmp extension requires the timeout in microseconds. + if(isset($timeout)) { $timeout = $timeout*1000*1000; } + if ($device['snmpver'] == "v2c") + { + $data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); + } elseif ( $device['snmpver'] == "v1") { + $data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); + } + if ($debug) { print "DEBUG: $oid: $data\n"; } + } + else + { + $cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; + + if ($options) { $cmd .= " " . $options; } + if ($mib) { $cmd .= " -m " . $mib; } + if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + + $cmd .= " ".$device['hostname'].":".$device['port']." ".$oid; + if (!$debug) { $cmd .= " 2>/dev/null"; } + if ($debug) { echo("$cmd\n"); } + $data = trim(shell_exec($cmd)); + if ($debug) { echo("$data\n"); } + } + $runtime_stats['snmpget']++; + if (is_string($data) && (preg_match("/No Such Instance/i", $data) || preg_match("/No Such Object/i", $data) || preg_match("/No more variables left/i", $data))) + { + return false; + } + elseif ($data) { return $data; } + else { return false; } } -function snmpwalk_cache_cip($device, $oid, $array, $mib = 0) { - global $config; - if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } - if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } - if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { - $snmpcommand = $config['snmpwalk']; - } - else { - $snmpcommand = $config['snmpbulkwalk']; - } - $cmd = $snmpcommand . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " "; - if ($mib) { $cmd .= " -m $mib"; } - $cmd .= " -M ".$config['install_dir']."/mibs/"; - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - $cmd .= " ".$device['hostname'].":".$device['port']." ".$oid; - if (!$debug) { $cmd .= " 2>/dev/null"; } - $data = trim(shell_exec($cmd)); - $device_id = $device['device_id']; - #echo("Caching: $oid\n"); - foreach(explode("\n", $data) as $entry) { - list ($this_oid, $this_value) = preg_split("/=/", $entry); - $this_oid = trim($this_oid); - $this_value = trim($this_value); - $this_oid = substr($this_oid, 30); - list($ifIndex,$dir,$a,$b,$c,$d,$e,$f) = explode(".", $this_oid); - $h_a = zeropad(dechex($a)); - $h_b = zeropad(dechex($b)); - $h_c = zeropad(dechex($c)); - $h_d = zeropad(dechex($d)); - $h_e = zeropad(dechex($e)); - $h_f = zeropad(dechex($f)); - $mac = "$h_a$h_b$h_c$h_d$h_e$h_f"; - if ($dir == "1") { $dir = "input"; } elseif ($dir == "2") { $dir = "output"; } - if ($mac && $dir) { - $array[$ifIndex][$mac][$oid][$dir] = $this_value; - } - return $array; - } -} - -function snmp_cache_ifIndex($device) +function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL) { - global $config; + global $debug,$config,$runtime_stats; + if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } + + // php has no bulkwalk functionality, so use binary for this. if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { + { $snmpcommand = $config['snmpwalk']; } else { $snmpcommand = $config['snmpbulkwalk']; } + + $cmd = $snmpcommand . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; + if ($options) { $cmd .= " $options "; } + if ($mib) { $cmd .= " -m $mib"; } + if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + $cmd .= " ".$device['hostname'].":".$device['port']." ".$oid; + + if (!$debug) { $cmd .= " 2>/dev/null"; } + if ($debug) { echo("$cmd\n"); } + $data = trim(shell_exec($cmd)); + if ($debug) { echo("$data\n"); } + + if (is_string($data) && (preg_match("/No Such (Object|Instance)/i", $data))) + { + $data = false; + } + else + { + if (preg_match("/No more variables left in this MIB View \(It is past the end of the MIB tree\)$/",$data)) { + # Bit ugly :-( + $d_ex = explode("\n",$data); + unset($d_ex[count($d_ex)-1]); + $data = implode("\n",$d_ex); + } + } + $runtime_stats['snmpwalk']++; + + return $data; +} + +function snmpwalk_cache_cip($device, $oid, $array, $mib = 0) +{ + global $config; + + if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } + if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } + + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) + { + $snmpcommand = $config['snmpwalk']; + } + else + { + $snmpcommand = $config['snmpbulkwalk']; + } + + $cmd = $snmpcommand . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " "; + if ($mib) { $cmd .= " -m $mib"; } + $cmd .= " -M ".$config['install_dir']."/mibs/"; + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + + $cmd .= " ".$device['hostname'].":".$device['port']." ".$oid; + + if (!$debug) { $cmd .= " 2>/dev/null"; } + $data = trim(shell_exec($cmd)); + $device_id = $device['device_id']; + + #echo("Caching: $oid\n"); + foreach(explode("\n", $data) as $entry) + { + list ($this_oid, $this_value) = preg_split("/=/", $entry); + $this_oid = trim($this_oid); + $this_value = trim($this_value); + $this_oid = substr($this_oid, 30); + list($ifIndex,$dir,$a,$b,$c,$d,$e,$f) = explode(".", $this_oid); + $h_a = zeropad(dechex($a)); + $h_b = zeropad(dechex($b)); + $h_c = zeropad(dechex($c)); + $h_d = zeropad(dechex($d)); + $h_e = zeropad(dechex($e)); + $h_f = zeropad(dechex($f)); + $mac = "$h_a$h_b$h_c$h_d$h_e$h_f"; + if ($dir == "1") { $dir = "input"; } elseif ($dir == "2") { $dir = "output"; } + if ($mac && $dir) + { + $array[$ifIndex][$mac][$oid][$dir] = $this_value; + } + + return $array; + } +} + +function snmp_cache_ifIndex($device) +{ + // FIXME: this has no internal version, and is not yet using our own snmp_* + global $config; + + if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } + if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } + + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) + { + $snmpcommand = $config['snmpwalk']; + } + else + { + $snmpcommand = $config['snmpbulkwalk']; + } + $cmd = $snmpcommand . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " "; $cmd .= " -M ".$config['install_dir']."/mibs/"; - $cmd .= " -m IF-MIB ifIndex"; + $cmd .= " -m IF-MIB ifIndex"; + if (isset($timeout)) { $cmd .= " -t " . $timeout; } if (isset($retries)) { $cmd .= " -r " . $retries; } if (!$debug) { $cmd .= " 2>/dev/null"; } $data = trim(shell_exec($cmd)); $device_id = $device['device_id']; - foreach(explode("\n", $data) as $entry) { + + foreach(explode("\n", $data) as $entry) + { list ($this_oid, $this_value) = preg_split("/=/", $entry); list ($this_oid, $this_index) = explode(".", $this_oid); $this_index = trim($this_index); $this_oid = trim($this_oid); $this_value = trim($this_value); - if (!strstr($this_value, "at this OID") && $this_index) { + if (!strstr($this_value, "at this OID") && $this_index) + { $array[] = $this_value; } } + return $array; } -function snmpwalk_cache_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) +function snmpwalk_cache_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); - foreach(explode("\n", $data) as $entry) { + foreach(explode("\n", $data) as $entry) + { list($oid,$value) = explode("=", $entry); $oid = trim($oid); $value = trim($value); list($oid, $index) = explode(".", $oid); - if (!strstr($value, "at this OID") && isset($oid) && isset($index)) { + if (!strstr($value, "at this OID") && isset($oid) && isset($index)) + { $array[$index][$oid] = $value; } } + return $array; } -function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) +function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { global $cache; - + if (!(is_array($cache['snmp'][$device['device_id']]) && array_key_exists($oid,$cache['snmp'][$device['device_id']]))) { $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); - foreach(explode("\n", $data) as $entry) + foreach(explode("\n", $data) as $entry) { list($r_oid,$value) = explode("=", $entry); $r_oid = trim($r_oid); $value = trim($value); @@ -260,7 +295,7 @@ function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = NULL, $mibdir = if (isset($oid_parts['4'])) { $index .= ".".$oid_parts['4']; } if (isset($oid_parts['5'])) { $index .= ".".$oid_parts['5']; } if (isset($oid_parts['6'])) { $index .= ".".$oid_parts['6']; } - if (!strstr($value, "at this OID") && isset($r_oid) && isset($index)) + if (!strstr($value, "at this OID") && isset($r_oid) && isset($index)) { $array[$index][$r_oid] = $value; } @@ -272,45 +307,53 @@ function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = NULL, $mibdir = } -function snmpwalk_cache_double_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) +function snmpwalk_cache_double_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); - foreach(explode("\n", $data) as $entry) { + + foreach(explode("\n", $data) as $entry) + { list($oid,$value) = explode("=", $entry); $oid = trim($oid); $value = trim($value); list($oid, $first, $second) = explode(".", $oid); - if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) { + if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) + { $double = $first.".".$second; $array[$double][$oid] = $value; } } + return $array; } -function snmpwalk_cache_triple_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) +function snmpwalk_cache_triple_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); foreach(explode("\n", $data) as $entry) { list($oid,$value) = explode("=", $entry); $oid = trim($oid); $value = trim($value); list($oid, $first, $second, $third) = explode(".", $oid); - if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) { + if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) + { $index = $first.".".$second.".".$third; $array[$index][$oid] = $value; } } + return $array; } -function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0) +function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0) { global $config; + if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { + { $snmpcommand = $config['snmpwalk']; } else @@ -326,29 +369,36 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0) if (!$debug) { $cmd .= " 2>/dev/null"; } $data = trim(shell_exec($cmd)); $device_id = $device['device_id']; - foreach(explode("\n", $data) as $entry) { + foreach(explode("\n", $data) as $entry) + { list($oid,$value) = explode("=", $entry); $oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value); list($oid, $first, $second) = explode(".", $oid); - if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) { + if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) + { $array[$first][$second][$oid] = $value; } } + return $array; } -function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0) { +function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0) +{ global $config, $debug; + if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { + { $snmpcommand = $config['snmpwalk']; } else { $snmpcommand = $config['snmpbulkwalk']; } + $cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " "; $cmd .= " -M ".$config['install_dir']."/mibs/"; if ($mib) { $cmd .= " -m $mib"; } @@ -357,31 +407,39 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0) { $cmd .= " ".$device['hostname'].":".$device['port']." ".$oid; if (!$debug) { $cmd .= " 2>/dev/null"; } $data = trim(shell_exec($cmd)); + $device_id = $device['device_id']; - foreach(explode("\n", $data) as $entry) { + foreach(explode("\n", $data) as $entry) + { list($oid,$value) = explode("=", $entry); $oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value); list($oid, $first, $second, $third) = explode(".", $oid); if ($debug) {echo("$entry || $oid || $first || $second || $third\n");} - if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second) && isset($third)) { + if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second) && isset($third)) + { $array[$first][$second][$third][$oid] = $value; } } + return $array; } -function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) { +function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) +{ global $config; + if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { + { $snmpcommand = $config['snmpwalk']; } else { $snmpcommand = $config['snmpbulkwalk']; } + $cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " "; if ($mib) { $cmd .= " -m $mib"; } $cmd .= " -M ".$config['install_dir']."/mibs/"; @@ -391,20 +449,23 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) { if (!$debug) { $cmd .= " 2>/dev/null"; } $data = trim(shell_exec($cmd)); $device_id = $device['device_id']; - foreach(explode("\n", $data) as $entry) { + + foreach(explode("\n", $data) as $entry) + { $entry = str_replace($oid.".", "", $entry); list($slotport, $value) = explode("=", $entry); $slotport = trim($slotport); $value = trim($value); - if ($array[$slotport]['ifIndex']) { + if ($array[$slotport]['ifIndex']) + { $ifIndex = $array[$slotport]['ifIndex']; - #$array[$slotport][$oid] = $value; $array[$ifIndex][$oid] = $value; } } + return $array; } -function snmp_cache_oid($oid, $device, $array, $mib = 0) +function snmp_cache_oid($oid, $device, $array, $mib = 0) { $array = snmpwalk_cache_oid($device, $oid, $array, $mib); return $array; @@ -412,11 +473,15 @@ function snmp_cache_oid($oid, $device, $array, $mib = 0) function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) { global $config; + if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } - foreach($oids as $oid){ + + foreach($oids as $oid) + { $string .= " $oid.$port"; } + $cmd = $config['snmpget'] . " -O vq -" . $device['snmpver'] . " -c " . $device['community'] . " "; if (isset($timeout)) { $cmd .= " -t " . $timeout; } if (isset($retries)) { $cmd .= " -r " . $retries; } @@ -435,13 +500,17 @@ function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) { } $x++; } + return $array; } -function snmp_cache_portIfIndex ($device, $array) { +function snmp_cache_portIfIndex ($device, $array) +{ global $config; + if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } + $cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O q -" . $device['snmpver'] . " -c " . $device['community'] . " "; $cmd .= " -M ".$config['install_dir']."/mibs/"; if (isset($timeout)) { $cmd .= " -t " . $timeout; } @@ -449,7 +518,9 @@ function snmp_cache_portIfIndex ($device, $array) { $cmd .= " ".$device['hostname'].":".$device['port']." portIfIndex"; $output = trim(shell_exec($cmd)); $device_id = $device['device_id']; - foreach(explode("\n", $output) as $entry){ + + foreach(explode("\n", $output) as $entry) + { $entry = str_replace("CISCO-STACK-MIB::portIfIndex.", "", $entry); list($slotport, $ifIndex) = explode(" ", $entry); if ($slotport && $ifIndex){ @@ -457,13 +528,17 @@ function snmp_cache_portIfIndex ($device, $array) { $array[$slotport]['ifIndex'] = $ifIndex; } } + return $array; } -function snmp_cache_portName ($device, $array) { +function snmp_cache_portName ($device, $array) +{ global $config; + if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } + $cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " "; $cmd .= " -M ".$config['install_dir']."/mibs/"; if (isset($timeout)) { $cmd .= " -t " . $timeout; } @@ -472,16 +547,20 @@ function snmp_cache_portName ($device, $array) { $output = trim(shell_exec($cmd)); $device_id = $device['device_id']; #echo("Caching: portName\n"); - foreach(explode("\n", $output) as $entry){ + + foreach(explode("\n", $output) as $entry) + { $entry = str_replace("portName.", "", $entry); list($slotport, $portName) = explode("=", $entry); $slotport = trim($slotport); $portName = trim($portName); - if ($array[$slotport]['ifIndex']) { + if ($array[$slotport]['ifIndex']) + { $ifIndex = $array[$slotport]['ifIndex']; $array[$slotport]['portName'] = $portName; $array[$ifIndex]['portName'] = $portName; } } + return $array; } ?> diff --git a/poller.php b/poller.php index 38b888f97f..bcd4ee0dd5 100755 --- a/poller.php +++ b/poller.php @@ -18,18 +18,18 @@ elseif ($options['h'] == "all") { $where = " "; $doing = "all"; } elseif ($options['h']) { if (is_numeric($options['h'])) { - $where = "AND `device_id` = '".$options['h']."'"; + $where = "AND `device_id` = '".$options['h']."'"; $doing = $options['h']; } else { - $where = "AND `hostname` LIKE '".str_replace('*','%',mres($options['h']))."'"; + $where = "AND `hostname` LIKE '".str_replace('*','%',mres($options['h']))."'"; $doing = $options['h']; } } if (isset($options['i']) && $options['i'] && isset($options['n'])) { - $where = "AND MOD(device_id,".$options['i'].") = '" . $options['n'] . "'"; + $where = "AND MOD(device_id,".$options['i'].") = '" . $options['n'] . "'"; $doing = $options['n'] ."/".$options['i']; } @@ -46,7 +46,7 @@ if (!$where) { exit; } -if (isset($options['d'])) { +if (isset($options['d'])) { echo("DEBUG!\n"); $debug = TRUE; ini_set('display_errors', 1); @@ -65,7 +65,7 @@ if (isset($options['d'])) { echo("Starting polling run:\n\n"); $polled_devices = 0; $device_query = mysql_query("SELECT `device_id` FROM `devices` WHERE `ignore` = 0 AND `disabled` = 0 $where ORDER BY `device_id` ASC"); -while ($device = mysql_fetch_assoc($device_query)) +while ($device = mysql_fetch_assoc($device_query)) { $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device['device_id']."'")); $status = 0; unset($array); @@ -75,7 +75,7 @@ while ($device = mysql_fetch_assoc($device_query)) if($config['os'][$device['os']]['group']) {$device['os_group'] = $config['os'][$device['os']]['group']; echo("(".$device['os_group'].")");} echo("\n"); - unset($poll_update); unset($poll_update_query); unset($poll_separator); unset($version); unset($uptime); unset($features); + unset($poll_update); unset($poll_update_query); unset($poll_separator); unset($version); unset($uptime); unset($features); unset($sysLocation); unset($hardware); unset($sysDescr); unset($sysContact); unset($sysName); unset($serial); $host_rrd = $config['rrd_dir'] . "/" . $device['hostname']; @@ -106,8 +106,8 @@ while ($device = mysql_fetch_assoc($device_query)) notify($device, "Device ".($status == '1' ? 'Up' : 'Down').": " . $device['hostname'], "Device ".($status == '1' ? 'up' : 'down').": " . $device['hostname'] . " at " . date($config['timestamp_format'])); } - if ($status == "1") - { + if ($status == "1") + { $graphs = array(); $oldgraphs = array(); @@ -130,7 +130,7 @@ while ($device = mysql_fetch_assoc($device_query)) $agent_uptime = $uptime; ## Move uptime into agent_uptime #HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (63050465) 7 days, 7:08:24.65 $hrSystemUptime = str_replace("(", "", $hrSystemUptime); - $hrSystemUptime = str_replace(")", "", $hrSystemUptime); + $hrSystemUptime = str_replace(")", "", $hrSystemUptime); list($days,$hours, $mins, $secs) = explode(":", $hrSystemUptime); list($secs, $microsecs) = explode(".", $secs); $hours = $hours + ($days * 24); @@ -150,17 +150,17 @@ while ($device = mysql_fetch_assoc($device_query)) $uptime = $secs; } - if (is_numeric($uptime)) + if (is_numeric($uptime)) { if ( $uptime < $device['uptime'] ) { notify($device,"Device rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago."); log_event('Device rebooted after '.formatUptime($device['uptime']), $device['device_id'], 'reboot', $device['uptime']); } - + $uptimerrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd"; - - if (!is_file($uptimerrd)) + + if (!is_file($uptimerrd)) { rrdtool_create ($uptimerrd, "DS:uptime:GAUGE:600:0:U RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797"); } @@ -172,14 +172,14 @@ while ($device = mysql_fetch_assoc($device_query)) $poll_update .= $poll_separator . "`uptime` = '$uptime'"; $poll_separator = ", "; - } + } - if (is_file($config['install_dir'] . "/includes/polling/os/".$device['os'].".inc.php")) + if (is_file($config['install_dir'] . "/includes/polling/os/".$device['os'].".inc.php")) { /// OS Specific include($config['install_dir'] . "/includes/polling/os/".$device['os'].".inc.php"); } - elseif ($device['os_group'] && is_file($config['install_dir'] . "/includes/polling/os/".$device['os_group'].".inc.php")) + elseif ($device['os_group'] && is_file($config['install_dir'] . "/includes/polling/os/".$device['os_group'].".inc.php")) { /// OS Group Specific include($config['install_dir'] . "/includes/polling/os/".$device['os_group'].".inc.php"); @@ -191,8 +191,8 @@ while ($device = mysql_fetch_assoc($device_query)) echo("Hardware: ".$hardware." Version: ".$version." Features: ".$features."\n"); - $sysLocation = str_replace("\"","", $sysLocation); - + $sysLocation = str_replace("\"","", $sysLocation); + include("includes/polling/ipmi.inc.php"); include("includes/polling/temperatures.inc.php"); include("includes/polling/humidity.inc.php"); @@ -222,49 +222,49 @@ while ($device = mysql_fetch_assoc($device_query)) unset( $update ) ; unset( $seperator) ; - + if ( $serial && $serial != $device['serial'] ) { $poll_update .= $poll_separator . "`serial` = '".mres($serial)."'"; $poll_separator = ", "; log_event("Serial -> $serial", $device['device_id'], 'system'); } - + if ( $sysContact && $sysContact != $device['sysContact'] ) { $poll_update .= $poll_separator . "`sysContact` = '".mres($sysContact)."'"; $poll_separator = ", "; log_event("Contact -> $sysContact", $device['device_id'], 'system'); } - + if ( $sysName && $sysName != $device['sysName'] ) { $poll_update .= $poll_separator . "`sysName` = '$sysName'"; $poll_separator = ", "; log_event("sysName -> $sysName", $device['device_id'], 'system'); } - + if ( $sysDescr && $sysDescr != $device['sysDescr'] ) { $poll_update .= $poll_separator . "`sysDescr` = '$sysDescr'"; $poll_separator = ", "; log_event("sysDescr -> $sysDescr", $device['device_id'], 'system'); } - + if ( $sysLocation && $device['location'] != $sysLocation ) { $poll_update .= $poll_separator . "`location` = '$sysLocation'"; $poll_separator = ", "; log_event("Location -> $sysLocation", $device['device_id'], 'system'); } - + if ( $version && $device['version'] != $version ) { $poll_update .= $poll_separator . "`version` = '$version'"; $poll_separator = ", "; log_event("OS Version -> $version", $device['device_id'], 'system'); } - + if ( $features != $device['features'] ) { $poll_update .= $poll_separator . "`features` = '$features'"; $poll_separator = ", "; log_event("OS Features -> $features", $device['device_id'], 'system'); } - + if ( $hardware && $hardware != $device['hardware'] ) { $poll_update .= $poll_separator . "`hardware` = '$hardware'"; $poll_separator = ", "; @@ -276,7 +276,7 @@ while ($device = mysql_fetch_assoc($device_query)) $polled_devices++; echo("\n"); - } + } ## FIX ME EVENTLOGGING ### This code cycles through the graphs already known in the database and the ones we've defined as being polled here @@ -287,7 +287,7 @@ while ($device = mysql_fetch_assoc($device_query)) while($graph = mysql_fetch_array($query)){ if(!isset($graphs[$graph[0]])) { - mysql_query("DELETE FROM `device_graphs` WHERE `device_id` = '".$device['device_id']."' AND `graph` = '".$graph[0]."'"); + mysql_query("DELETE FROM `device_graphs` WHERE `device_id` = '".$device['device_id']."' AND `graph` = '".$graph[0]."'"); } else { $oldgraphs[$graph[0]] = TRUE; } @@ -312,16 +312,16 @@ while ($device = mysql_fetch_assoc($device_query)) if($debug) {echo("Updating " . $device['hostname'] . " - $poll_update_query \n");} $poll_update_result = mysql_query($poll_update_query); if(mysql_affected_rows() == "1") { echo("UPDATED!\n"); } else { echo("NOT UPDATED!\n"); } - + unset($storage_cache); // Clear cache of hrStorage ** MAYBE FIXME? ** unset($cache); // Clear cache (unify all things here?) -} +} $poller_end = utime(); $poller_run = $poller_end - $poller_start; $poller_time = substr($poller_run, 0, 5); if($polled_devices) { - mysql_query("INSERT INTO `perf_times` (`type`, `doing`, `start`, `duration`, `devices`) + mysql_query("INSERT INTO `perf_times` (`type`, `doing`, `start`, `duration`, `devices`) VALUES ('poll', '$doing', '$poller_start', '$poller_time', '$polled_devices')"); }