From 232b330f3d0f17c3bf448f59a680d7f8a111c4bc Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Fri, 2 Sep 2011 06:56:21 +0000 Subject: [PATCH] fixed syslog? why knows! git-svn-id: http://www.observium.org/svn/observer/trunk@2405 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/dbFacile.php | 7 ++++- includes/syslog.php | 73 ++++++++++++++++++++++++++++++++++++++++--- syslog.php | 2 ++ 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/includes/dbFacile.php b/includes/dbFacile.php index 7c0d13af7..63ef43a6e 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -30,6 +30,8 @@ function dbQuery($sql, $parameters = array()) { $time_start = microtime(true); */ +# echo($fullSql); + $result = mysql_query($fullSql); // sets $this->result /* if($this->logFile) { @@ -79,6 +81,9 @@ function dbInsert($data, $table) { dbRollbackTransaction(); #$id = false; } + + logfile($fullSql); + $time_end = microtime(true); $db_stats['insert_sec'] += number_format($time_end - $time_start, 8); $db_stats['insert']++; @@ -122,7 +127,7 @@ function dbUpdate($data, $table, $where = null, $parameters = array()) { if(dbQuery($sql, $data)) { $return = mysql_affected_rows(); } else { - echo("$fullSql"); + #echo("$fullSql"); trigger_error('QDB - Update failed.', E_USER_WARNING); $return = false; } diff --git a/includes/syslog.php b/includes/syslog.php index 9a6127252..dcdf85826 100755 --- a/includes/syslog.php +++ b/includes/syslog.php @@ -1,21 +1,28 @@ $entry['device_id'], + 'host' => $entry['host'], + 'program' => $entry['program'], + 'facility' => $entry['facility'], + 'priority' => $entry['priority'], + 'level' => $entry['level'], + 'tag' => $entry['tag'], + 'msg' => $entry['msg'], + 'datetime' => $entry['timestamp'] + ), + 'logs' + ); + + dbInsert( + array( + 'device_id' => $entry['device_id'], + 'program' => $entry['program'], + 'facility' => $entry['facility'], + 'priority' => $entry['priority'], + 'level' => $entry['level'], + 'tag' => $entry['tag'], + 'msg' => $entry['msg'], + 'timestamp' => $entry['timestamp'] + ), + 'syslog' + ); + } + + + return $entry; +} + + + +function process_syslog_old ($entry, $update) { + global $config; + global $dev_cache; + foreach($config['syslog_filter'] as $bi) if(strpos($entry['msg'], $bi) !== FALSE){ print_r($entry); @@ -38,6 +96,7 @@ function process_syslog ($entry, $update) { $entry['device_id'] = get_cache($entry['host'], 'device_id'); if($entry['device_id']) { $os = get_cache($entry['host'], 'os'); + if(in_array($os, array('ios', 'iosxe', 'catos'))){ $matches = array(); if(preg_match('#%(?P.*):( ?)(?P.*)#', $entry['msg'], $matches)){ @@ -45,6 +104,7 @@ function process_syslog ($entry, $update) { $entry['program'] = $matches['program']; } unset($matches); + } elseif($os == 'linux' and get_cache($entry['host'], 'version') == 'Point'){ //Cisco WAP200 and similar $matches = array(); @@ -53,6 +113,7 @@ function process_syslog ($entry, $update) { $entry['program'] = $matches['program']; } unset($matches); + } elseif($os == 'linux'){ $matches = array(); //User_CommonName/123.213.132.231:39872 VERIFY OK: depth=1, /C=PL/ST=Malopolska/O=VLO/CN=v-lo.krakow.pl/emailAddress=root@v-lo.krakow.pl @@ -82,12 +143,14 @@ function process_syslog ($entry, $update) { } unset($matches); } + if(!isset($entry['program'])){ $entry['program'] = $entry['msg']; unset($entry['msg']); } $entry['program'] = strtoupper($entry['program']); array_walk($entry, 'trim'); + if($update) dbInsert( array( diff --git a/syslog.php b/syslog.php index a7cfe8906..7353621ef 100755 --- a/syslog.php +++ b/syslog.php @@ -6,12 +6,14 @@ include("config.php"); include("includes/syslog.php"); include("includes/dbFacile.php"); include("includes/common.php"); +include("includes/functions.php"); $i = "1"; $s = fopen('php://stdin','r'); while ($line = fgets($s)) { + logfile($line); list($entry['host'],$entry['facility'],$entry['priority'], $entry['level'], $entry['tag'], $entry['timestamp'], $entry['msg'], $entry['program']) = explode("||", trim($line)); process_syslog($entry, 1); unset($entry); unset($line);