clean, clean, clean, all i have to do is clean

git-svn-id: http://www.observium.org/svn/observer/trunk@1855 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-03-15 15:27:14 +00:00
parent 6b0c5c183f
commit a8d60662d2
6 changed files with 151 additions and 119 deletions

View File

@ -1,33 +1,33 @@
<?php
## Very basic parser to parse classic Observium-type schemes.
## Parser should populate $port_ifAlias array with type, descr, circuit, speed and notes
## Very basic parser to parse classic Observium-type schemes.
## Parser should populate $port_ifAlias array with type, descr, circuit, speed and notes
unset ($port_ifAlias);
unset ($port_ifAlias);
echo($this_port['ifAlias']);
echo($this_port['ifAlias']);
list($type,$descr) = preg_split("/[\:\[\]\{\}\(\)]/", $this_port['ifAlias']);
list(,$circuit) = preg_split("/[\{\}]/", $this_port['ifAlias']);
list(,$notes) = preg_split("/[\(\)]/", $this_port['ifAlias']);
list(,$speed) = preg_split("/[\[\]]/", $this_port['ifAlias']);
$descr = trim($descr);
list($type,$descr) = preg_split("/[\:\[\]\{\}\(\)]/", $this_port['ifAlias']);
list(,$circuit) = preg_split("/[\{\}]/", $this_port['ifAlias']);
list(,$notes) = preg_split("/[\(\)]/", $this_port['ifAlias']);
list(,$speed) = preg_split("/[\[\]]/", $this_port['ifAlias']);
$descr = trim($descr);
if($type && $descr) {
$type = strtolower($type);
$port_ifAlias['type'] = $type;
$port_ifAlias['descr'] = $descr;
$port_ifAlias['circuit'] = $circuit;
$port_ifAlias['speed'] = $speed;
$port_ifAlias['notes'] = $notes;
if($debug) {
print_r($port_ifAlias);
}
if ($type && $descr)
{
$type = strtolower($type);
$port_ifAlias['type'] = $type;
$port_ifAlias['descr'] = $descr;
$port_ifAlias['circuit'] = $circuit;
$port_ifAlias['speed'] = $speed;
$port_ifAlias['notes'] = $notes;
if ($debug)
{
print_r($port_ifAlias);
}
}
unset ($port_type, $port_descr, $port_circuit, $port_notes, $port_speed);
unset ($port_type, $port_descr, $port_circuit, $port_notes, $port_speed);
?>
?>

View File

@ -4,16 +4,18 @@ function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir
{
global $debug,$config,$runtime_stats,$mibs_loaded;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
}
if ($config['snmp']['internal'] == true)
@ -27,14 +29,14 @@ function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir
snmp_set_quick_print(1);
$oids = explode(" ",trim($oids));
// s->ms - php snmp extension requires the timeout in microseconds.
if(isset($timeout)) { $timeout = $timeout*1000*1000; }
foreach($oids as $oid)
if (isset($timeout)) { $timeout = $timeout*1000*1000; }
foreach ($oids as $oid)
{
if ($device['snmpver'] == "v2c")
{
$data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
}
elseif ( $device['snmpver'] == "v1")
elseif ($device['snmpver'] == "v1")
{
$data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
}
@ -46,7 +48,7 @@ function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir
}
else
{
$cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$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']; }
@ -60,7 +62,7 @@ function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir
$data = trim(shell_exec($cmd));
$runtime_stats['snmpget']++;
if ($debug) { echo("$data\n"); }
foreach(explode("\n", $data) as $entry)
foreach (explode("\n", $data) as $entry)
{
list($oid,$value) = explode("=", $entry);
$oid = trim($oid); $value = trim($value);
@ -78,13 +80,15 @@ function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
{
global $debug,$config,$runtime_stats,$mibs_loaded;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
@ -105,11 +109,11 @@ function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
}
snmp_set_quick_print(1);
// s->ms - php snmp extension requires the timeout in microseconds.
if(isset($timeout)) { $timeout = $timeout*1000*1000; }
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") {
} elseif ($device['snmpver'] == "v1") {
$data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
}
if ($debug) { print "DEBUG: $oid: $data\n"; }
@ -143,13 +147,16 @@ function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
{
global $debug,$config,$runtime_stats;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
} elseif (isset($config['snmp']['timeout']))
{
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
@ -165,7 +172,7 @@ function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
$snmpcommand = $config['snmpbulkwalk'];
}
$cmd = $snmpcommand . " -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$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']; }
@ -200,13 +207,15 @@ function snmpwalk_cache_cip($device, $oid, $array, $mib = 0)
{
global $config;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
@ -221,7 +230,7 @@ function snmpwalk_cache_cip($device, $oid, $array, $mib = 0)
$snmpcommand = $config['snmpbulkwalk'];
}
$cmd = $snmpcommand . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$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; }
@ -234,7 +243,7 @@ function snmpwalk_cache_cip($device, $oid, $array, $mib = 0)
$device_id = $device['device_id'];
#echo("Caching: $oid\n");
foreach(explode("\n", $data) as $entry)
foreach (explode("\n", $data) as $entry)
{
list ($this_oid, $this_value) = preg_split("/=/", $entry);
$this_oid = trim($this_oid);
@ -263,13 +272,15 @@ 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']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
@ -284,7 +295,7 @@ function snmp_cache_ifIndex($device)
$snmpcommand = $config['snmpbulkwalk'];
}
$cmd = $snmpcommand . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$cmd = $snmpcommand . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$cmd .= " -M ".$config['install_dir']."/mibs/";
$cmd .= " -m IF-MIB ifIndex";
@ -294,7 +305,7 @@ function snmp_cache_ifIndex($device)
$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);
@ -313,7 +324,7 @@ function snmp_cache_ifIndex($device)
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);
@ -334,7 +345,7 @@ function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = NULL, $mibdir =
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);
@ -362,7 +373,7 @@ function snmpwalk_cache_double_oid($device, $oid, $array, $mib = NULL, $mibdir =
{
$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);
@ -380,7 +391,9 @@ function snmpwalk_cache_double_oid($device, $oid, $array, $mib = NULL, $mibdir =
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) {
foreach (explode("\n", $data) as $entry)
{
list($oid,$value) = explode("=", $entry);
$oid = trim($oid); $value = trim($value);
list($oid, $first, $second, $third) = explode(".", $oid);
@ -400,13 +413,15 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0)
{
global $config;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
@ -420,7 +435,7 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0)
{
$snmpcommand = $config['snmpbulkwalk'];
}
$cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$cmd .= " -M ".$config['install_dir']."/mibs/";
if ($mib) { $cmd .= " -m $mib"; }
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
@ -429,7 +444,7 @@ 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);
@ -447,13 +462,15 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
{
global $config, $debug;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
@ -468,7 +485,7 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
$snmpcommand = $config['snmpbulkwalk'];
}
$cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$cmd .= " -M ".$config['install_dir']."/mibs/";
if ($mib) { $cmd .= " -m $mib"; }
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
@ -478,12 +495,12 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
$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 ($debug) {echo("$entry || $oid || $first || $second || $third\n"); }
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second) && isset($third))
{
$array[$first][$second][$third][$oid] = $value;
@ -497,13 +514,15 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0)
{
global $config;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
@ -518,7 +537,7 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0)
$snmpcommand = $config['snmpbulkwalk'];
}
$cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
$cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
if ($mib) { $cmd .= " -m $mib"; }
$cmd .= " -M ".$config['install_dir']."/mibs/";
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
@ -528,7 +547,7 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0)
$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);
@ -553,19 +572,21 @@ function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0)
{
global $config;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
}
foreach($oids as $oid)
foreach ($oids as $oid)
{
$string .= " $oid.$port";
}
@ -582,8 +603,9 @@ function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0)
$x=0;
$values = explode("\n", $data);
#echo("Caching: ifIndex $port\n");
foreach($oids as $oid){
if (!strstr($values[$x], "at this OID")) {
foreach ($oids as $oid){
if (!strstr($values[$x], "at this OID"))
{
$array[$port][$oid] = $values[$x];
}
$x++;
@ -596,13 +618,15 @@ function snmp_cache_portIfIndex($device, $array)
{
global $config;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
@ -616,7 +640,7 @@ function snmp_cache_portIfIndex($device, $array)
$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);
@ -633,13 +657,15 @@ function snmp_cache_portName($device, $array)
{
global $config;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
if (is_numeric($device['timeout']) && $device['timeout'] > 0)
{
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
if (is_numeric($device['retries']) && $device['retries'] > 0)
{
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
@ -654,7 +680,7 @@ function snmp_cache_portName($device, $array)
$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);
@ -669,4 +695,5 @@ function snmp_cache_portName($device, $array)
return $array;
}
?>
?>

View File

@ -4,7 +4,7 @@ function process_syslog ($entry, $update)
{
global $config;
foreach($config['syslog_filter'] as $bi)
foreach ($config['syslog_filter'] as $bi)
{
if (strstr($entry['msg'], $bi) !== FALSE)
{
@ -12,13 +12,14 @@ function process_syslog ($entry, $update)
}
}
if(strstr($entry['msg'], "diskio.c: don't know how to handle") !== FALSE) {
if (strstr($entry['msg'], "diskio.c: don't know how to handle") !== FALSE)
{
$delete = 1;
}
$device_id_host = @mysql_result(mysql_query("SELECT device_id FROM devices WHERE `hostname` = '".$entry['host']."' OR `sysName` = '".$entry['host']."'"),0);
if($device_id_host)
if ($device_id_host)
{
$entry['device_id'] = $device_id_host;
}
@ -26,24 +27,24 @@ function process_syslog ($entry, $update)
{
$device_id_ip = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE
A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id"),0);
if($device_id_ip)
if ($device_id_ip)
{
$entry['device_id'] = $device_id_ip;
}
}
if($entry['device_id'] && !$delete)
if ($entry['device_id'] && !$delete)
{
$os = mysql_result(mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '".$entry['device_id']."'"),0);
if($os == "ios" || $os == "iosxe")
if ($os == "ios" || $os == "iosxe")
{
if(strstr($entry[msg], "%"))
if (strstr($entry[msg], "%"))
{
$entry['msg'] = preg_replace("/^%(.+?):\ /", "\\1||", $entry['msg']);
list(,$entry[msg]) = split(": %", $entry['msg']);
$entry['msg'] = "%" . $entry['msg'];
$entry['msg'] = preg_replace("/^%(.+?):\ /", "\\1||", $entry['msg']);
}
}
else
{
$entry['msg'] = preg_replace("/^.*[0-9]:/", "", $entry['msg']);
@ -57,22 +58,22 @@ function process_syslog ($entry, $update)
list($entry['program'], $entry['msg']) = explode("||", $entry['msg']);
$entry['msg'] = preg_replace("/^[0-9]+:/", "", $entry['msg']);
if(!$entry['program'])
if (!$entry['program'])
{
$entry['msg'] = preg_replace("/^([0-9A-Z\-]+?):\ /", "\\1||", $entry['msg']);
list($entry['program'], $entry['msg']) = explode("||", $entry['msg']);
}
if(!$entry['msg']) { $entry['msg'] = $entry['program']; unset ($entry['program']); }
if (!$entry['msg']) { $entry['msg'] = $entry['program']; unset ($entry['program']); }
}
else
{
$program = preg_quote($entry['program'],'/');
$entry['msg'] = preg_replace("/^$program:\ /", "", $entry['msg']);
# if(preg_match("/^[a-zA-Z\/]+\[[0-9]+\]:/", $entry['msg'])) {
# if (preg_match("/^[a-zA-Z\/]+\[[0-9]+\]:/", $entry['msg'])) {
$entry['msg'] = preg_replace("/^(.+?)\[[0-9]+\]:\ /", "\\1||", $entry['msg']);
if(!strstr($entry['msg'], "||")) { $entry['msg'] = preg_replace("/^(.+?):\ /", "\\1||", $entry['msg']);}
if (!strstr($entry['msg'], "||")) { $entry['msg'] = preg_replace("/^(.+?):\ /", "\\1||", $entry['msg']); }
list($entry['program'], $entry['msg']) = explode("||", $entry['msg']);
$entry['program'] = preg_replace("@\-[0-9]+@", "", $entry['program']);
# }
@ -81,12 +82,11 @@ function process_syslog ($entry, $update)
$x = "UPDATE `syslog` set `device_id` = '".$entry['device_id']."', `program` = '".$entry['program']."', `msg` = '" . mres($entry['msg']) . "', processed = '1' WHERE `seq` = '" . $entry['seq'] . "'";
$x = "INSERT INTO `syslog` (`device_id`,`program`,`facility`,`priority`, `level`, `tag`, `msg`, `timestamp`) ";
$x .= "VALUES ('".$entry['device_id']."','".$entry['program']."','".$entry['facility']."','".$entry['priority']."', '".$entry['level']."', '".$entry['tag']."', '".$entry['msg']."','".$entry['timestamp']."')";
if($update && $entry['device_id']) { mysql_query($x); }
if ($update && $entry['device_id']) { mysql_query($x); }
unset ($fix);
} else { print_r($entry); echo("D-$delete");}
} else { print_r($entry); echo("D-$delete"); }
return $entry;
}
?>

20
irc.php
View File

@ -16,9 +16,9 @@ class observiumbot
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'"));
if($device['status'] == 1) { $status = "Up " . formatUptime($device['uptime'] . " "); } else { $status = "Down "; }
if($device['ignore']) { $status = "*Ignored*"; }
if($device['disabled']) { $status = "*Disabled*"; }
if ($device['status'] == 1) { $status = "Up " . formatUptime($device['uptime'] . " "); } else { $status = "Down "; }
if ($device['ignore']) { $status = "*Ignored*"; }
if ($device['disabled']) { $status = "*Disabled*"; }
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'id'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .
$device['features'] . " " . $status);
@ -47,17 +47,17 @@ $port = 6667;
$nick = "Observium";
$chan = "#observium";
$bot = &new observiumbot( );
$irc = &new Net_SmartIRC( );
$bot = &new observiumbot();
$irc = &new Net_SmartIRC();
$irc->setUseSockets( TRUE );
$irc->registerActionhandler( SMARTIRC_TYPE_CHANNEL, '!device', $bot, 'device_info' );
$irc->registerActionhandler( SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info' );
$irc->connect( $host, $port );
$irc->login( $nick, 'Observium Bot', 0, $nick );
$irc->join( array( $chan ) );
$irc->listen( );
$irc->disconnect( );
$irc->connect($host, $port));
$irc->login($nick, 'Observium Bot', 0, $nick );
$irc->join(array($chan))));
$irc->listen();
$irc->disconnect();
?>

View File

@ -9,15 +9,19 @@ $search = $argv[1] . "$";
$data = trim(`cat ips-scanned.txt | grep alive | cut -d" " -f 1 | egrep $search`);
foreach( explode("\n", $data) as $ip) {
foreach (explode("\n", $data) as $ip)
{
$snmp = shell_exec("snmpget -t 0.2 -v2c -c ".$config['community']." $ip sysName.0");
if(strstr($snmp, "STRING")) {
if (strstr($snmp, "STRING"))
{
$hostname = trim(str_replace("SNMPv2-MIB::sysName.0 = STRING: ","", $snmp));
if(mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE hostname = '$hostname'"),0) == '0') {
if(gethostbyname($hostname) == gethostbyname($hostname.".".$config['mydomain'])) { $hostname = $hostname . ".".$config['mydomain']; }
if (mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE hostname = '$hostname'"),0) == '0')
{
if (gethostbyname($hostname) == gethostbyname($hostname.".".$config['mydomain'])) { $hostname = $hostname . ".".$config['mydomain']; }
addHost($hostname, $community, 'v2c');
echo("Adding $hostname \n");
}
}
}
?>
?>

View File

@ -6,14 +6,15 @@ include("config.php");
include("includes/syslog.php");
include("includes/common.php");
$i="1";
$i = "1";
$s=fopen('php://stdin','r');
while($line=fgets($s)){
list($entry['host'],$entry['facility'],$entry['priority'], $entry['level'], $entry['tag'], $entry['timestamp'], $entry['msg']) = explode("||", trim($line));
process_syslog($entry, 1);
unset($entry); unset($line);
$i++;
$s = fopen('php://stdin','r');
while ($line = fgets($s))
{
list($entry['host'],$entry['facility'],$entry['priority'], $entry['level'], $entry['tag'], $entry['timestamp'], $entry['msg']) = explode("||", trim($line));
process_syslog($entry, 1);
unset($entry); unset($line);
$i++;
}
?>
?>