clear $array at the start of each device. ignore fake cpus from net-snmpd. syslog additions.

git-svn-id: http://www.observium.org/svn/observer/trunk@886 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2010-02-19 23:57:50 +00:00
parent 4064d7b824
commit 8692b82e7a
6 changed files with 6 additions and 29 deletions

View File

@@ -74,11 +74,7 @@ if(isset($options['d'])) { echo("DEBUG!\n"); $debug = 1; } else { $debug = 0; }
$devices_discovered = 0;
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' $where ORDER BY device_id DESC");
while ($device = mysql_fetch_array($device_query)) {
$devices[] = $device;
}
foreach ($devices as $device)
while ($device = mysql_fetch_array($device_query))
{
echo($device['hostname'] . " ".$device['device_id']." ".$device['os']." ");
if($device['os'] != strtolower($device['os'])) {

View File

@@ -26,7 +26,7 @@
echo("Moved RRD ");
}
if(!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
if(!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" && $descr != "An electronic chip that makes the computer work.")
{
if(mysql_result(mysql_query("SELECT count(processor_id) FROM `processors` WHERE `processor_index` = '$index' AND `device_id` = '".$device['device_id']."' AND `processor_type` = 'hr'"),0) == '0') {
$query = "INSERT INTO processors (`hrDeviceIndex`, `device_id`, `processor_descr`, `processor_index`, `processor_oid`, `processor_usage`, `processor_type`)

View File

@@ -37,7 +37,7 @@ if (!is_file($cpurrd)) {
RRA:MAX:0.5:288:800");
}
rrdtool_update($cpurrd, "N:$cpuUser:$cpuSystem:$cpuNice:$cpuIdle");
rrdtool_update($cpurrd, "N:".($cpuUser+0).":".($cpuSystem+0).":".($cpuNice+0).":".($cpuIdle+0));
if (!is_file($memrrd)) {

View File

@@ -10,24 +10,18 @@ function process_syslog ($entry, $update) {
}
}
$device_id_host = @mysql_result(mysql_query("SELECT device_id FROM devices WHERE `hostname` = '".$entry['host']."'"),0);
$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) {
$entry['device_id'] = $device_id_host;
} else {
$device_id_ip = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, interfaces AS I WHERE
A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id"),0);
#echo("SELECT device_id FROM ipv4_addresses AS A, interfaces AS I WHERE
#A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id");
if($device_id_ip) {
$entry['device_id'] = $device_id_ip;
}
}
print_r($entry);
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") {
@@ -40,7 +34,6 @@ function process_syslog ($entry, $update) {
$entry['msg'] = preg_replace("/^.*[0-9]:/", "", $entry['msg']);
$entry['msg'] = preg_replace("/^[0-9][0-9]\ [A-Z]{3}:/", "", $entry['msg']);
$entry['msg'] = preg_replace("/^(.+?):\ /", "\\1||", $entry['msg']);
#$entry['msg'] = "||" . $entry['msg'];
}
$entry['msg'] = preg_replace("/^.+\.[0-9]{3}:/", "", $entry['msg']);
@@ -67,8 +60,7 @@ function process_syslog ($entry, $update) {
$x = "UPDATE `syslog` set `device_id` = '".$entry['device_id']."', `program` = '".$entry['program']."', `msg` = '" . mysql_real_escape_string($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) { mysql_query($x); }
if(mysql_affected_rows() > "0") { shell_exec("echo written $x >> /tmp/syslog"); } else { echo(mysql_error()); }
if($update && $entry['device_id']) { mysql_query($x); }
unset ($fix);
}

View File

@@ -42,7 +42,7 @@ echo("Starting polling run:\n\n");
$polled_devices = 0;
$device_query = mysql_query("SELECT * FROM `devices` WHERE `ignore` = '0' $where ORDER BY `device_id` ASC");
while ($device = mysql_fetch_array($device_query)) {
$status = 0;
$status = 0; unset($array);
echo($device['hostname'] . " ".$device['device_id']." ".$device['os']." ");
if ($os_groups[$device[os]]) {$device['os_group'] = $os_groups[$device[os]]; echo "(".$device['os_group'].")";}

View File

@@ -1,27 +1,16 @@
#!/usr/bin/php
<?php
# ini_set('display_errors', 0);
# ini_set('display_startup_errors', 0);
# ini_set('log_errors', 0);
# ini_set('error_reporting', E_ALL);
include("config.php");
include("includes/syslog.php");
$i="1";
#mysql_query("DELETE FROM `syslog` WHERE `datetime` < DATE_SUB(NOW(), INTERVAL ".$config['syslog_age'].")");
$s=fopen('php://stdin','r');
while($line=fgets($s)){
`echo "$line" >> /tmp/syslog`;
list($entry['host'],$entry['facility'],$entry['priority'], $entry['level'], $entry['tag'], $entry['timestamp'], $entry['msg']) = explode("||", trim($line));
shell_exec('echo "'.$i.'. '.$entry['host'].' -> '.$entry['msg'].'" >> /tmp/syslog');
process_syslog($entry, 1);
unset($entry); unset($line);
$i++;
}