mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
minor code cleanup, change queries to eventlog table to eventlog() function
git-svn-id: http://www.observium.org/svn/observer/trunk@609 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
if($os != $device['os']) {
|
||||
$sql = mysql_query("UPDATE `devices` SET `os` = '$os' WHERE `device_id` = '".$device['device_id']."'");
|
||||
echo("Changed OS! : $os\n");
|
||||
$eventlog = mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Device OS changed ".$device['os']." => $os')");
|
||||
eventlog("Device OS changed ".$device['os']." => $os", $device['device_id']);
|
||||
$device['os'] = $os;
|
||||
}
|
||||
|
||||
|
@@ -357,7 +357,7 @@ function renamehost($id, $new) {
|
||||
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
|
||||
shell_exec("mv ".$config['rrd_dir']."/$host ".$config['rrd_dir']."/$new");
|
||||
mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'");
|
||||
mysql_query("INSERT INTO eventlog (host, datetime, message) VALUES ('" . $id . "', NULL, NOW(), 'Hostname changed -> $new (console)')");
|
||||
eventlog("Hostname changed -> $new (console)", $id);
|
||||
}
|
||||
|
||||
function delHost($id)
|
||||
@@ -735,4 +735,12 @@ function get_astext($asn)
|
||||
return trim(str_replace('"', '', $txt[4]));
|
||||
}
|
||||
|
||||
function eventlog($eventtext,$device_id = "", $interface_id = "")
|
||||
{
|
||||
$event_query = "INSERT INTO eventlog (host, interface, datetime, message) VALUES (" . ($device_id ? $device_id : "NULL");
|
||||
$event_query .= ", " . ($interface_id ? $interface_id : "NULL") . ", NOW(), '" . mysql_escape_string($eventtext) . "')";
|
||||
echo "$event_query\n";
|
||||
mysql_query($event_query);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -88,30 +88,30 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
||||
if ( $interface['ifDescr'] != $ifDescr && $ifDescr != "" ) {
|
||||
$update .= $seperator . "`ifDescr` = '$ifDescr'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'ifDescr -> $ifDescr')");
|
||||
eventlog("ifDescr -> $ifDescr", $interface['device_id'], $interface['interface_id']);
|
||||
}
|
||||
|
||||
if ( $interface['ifName'] != $ifName && $ifName != "" ) {
|
||||
$update .= $seperator . "`ifName` = '$ifName'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'ifName -> $ifName')");
|
||||
eventlog("ifName -> $ifName", $interface['device_id'], $interface['interface_id']);
|
||||
}
|
||||
|
||||
if ( $interface['ifAlias'] != $ifAlias && $ifAlias != "" ) {
|
||||
$update .= $seperator . "`ifAlias` = '".mysql_real_escape_string($ifAlias)."'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'ifAlias -> $ifAlias')");
|
||||
eventlog("ifAlias -> $ifAlias", $interface['device_id'], $interface['interface_id']);
|
||||
}
|
||||
if ( $interface['ifOperStatus'] != $ifOperStatus && $ifOperStatus != "" ) {
|
||||
$update .= $seperator . "`ifOperStatus` = '$ifOperStatus'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface went $ifOperStatus')");
|
||||
eventlog("Interface went $ifOperStatus", $interface['device_id'], $interface['interface_id']);
|
||||
}
|
||||
if ( $interface['ifAdminStatus'] != $ifAdminStatus && $ifAdminStatus != "" ) {
|
||||
$update .= $seperator . "`ifAdminStatus` = '$ifAdminStatus'";
|
||||
$seperator = ", ";
|
||||
if($ifAdminStatus == "up") { $admin = "enabled"; } else { $admin = "disabled"; }
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface $admin')");
|
||||
eventlog("Interface $admin", $interface['device_id'], $interface['interface_id']);
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
|
@@ -82,12 +82,11 @@
|
||||
foreach ($data_oids as $oid) {
|
||||
if ( $port[$oid] != $this_port[$oid] && !isset($this_port[$oid])) {
|
||||
$update .= ", `$oid` = NULL";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $device['device_id'] . "', '" . $port['interface_id'] . "', NOW(), '".$oid . ": ".$port[$oid]." -> NULL')");
|
||||
eventlog($oid . ": ".$port[$oid]." -> NULL", $device['device_id'], $port['interface_id']);
|
||||
if($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); }
|
||||
} elseif ( $port[$oid] != $this_port[$oid] ) {
|
||||
$update .= ", `$oid` = '".mysql_real_escape_string($this_port[$oid])."'";
|
||||
#eventlog($device['device_id'], 'interface', $port['interface_id'], $oid . ": ".$port[$oid]." -> " . $this_port[$oid]);
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $device['device_id'] . "', '" . $port['interface_id'] . "', NOW(), '".$oid . ": ".$port[$oid]." -> " . $this_port[$oid]."')");
|
||||
eventlog($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device['device_id'], $port['interface_id']);
|
||||
if($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); }
|
||||
}
|
||||
}
|
||||
@@ -144,21 +143,12 @@
|
||||
if ( $this_port[$oid] != $port[$oid] ) { // If data has changed, build a query
|
||||
$update .= ", `$oid` = '".mres($this_port[$oid])."'";
|
||||
echo("PAgP ");
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $device['device_id'] . "', '" . $port['interface_id'] . "', NOW(), '$oid -> ".$this_port[$oid]."')");
|
||||
eventlog("$oid -> ".$this_port[$oid], $device['device_id'], $port['interface_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
// End Update PAgP
|
||||
|
||||
// Do Eventlogging
|
||||
# $eventlog_oids = array('ifDescr', 'ifName', 'ifAlias', 'ifOperStatus', 'ifAdminStatus');
|
||||
# foreach ($data_oids as $oid) { // Loop the OIDs
|
||||
# if ( $port[$oid] != $this_port[oid]) {
|
||||
# mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $device['device_id'] . "', '" . $port['interface_id'] . "', NOW(), '$oid -> ".$this_port[$oid]."')");
|
||||
# }
|
||||
# }
|
||||
// End Eventlogging
|
||||
|
||||
/// Do EtherLike-MIB
|
||||
if($config['enable_ports_etherlike']) { include("port-etherlike.inc.php"); }
|
||||
|
||||
|
@@ -16,13 +16,13 @@ if ($options['h'] == "odd") {
|
||||
$where = "AND MOD(device_id,2) = 0"; $doing = $options['h'];
|
||||
} elseif ($options['h'] == "all") {
|
||||
$where = " "; $doing = "all";
|
||||
} elseif($options['h']) {
|
||||
} elseif ($options['h']) {
|
||||
$where = "AND `device_id` = '".$options['h']."'"; $doing = "Host ".$options['h'];
|
||||
} elseif ($options['i'] && isset($options['n'])) {
|
||||
$where = "AND MOD(device_id,".$options['i'].") = '" . $options['n'] . "'"; $doing = "Proc ".$options['n'] ."/".$options['i'];
|
||||
}
|
||||
|
||||
if(!$where) {
|
||||
if (!$where) {
|
||||
echo("-h <device id> 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");
|
||||
@@ -35,7 +35,7 @@ if(!$where) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if(isset($options['d'])) { echo("DEBUG!\n"); $debug = 1; }
|
||||
if (isset($options['d'])) { echo("DEBUG!\n"); $debug = 1; }
|
||||
|
||||
|
||||
echo("Starting polling run:\n\n");
|
||||
@@ -45,7 +45,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
$status = 0;
|
||||
|
||||
echo($device['hostname'] . " ".$device['device_id']." ".$device['os']." ");
|
||||
if($os_groups[$device[os]]) {$device['os_group'] = $os_groups[$device[os]]; echo "(".$device['os_group'].")";}
|
||||
if ($os_groups[$device[os]]) {$device['os_group'] = $os_groups[$device[os]]; echo "(".$device['os_group'].")";}
|
||||
echo("\n");
|
||||
|
||||
unset($update); unset($update_query); unset($seperator); unset($version); unset($uptime); unset($features);
|
||||
@@ -55,15 +55,15 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
|
||||
$host_rrd = $config['rrd_dir'] . "/" . $device['hostname'];
|
||||
|
||||
if(!is_dir($host_rrd)) { mkdir($host_rrd); echo("Created directory : $host_rrd\n"); }
|
||||
if (!is_dir($host_rrd)) { mkdir($host_rrd); echo("Created directory : $host_rrd\n"); }
|
||||
|
||||
if($pingable) { echo("Pings : yes :)\n"); } else { echo("Pings : no :(\n"); }
|
||||
if ($pingable) { echo("Pings : yes :)\n"); } else { echo("Pings : no :(\n"); }
|
||||
|
||||
$snmpable = FALSE;
|
||||
|
||||
if($pingable) {
|
||||
if ($pingable) {
|
||||
$snmpable = isSNMPable($device['hostname'], $device['community'], $device['snmpver'], $device['port']);
|
||||
if($snmpable) { echo("SNMP : yes :)\n"); } else { echo("SNMP : no :(\n"); }
|
||||
if ($snmpable) { echo("SNMP : yes :)\n"); } else { echo("SNMP : no :(\n"); }
|
||||
}
|
||||
|
||||
unset($snmpdata);
|
||||
@@ -89,10 +89,10 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
$secs = $secs + ($mins * 60);
|
||||
$uptime = $secs;
|
||||
|
||||
if(is_file($config['install_dir'] . "/includes/polling/device-".$device['os'].".inc.php")) {
|
||||
if (is_file($config['install_dir'] . "/includes/polling/device-".$device['os'].".inc.php")) {
|
||||
/// OS Specific
|
||||
include($config['install_dir'] . "/includes/polling/device-".$device['os'].".inc.php");
|
||||
}elseif($device['os_group'] && is_file($config['install_dir'] . "/includes/polling/device-".$device['os_group'].".inc.php")) {
|
||||
}elseif ($device['os_group'] && is_file($config['install_dir'] . "/includes/polling/device-".$device['os_group'].".inc.php")) {
|
||||
/// OS Group Specific
|
||||
include($config['install_dir'] . "/includes/polling/device-".$device['os_group'].".inc.php");
|
||||
}else{
|
||||
@@ -115,56 +115,56 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
if ( $sysContact && $sysContact != $device['sysContact'] ) {
|
||||
$update .= $seperator . "`sysContact` = '".mres($sysContact)."'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Contact -> $sysContact')");
|
||||
eventlog("Contact -> $sysContact", $device['device_id']);
|
||||
}
|
||||
|
||||
if ( $sysName && $sysName != $device['sysName'] ) {
|
||||
$update .= $seperator . "`sysName` = '$sysName'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'sysName -> $sysName')");
|
||||
eventlog("sysName -> $sysName", $device['device_id']);
|
||||
}
|
||||
|
||||
if ( $sysDescr && $sysDescr != $device['sysDescr'] ) {
|
||||
$update .= $seperator . "`sysDescr` = '$sysDescr'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'sysDescr -> $sysDescr')");
|
||||
eventlog("sysDescr -> $sysDescr", $device['device_id']);
|
||||
}
|
||||
|
||||
if ( $sysLocation && $device['location'] != $sysLocation ) {
|
||||
$update .= $seperator . "`location` = '$sysLocation'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Location -> $sysLocation')");
|
||||
eventlog("Location -> $sysLocation", $device['device_id']);
|
||||
}
|
||||
|
||||
if ( $version && $device['version'] != $version ) {
|
||||
$update .= $seperator . "`version` = '$version'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Version -> $version')");
|
||||
eventlog("OS Version -> $version", $device['device_id']);
|
||||
}
|
||||
|
||||
if ( $features && $features != $device['features'] ) {
|
||||
$update .= $seperator . "`features` = '$features'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Features -> $features')");
|
||||
eventlog("OS Features -> $features", $device['device_id']);
|
||||
}
|
||||
|
||||
if ( $hardware && $hardware != $device['hardware'] ) {
|
||||
$update .= $seperator . "`hardware` = '$hardware'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Hardware -> $hardware')");
|
||||
eventlog("Hardware -> $hardware", $device['device_id']);
|
||||
}
|
||||
|
||||
if ($uptime) {
|
||||
|
||||
if( $uptime < $device['uptime'] ) {
|
||||
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
||||
if ($uptime)
|
||||
{
|
||||
if ( $uptime < $device['uptime'] ) {
|
||||
if ($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
||||
mail($email, "Device Rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago.", $config['email_headers']);
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $device['device_id'] . "', '', NOW(), 'Device rebooted')");
|
||||
eventlog('Device rebooted', $device['device_id']);
|
||||
}
|
||||
|
||||
$uptimerrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd";
|
||||
|
||||
if(!is_file($uptimerrd)) {
|
||||
if (!is_file($uptimerrd)) {
|
||||
$woo = shell_exec($config['rrdtool'] . " create $uptimerrd \
|
||||
DS:uptime:GAUGE:600:0:U \
|
||||
RRA:AVERAGE:0.5:1:600 \
|
||||
@@ -188,11 +188,11 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
$update_result = mysql_query($update_query);
|
||||
}
|
||||
|
||||
if( $device['status'] != $status ) {
|
||||
if ( $device['status'] != $status ) {
|
||||
$update .= $seperator . "`status` = '$status'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is " . ($status == '1' ? 'up' : 'down') . "')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Device status changed to " . ($status == '1' ? 'Up' : 'Down') . "')");
|
||||
eventlog('Device status changed to ' . ($status == '1' ? 'Up' : 'Down'), $device['device_id']);
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
|
@@ -51,7 +51,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')");
|
||||
mail($email, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date('l dS F Y h:i:s A'), $config['email_headers']);
|
||||
}
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Device status changed to $stat')");
|
||||
eventlog("Device status changed to $stat", $device['device_id']);
|
||||
echo("Status Changed!\n");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user