more code cleanups, modify renamehost to also take a source parameter so we can build a renamehost function into the web gui some day

git-svn-id: http://www.observium.org/svn/observer/trunk@1980 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans 2011-03-27 10:21:19 +00:00
parent 7ffefc0d57
commit 340c71b2e7
27 changed files with 110 additions and 107 deletions

View File

@ -38,7 +38,7 @@ if (isset($argv[1]) && $argv[1])
}
list($hostshort) = explode(".", $host);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '".mres($host)."'"), 0) == '0' )
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '".mres($host)."'"), 0) == '0')
{
if (isDomainResolves($argv[1]))
{

View File

@ -73,13 +73,13 @@ if (isset($options['d']))
if (!$where)
{
echo("-h <device id> | <device hostname wildcard> Poll single device\n");
echo("-h odd Poll odd numbered devices (same as -i 2 -n 0)\n");
echo("-h even Poll even numbered devices (same as -i 2 -n 1)\n");
echo("-h all Poll all devices\n");
echo("-h new Poll all devices that have not had a discovery run before\n\n");
echo("-i <instances> -n <number> Poll as instance <number> of <instances>\n");
echo(" Instances start at 0. 0-3 for -n 4\n\n");
echo("-d Enable debugging output\n");
echo("-h odd Poll odd numbered devices (same as -i 2 -n 0)\n");
echo("-h even Poll even numbered devices (same as -i 2 -n 1)\n");
echo("-h all Poll all devices\n");
echo("-h new Poll all devices that have not had a discovery run before\n\n");
echo("-i <instances> -n <number> Poll as instance <number> of <instances>\n");
echo(" Instances start at 0. 0-3 for -n 4\n\n");
echo("-d Enable debugging output\n");
echo("\n");
echo("No polling type specified!\n");
exit;

View File

@ -187,7 +187,7 @@ function device_permitted($device_id)
if ($_SESSION['userlevel'] >= "5")
{
$allowed = true;
} elseif ($permissions['device'][$device_id] ) {
} elseif ($permissions['device'][$device_id]) {
$allowed = true;
} else {
$allowed = false;
@ -307,8 +307,8 @@ function geteventicon($message)
{
if ($message == "Device status changed to Down") { $icon = "server_connect.png"; }
if ($message == "Device status changed to Up") { $icon = "server_go.png"; }
if ($message == "Interface went down" || $message == "Interface changed state to Down" ) { $icon = "if-disconnect.png"; }
if ($message == "Interface went up" || $message == "Interface changed state to Up" ) { $icon = "if-connect.png"; }
if ($message == "Interface went down" || $message == "Interface changed state to Down") { $icon = "if-disconnect.png"; }
if ($message == "Interface went up" || $message == "Interface changed state to Up") { $icon = "if-connect.png"; }
if ($message == "Interface disabled") { $icon = "if-disable.png"; }
if ($message == "Interface enabled") { $icon = "if-enable.png"; }
if (isset($icon)) { return $icon; } else { return false; }

View File

@ -192,7 +192,7 @@ if (strpos($interface['label'], "oopback") === false && !$graph_type)
if ($int_links_phys[$int_link]) { echo("<img align=absmiddle src='images/16/connect.png'> "); } else {
echo("<img align=absmiddle src='images/16/bullet_go.png'> "); }
echo("<b>" . generate_port_link($link_if, makeshortif($link_if['label'])) . " on " . generate_device_link($link_if, shorthost($link_if['hostname'])) );
echo("<b>" . generate_port_link($link_if, makeshortif($link_if['label'])) . " on " . generate_device_link($link_if, shorthost($link_if['hostname'])));
if ($int_links_v6[$int_link]) { echo(" <b style='color: #a10000;'>v6</b>"); }
if ($int_links_v4[$int_link]) { echo(" <b style='color: #00a100'>v4</b>"); }

View File

@ -113,7 +113,8 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
$map .= "\"$dst\" [URL=\"{$config['base_url']}/device/$dst_host/map/\" fontsize=20 shape=box3d]\n";
if ($dst_host == $device['device_id'] || $where == '') {
if ($dst_host == $device['device_id'] || $where == '')
{
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n";
} else {
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n";
@ -156,7 +157,8 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
if ($where == '') { $maptool = 'neato -Gpack'; }
$img = shell_exec("echo \"".addslashes($map)."\" | $maptool -T".$_GET['format']."");
if ($_GET['format'] == "png") {
if ($_GET['format'] == "png")
{
header("Content-type: image/".$_GET['format']);
} elseif ($_GET['format'] == "svg") {
header("Content-type: image/svg+xml");

View File

@ -24,9 +24,9 @@ if ($_POST['hostname'] && $_POST['community'])
} else {
echo("<p class='errorbox'><b>Error:</b> You don't have the necessary privileges to add hosts.</p>");
}
} elseif ($_POST['hostname'] && !$_POST['community'] ) {
} elseif ($_POST['hostname'] && !$_POST['community']) {
echo("<p class='errorbox'><b>Error:</b> A community string is required.</p>");
} elseif (!$_POST['hostname'] && $_POST['community'] ) {
} elseif (!$_POST['hostname'] && $_POST['community']) {
echo("<p class='errorbox'><b>Error:</b> A hostname is required.</p>");
}
@ -35,27 +35,28 @@ if ($_POST['hostname'] && $_POST['community'])
<form name="form1" method="post" action="<?php echo($config['base_url']); ?>/addhost/">
<p>Devices will be checked for Ping and SNMP reachability before being probed. Only devices with recognised OSes will be added.</p>
<div style="padding: 10px; background: #f0f0f0;">
<table cellpadding=2px>
<tr>
<td><strong>Hostname</strong></td>
<td><input type="text" name="hostname" size="32"></td>
</tr>
<td><strong>Community</strong></td>
<td><input type="text" name="community" size="32"></td>
</tr>
<tr>
<td><strong>SNMP Version</strong></td>
<td><select name="snmpver">
<option value="v1">v1</option>
<option value="v2c" selected>v2c</option>
</select>
&nbsp;<strong>Port</strong> <input type="text" name="port" size="16">
</td>
</tr>
<tr>
<td></td><td><input type="submit" class="submit" name="Submit" value="Add Host"></td>
</tr>
</table>
</div>
<div style="padding: 10px; background: #f0f0f0;">
<table cellpadding=2px>
<tr>
<td><strong>Hostname</strong></td>
<td><input type="text" name="hostname" size="32"></td>
</tr>
<td><strong>Community</strong></td>
<td><input type="text" name="community" size="32"></td>
</tr>
<tr>
<td><strong>SNMP Version</strong></td>
<td>
<select name="snmpver">
<option value="v1">v1</option>
<option value="v2c" selected>v2c</option>
</select>
&nbsp;<strong>Port</strong> <input type="text" name="port" size="16">
</td>
</tr>
<tr>
<td></td><td><input type="submit" class="submit" name="Submit" value="Add Host"></td>
</tr>
</table>
</div>
</form>

View File

@ -1,6 +1,6 @@
<?php
if ($_GET['opta'] == graphs )
if ($_GET['opta'] == 'graphs')
{
if ($_GET['optb']) { $graph_type = "port_" . $_GET['optb']; } else { $graph_type = "port_bits"; }
}
@ -53,7 +53,7 @@ if ($_GET['optc'] == thumbs)
}
echo("</div>");
} else {
if ($_GET['opta'] == "arp" )
if ($_GET['opta'] == "arp")
{
include("arp.inc.php");
} elseif ($_GET['opta'] == "adsl") {
@ -70,7 +70,7 @@ if ($_GET['optc'] == thumbs)
echo("</table></div>");
echo("<div style='min-height: 150px;'></div>");
} else {
if ($_GET['opta'] == "details" ) { $port_details = 1; }
if ($_GET['opta'] == "details") { $port_details = 1; }
echo("<div style='margin: 0px;'><table border=0 cellspacing=0 cellpadding=5 width=100%>");
$i = "1";
$interface_query = mysql_query("select * from ports WHERE device_id = '".$device['device_id']."' AND deleted = '0' ORDER BY `ifIndex` ASC");

View File

@ -75,7 +75,7 @@ while ($peer = mysql_fetch_array($sql)){
$sql = mysql_query("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '84600' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'");
while ($device = mysql_fetch_array($sql)){
if (device_permitted($device['device_id']) && $device['attrib_value'] < "84600" && $device['attrib_type'] == "uptime" ) {
if (device_permitted($device['device_id']) && $device['attrib_value'] < "84600" && $device['attrib_type'] == "uptime") {
echo("<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ddffdd;'>
<strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #090;'>Device<br />Rebooted</span><br />

View File

@ -75,7 +75,7 @@ while ($peer = mysql_fetch_array($sql)){
$sql = mysql_query("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '84600' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'");
while ($device = mysql_fetch_array($sql)){
if (device_permitted($device['device_id']) && $device['attrib_value'] < "84600" && $device['attrib_type'] == "uptime" ) {
if (device_permitted($device['device_id']) && $device['attrib_value'] < "84600" && $device['attrib_type'] == "uptime") {
echo("<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ddffdd;'>
<strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #090;'>Device<br />Rebooted</span><br />

View File

@ -57,7 +57,7 @@ while ($interface = mysql_fetch_array($query))
{
list($addy, $mask) = explode("/", $_POST['address']);
if (!$mask) { $mask = "32"; }
if (!match_network($addy . "/" . $mask, $interface['ipv4_address'] )) { $ignore = 1; }
if (!match_network($addy . "/" . $mask, $interface['ipv4_address'])) { $ignore = 1; }
}
if (!$ignore)

View File

@ -1,6 +1,6 @@
<?php print_optionbar_start(28); ?>
<table cellpadding=0 cellspacing=0 class=devicetable width=100%>
<table cellpadding="0" cellspacing="0" class="devicetable" width="100%">
<tr>
<form method="post" action="">
<td width="200">
@ -74,7 +74,7 @@ while ($interface = mysql_fetch_array($query))
$error_img = generate_port_link($interface,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
} else { $error_img = ""; }
if (port_permitted($interface['interface_id']) )
if (port_permitted($interface['interface_id']))
{
echo('<tr bgcolor="' . $row_colour . '">
<td class="list-bold">' . generate_device_link($interface) . '</td>

View File

@ -5,7 +5,7 @@ function delete_port($interface_id)
$ipaddrs = mysql_query("SELECT * FROM `ipaddr` WHERE `interface_id` = '$interface_id'");
while ($ipaddr = mysql_fetch_array($ipaddrs))
{
echo("<div style='padding-left:8px; font-weight: normal;'>Deleting IPv4 address " . $ipaddr['addr'] . "/" . $ipaddr['cidr'] );
echo("<div style='padding-left:8px; font-weight: normal;'>Deleting IPv4 address " . $ipaddr['addr'] . "/" . $ipaddr['cidr']);
mysql_query("DELETE FROM addr WHERE id = '".$addr['id']."'");
echo("</div>");
}
@ -13,7 +13,7 @@ function delete_port($interface_id)
$ip6addr = mysql_query("SELECT * FROM `ip6addr` WHERE `interface_id` = '$interface_id'");
while ($ip6addr = mysql_fetch_array($ip6addrs))
{
echo("<div style='padding-left:8px; font-weight: normal;'>Deleting IPv6 address " . $ip6addr['ip6_comp_addr'] . "/" . $ip6addr['ip6_prefixlen'] );
echo("<div style='padding-left:8px; font-weight: normal;'>Deleting IPv6 address " . $ip6addr['ip6_comp_addr'] . "/" . $ip6addr['ip6_prefixlen']);
mysql_query("DELETE FROM ip6addr WHERE ip6_addr_id = '".$ip6addr['ip6_addr_id']."'");
echo("</div>");
}
@ -21,7 +21,7 @@ function delete_port($interface_id)
$ip6addr = mysql_query("SELECT * FROM `ip6addr` WHERE `interface_id` = '$interface_id'");
while ($ip6addr = mysql_fetch_array($ip6addrs))
{
echo("<div style='padding-left:8px; font-weight: normal;'>Deleting IPv6 address " . $ip6addr['ip6_comp_addr'] . "/" . $ip6addr['ip6_prefixlen'] );
echo("<div style='padding-left:8px; font-weight: normal;'>Deleting IPv6 address " . $ip6addr['ip6_comp_addr'] . "/" . $ip6addr['ip6_prefixlen']);
mysql_query("DELETE FROM ip6addr WHERE ip6_addr_id = '".$ip6addr['ip6_addr_id']."'");
echo("</div>");
}
@ -37,7 +37,7 @@ function delete_port($interface_id)
$ports = mysql_query("SELECT * FROM `ports` WHERE `deleted` = '1'");
while ($port = mysql_fetch_array($ports))
{
echo("<div style='font-weight: bold;'>Deleting port " . $port['interface_id'] . " - " . $port['ifDescr'] );
echo("<div style='font-weight: bold;'>Deleting port " . $port['interface_id'] . " - " . $port['ifDescr']);
delete_port($port['interface_id']);
echo("</div>");
}

View File

@ -14,7 +14,8 @@
<option value="">All Programs</option>
<?php
$query = mysql_query("SELECT `program` FROM `syslog` GROUP BY `program` ORDER BY `program`");
while ($data = mysql_fetch_array($query)) {
while ($data = mysql_fetch_array($query))
{
echo("<option value='".$data['program']."'");
if ($data['program'] == $_POST['program']) { echo("selected"); }
echo(">".$data['program']."</option>");
@ -28,7 +29,8 @@
<option value="">All Devices</option>
<?php
$query = mysql_query("SELECT * FROM `devices` ORDER BY `hostname`");
while ($data = mysql_fetch_array($query)) {
while ($data = mysql_fetch_array($query))
{
echo("<option value='".$data['device_id']."'");
if ($data['device_id'] == $_POST['device']) { echo("selected"); }
@ -80,5 +82,4 @@ while ($entry = mysql_fetch_array($query))
}
echo("</table>");
?>
</table>
?>

View File

@ -62,13 +62,13 @@ if (is_array($oids))
### FIXME this stuff is foul
if ($entry['entPhySensorScale'] == "nano") { $divisor = "1000000000"; $multiplier = "1"; }
if ($entry['entPhySensorScale'] == "micro") { $divisor = "1000000"; $multiplier = "1"; }
if ($entry['entPhySensorScale'] == "milli") { $divisor = "1000"; $multiplier = "1"; }
if ($entry['entPhySensorScale'] == "units") { $divisor = "1"; $multiplier = "1"; }
if ($entry['entPhySensorScale'] == "kilo") { $divisor = "1"; $multiplier = "1000"; }
if ($entry['entPhySensorScale'] == "mega") { $divisor = "1"; $multiplier = "1000000"; }
if ($entry['entPhySensorScale'] == "giga") { $divisor = "1"; $multiplier = "1000000000"; }
if ($entry['entPhySensorScale'] == "nano") { $divisor = "1000000000"; $multiplier = "1"; }
if ($entry['entPhySensorScale'] == "micro") { $divisor = "1000000"; $multiplier = "1"; }
if ($entry['entPhySensorScale'] == "milli") { $divisor = "1000"; $multiplier = "1"; }
if ($entry['entPhySensorScale'] == "units") { $divisor = "1"; $multiplier = "1"; }
if ($entry['entPhySensorScale'] == "kilo") { $divisor = "1"; $multiplier = "1000"; }
if ($entry['entPhySensorScale'] == "mega") { $divisor = "1"; $multiplier = "1000000"; }
if ($entry['entPhySensorScale'] == "giga") { $divisor = "1"; $multiplier = "1000000000"; }
if (is_numeric($entry['entPhySensorPrecision']) && $entry['entPhySensorPrecision'] > "0") { $divisor = $divisor . str_pad('', $entry['entPhySensorPrecision'], "0"); }
$current = $current * $multiplier / $divisor;

View File

@ -21,7 +21,7 @@ if ($device['os'] == "junos")
$usage_oid = ".1.3.6.1.4.1.2636.3.1.13.1.8." . $index;
$descr = $entry['jnxOperatingDescr'];
$usage = $entry['jnxOperatingBuffer'];
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "")
{
discover_mempool($valid_mempool, $device, $index, "junos", $descr, "1", NULL, NULL);
}

View File

@ -2,8 +2,8 @@
if (!$os)
{
if (strstr($sysObjectId, ".1.3.6.1.4.1.12356.15")) { $os = "fortigate"; }
if (strstr($sysObjectId, ".1.3.6.1.4.1.12356.101.1")) { $os = "fortigate"; }
if (strstr($sysObjectId, ".1.3.6.1.4.1.12356.15")) { $os = "fortigate"; }
if (strstr($sysObjectId, ".1.3.6.1.4.1.12356.101.1")) { $os = "fortigate"; }
}
?>

View File

@ -2,8 +2,8 @@
if (!$os)
{
if (strstr($sysObjectId, ".1.3.6.1.4.1.674.3224.1")) { $os = "screenos"; }
if (strstr($sysObjectId, ".1.3.6.1.4.1.3224")) { $os = "screenos"; }
if (strstr($sysObjectId, ".1.3.6.1.4.1.674.3224.1")) { $os = "screenos"; }
if (strstr($sysObjectId, ".1.3.6.1.4.1.3224")) { $os = "screenos"; }
}
?>

View File

@ -34,7 +34,7 @@ foreach (explode("\n", $ports) as $entry)
}
if (empty($ifDescr)) { $nullintf = 1; }
if ($device['os'] == "catos" && strstr($if, "vlan") ) { $nullintf = 1; }
if ($device['os'] == "catos" && strstr($if, "vlan")) { $nullintf = 1; }
if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $ifDescr, $matches)) { $ifDescr = $matches[1]; }
$ifDescr = fixifName($ifDescr);
if (preg_match('/serial[0-9]:/', $if)) { $nullintf = 1; }

View File

@ -41,7 +41,7 @@ if ($device['os'] == "ios" || $device['os_group'] == "ios")
#echo("|".$descr."|");
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "")
{
discover_processor($valid_processor, $device, $usage_oid, $index, "cpm", $descr, "1", $entry['juniSystemModuleCpuUtilPct'], $entPhysicalIndex, NULL);
}

View File

@ -21,7 +21,7 @@ if ($device['os'] == "junos")
$usage_oid = ".1.3.6.1.4.1.2636.3.1.13.1.8." . $index;
$descr = $entry['jnxOperatingDescr'];
$usage = $entry['jnxOperatingCPU'];
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "")
{
discover_processor($valid_processor, $device, $usage_oid, $index, "junos", $descr, "1", $usage, NULL, NULL);
}

View File

@ -19,7 +19,7 @@ if ($device['os'] == "junose")
$descr = $entry['juniSystemModuleDescr'];
$usage = $entry['juniSystemModuleCpuFiveMinAvgPct'];
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "")
{
discover_processor($valid_processor, $device, $usage_oid, $index, "junose", $descr, "1", $usage, $entPhysicalIndex, NULL);
}

View File

@ -121,7 +121,7 @@ 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);
}
@ -167,20 +167,22 @@ function format_bi($size, $round = '2')
{
$sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E');
$ext = $sizes[0];
for ($i = 1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; }
for ($i = 1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; }
return round($size, $round).$ext;
}
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);
$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)
@ -191,6 +193,7 @@ function interface_errors($rrd_file, $period = '-1d') // Returns the last in/out
}
$errors['in'] = round($in_errors);
$errors['out'] = round($out_errors);
return $errors;
}
@ -223,16 +226,19 @@ function getImage($host)
} elseif (file_exists($config['html_dir'] . "/images/os/$distro" . ".gif")){ $image = '<img src="'.$config['base_url'].'/images/os/'.$distro.'.gif" />'; }
}
}
return $image;
}
function renamehost($id, $new)
function renamehost($id, $new, $source = 'console')
{
global $config;
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); # FIXME getdevicebyid?
rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new");
mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'");
eventlog("Hostname changed -> $new (console)", $id);
eventlog("Hostname changed -> $new ($source)", $id);
}
function delete_port($int_id)
@ -300,7 +306,7 @@ function addHost($host, $community, $snmpver, $port = 161, $transport = 'udp')
{
if (isPingable($host))
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' )
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0')
{
# FIXME internalize -- but we don't have $device yet!
# FIXME this needs to be addhost.php's content instead, kindof, also use this function there then.
@ -378,7 +384,7 @@ function formatUptime($diff, $format="long")
else
{
if ($yearsDiff > '0') { $uptime .= $yearsDiff . " years, "; }
if ($daysDiff > '0') { $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '' ) . ", "; }
if ($daysDiff > '0') { $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '') . ", "; }
if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; }
if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; }
if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; }
@ -402,12 +408,12 @@ function isSNMPable($device)
function isPingable($hostname)
{
global $config;
$status = shell_exec($config['fping'] . " $hostname");
$status = shell_exec($config['fping'] . " $hostname 2>/dev/null");
if (strstr($status, "alive"))
{
return TRUE;
} else {
$status = shell_exec($config['fping6'] . " $hostname");
$status = shell_exec($config['fping6'] . " $hostname 2>/dev/null");
if (strstr($status, "alive"))
{
return TRUE;

View File

@ -1,6 +1,6 @@
<?php
$version = preg_replace("/.+ version (.+) running on .+ (\S+)$/", "\\1||\\2", $sysDescr );
$version = preg_replace("/.+ version (.+) running on .+ (\S+)$/", "\\1||\\2", $sysDescr);
list($version,$hardware) = explode("||", $version);
?>

View File

@ -154,7 +154,7 @@ while ($port = mysql_fetch_array($port_query))
$update .= ", `$oid` = NULL";
log_event($oid . ": ".$port[$oid]." -> NULL", $device['device_id'], 'interface', $port['interface_id']);
if ($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); }
} elseif ($port[$oid] != $this_port[$oid] ) {
} elseif ($port[$oid] != $this_port[$oid]) {
$update .= ", `$oid` = '".mres($this_port[$oid])."'";
log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device['device_id'], 'interface', $port['interface_id']);
if ($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); }
@ -251,7 +251,7 @@ while ($port = mysql_fetch_array($port_query))
{
foreach ($pagp_oids as $oid)
{ // Loop the OIDs
if ($this_port[$oid] != $port[$oid] )
if ($this_port[$oid] != $port[$oid])
{ // If data has changed, build a query
$update .= ", `$oid` = '".mres($this_port[$oid])."'";
echo("PAgP ");

View File

@ -105,7 +105,7 @@ function CollectData($bill_id)
$prev_out_delta = '0';
}
if ($delta < '0' )
if ($delta < '0')
{
$delta = $prev_delta;
$in_delta = $prev_in_delta;

View File

@ -12,8 +12,6 @@
* See COPYING for more details.
*/
### Observium Device Poller
include("includes/defaults.inc.php");
include("config.php");
include("includes/functions.php");
@ -48,17 +46,17 @@ if (isset($options['i']) && $options['i'] && isset($options['n']))
if (!$where)
{
echo("-h <device id> | <device hostname> Poll single device\n");
echo("-h odd Poll odd numbered devices (same as -i 2 -n 0)\n");
echo("-h even Poll even numbered devices (same as -i 2 -n 1)\n");
echo("-h all Poll all devices\n\n");
echo("-i <instances> -n <number> Poll as instance <number> of <instances>\n");
echo(" Instances start at 0. 0-3 for -n 4\n\n");
echo("-d Enable some debugging output\n");
echo("-h <device id> | <device hostname wildcard> Poll single device\n");
echo("-h odd Poll odd numbered devices (same as -i 2 -n 0)\n");
echo("-h even Poll even numbered devices (same as -i 2 -n 1)\n");
echo("-h all Poll all devices\n\n");
echo("-i <instances> -n <number> Poll as instance <number> of <instances>\n");
echo(" Instances start at 0. 0-3 for -n 4\n\n");
echo("-d Enable some debugging output\n");
echo("\n");
echo("No polling type specified!\n");
exit;
}
}
if (isset($options['d']))
{
@ -76,7 +74,6 @@ if (isset($options['d']))
# ini_set('error_reporting', 0);
}
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");
@ -102,7 +99,6 @@ while ($device = mysql_fetch_assoc($device_query))
$host_rrd = $config['rrd_dir'] . "/" . $device['hostname'];
if (!is_dir($host_rrd)) { mkdir($host_rrd); echo("Created directory : $host_rrd\n"); }
$device['pingable'] = isPingable($device['hostname']);
if ($device['pingable'])
{
@ -119,7 +115,7 @@ while ($device = mysql_fetch_assoc($device_query))
$status = "0";
}
if ($device['status'] != $status )
if ($device['status'] != $status)
{
$poll_update .= $poll_separator . "`status` = '$status'";
$poll_separator = ", ";
@ -131,7 +127,6 @@ while ($device = mysql_fetch_assoc($device_query))
if ($status == "1")
{
$graphs = array();
$oldgraphs = array();
@ -175,8 +170,8 @@ while ($device = mysql_fetch_assoc($device_query))
if (is_numeric($uptime))
{
if ($uptime < $device['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']);
}
@ -334,7 +329,6 @@ while ($device = mysql_fetch_assoc($device_query))
}
}
$device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5);
$poll_update .= $poll_separator . "`last_polled_timetaken` = '$device_time'";
#echo("$device_end - $device_start; $device_time $device_run");
@ -349,7 +343,6 @@ while ($device = mysql_fetch_assoc($device_query))
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);
@ -369,4 +362,4 @@ unset($config); ### Remove this for testing
#print_r(get_defined_vars());
?>
?>

View File

@ -13,7 +13,7 @@ if ($argv[1] && $argv[2])
$id = getidbyname($host);
if ($id)
{
renamehost($id, $argv[2]);
renamehost($id, $argv[2], 'console');
echo("Renamed $host\n");
} else {
echo("Host doesn't exist!\n");