mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
more code cleanup
git-svn-id: http://www.observium.org/svn/observer/trunk@2517 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
function isCli() {
|
||||
|
||||
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -13,7 +13,7 @@ function isCli() {
|
||||
|
||||
function print_error($text)
|
||||
{
|
||||
if(isCli()) {
|
||||
if (isCli()) {
|
||||
print Console_Color::convert("%r".$text."%n\n", false);
|
||||
} else {
|
||||
echo('<div class="errorbox"><img src="/images/16/exclamation.png" align="absmiddle"> '.$text.'</div>');
|
||||
@@ -22,7 +22,7 @@ function print_error($text)
|
||||
|
||||
function print_message($text)
|
||||
{
|
||||
if(isCli()) {
|
||||
if (isCli()) {
|
||||
print Console_Color::convert("%g".$text."%n\n", false);
|
||||
} else {
|
||||
echo('<div class="messagebox"><img src="/images/16/tick.png" align="absmiddle"> '.$text.'</div>');
|
||||
|
@@ -23,8 +23,9 @@ Usage
|
||||
* */
|
||||
function dbQuery($sql, $parameters = array()) {
|
||||
global $fullSql, $debug;
|
||||
|
||||
$fullSql = dbMakeQuery($sql, $parameters);
|
||||
if($debug) { echo(" SQL[".$fullSql."] "); }
|
||||
if ($debug) { echo(" SQL[".$fullSql."] "); }
|
||||
/*
|
||||
if($this->logFile)
|
||||
$time_start = microtime(true);
|
||||
@@ -53,7 +54,9 @@ function dbQuery($sql, $parameters = array()) {
|
||||
* */
|
||||
function dbInsert($data, $table) {
|
||||
global $fullSql;
|
||||
|
||||
global $db_stats;
|
||||
|
||||
// the following block swaps the parameters if they were given in the wrong order.
|
||||
// it allows the method to work for those that would rather it (or expect it to)
|
||||
// follow closer with SQL convention:
|
||||
@@ -98,7 +101,9 @@ function dbInsert($data, $table) {
|
||||
* */
|
||||
function dbUpdate($data, $table, $where = null, $parameters = array()) {
|
||||
global $fullSql;
|
||||
|
||||
global $db_stats;
|
||||
|
||||
// the following block swaps the parameters if they were given in the wrong order.
|
||||
// it allows the method to work for those that would rather it (or expect it to)
|
||||
// follow closer with SQL convention:
|
||||
@@ -163,7 +168,7 @@ function dbFetchRows($sql, $parameters = array()) {
|
||||
|
||||
if(mysql_num_rows($result) > 0) {
|
||||
$rows = array();
|
||||
while($row = mysql_fetch_assoc($result)) {
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
mysql_free_result($result);
|
||||
@@ -228,6 +233,7 @@ function dbFetchRow($sql = null, $parameters = array()) {
|
||||
* */
|
||||
function dbFetchCell($sql, $parameters = array()) {
|
||||
global $db_stats;
|
||||
|
||||
$time_start = microtime(true);
|
||||
$row = dbFetchRow($sql, $parameters);
|
||||
if($row) {
|
||||
@@ -247,6 +253,7 @@ function dbFetchCell($sql, $parameters = array()) {
|
||||
* */
|
||||
function dbFetchColumn($sql, $parameters = array()) {
|
||||
global $db_stats;
|
||||
|
||||
$time_start = microtime(true);
|
||||
$cells = array();
|
||||
foreach(dbFetch($sql, $parameters) as $row) {
|
||||
@@ -286,7 +293,7 @@ function dbFetchKeyValue($sql, $parameters = array()) {
|
||||
*/
|
||||
function dbMakeQuery($sql, $parameters) {
|
||||
// bypass extra logic if we have no parameters
|
||||
if(sizeof($parameters) == 0)
|
||||
if (sizeof($parameters) == 0)
|
||||
return $sql;
|
||||
|
||||
$parameters = dbPrepareData($parameters);
|
||||
|
@@ -31,7 +31,7 @@ if (is_array($cefs))
|
||||
echo(" | |-".$path.": ".$path_name['cefSwitchingPath']."\n");
|
||||
|
||||
|
||||
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `cef` WHERE `device_id` = '".$device['device_id']."' AND `entPhysicalIndex` = '".$entity."'
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `cef` WHERE `device_id` = '".$device['device_id']."' AND `entPhysicalIndex` = '".$entity."'
|
||||
AND `afi` = '".$afi."' AND `cef_index` = '".$path."'"),0) != "1")
|
||||
{
|
||||
$sql = "INSERT INTO `cef` (`device_id`, `entPhysicalIndex`, `afi`, `cef_index`, `cef_path`)
|
||||
|
@@ -11,7 +11,7 @@ if ($device['os'] == 'sentry3')
|
||||
# These PDUs may have > 1 "tower" accessible via a single management interface
|
||||
$tower_count = snmp_get($device,"systemTowerCount.0", "-Ovq", "Sentry3-MIB");
|
||||
$towers=1;
|
||||
while($towers <= $tower_count) {
|
||||
while ($towers <= $tower_count) {
|
||||
|
||||
#################################
|
||||
# Check for Infeeds
|
||||
@@ -107,7 +107,7 @@ if ($device['os'] == 'sentry3')
|
||||
|
||||
$towers++;
|
||||
|
||||
} // while($towers <= $tower_count)
|
||||
} // while ($towers <= $tower_count)
|
||||
|
||||
unset($towers);
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ if ($device['os'] == "ironware")
|
||||
$fdp = $fdp_if_array[$entry_key];
|
||||
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$fdp['snFdpCacheDeviceId']."' OR `hostname`='".$fdp['snFdpCacheDeviceId']."'"), 0);
|
||||
|
||||
if(!$remote_device_id)
|
||||
if (!$remote_device_id)
|
||||
{
|
||||
$remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId']);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ if ($cdp_array)
|
||||
$cdp = $cdp_if_array[$entry_key];
|
||||
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$cdp['cdpCacheDeviceId']."' OR `hostname`='".$cdp['cdpCacheDeviceId']."'"), 0);
|
||||
|
||||
if(!$remote_device_id)
|
||||
if (!$remote_device_id)
|
||||
{
|
||||
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId']);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ if ($lldp_array)
|
||||
$lldp = $lldp_instance[$entry_instance];
|
||||
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$lldp['lldpRemSysName']."' OR `hostname`='".$lldp['lldpRemSysName']."'"), 0);
|
||||
|
||||
if(!$remote_device_id)
|
||||
if (!$remote_device_id)
|
||||
{
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName']);
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ function discover_new_device($hostname)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if($config['autodiscovery']['xdp']) {
|
||||
if ($config['autodiscovery']['xdp']) {
|
||||
if ( isDomainResolves($hostname . "." . $config['mydomain']) ) {
|
||||
$dst_host = $hostname . "." . $config['mydomain'];
|
||||
} else {
|
||||
@@ -26,7 +26,7 @@ function discover_new_device($hostname)
|
||||
if ( match_network($config['nets'], $ip) )
|
||||
{
|
||||
$remote_device_id = addHost ($dst_host, NULL, "v2c");
|
||||
if($remote_device_id) {
|
||||
if ($remote_device_id) {
|
||||
$remote_device = device_by_id_cache($remote_device_id, 1);
|
||||
echo("+[".$remote_device['hostname']."(".$remote_device['device_id'].")]");
|
||||
discover_device($remote_device);
|
||||
@@ -51,10 +51,10 @@ function discover_device($device, $options = NULL)
|
||||
|
||||
echo($device['hostname'] . " ".$device['device_id']." ".$device['os']." ");
|
||||
|
||||
if($device['os'] == 'generic') // verify if OS has changed from generic
|
||||
if ($device['os'] == 'generic') // verify if OS has changed from generic
|
||||
{
|
||||
$device['os']= getHostOS($device);
|
||||
if($device['os'] != 'generic')
|
||||
if ($device['os'] != 'generic')
|
||||
{
|
||||
echo "Device os was updated to".$device['os']."!";
|
||||
dbUpdate(array('os' => $device['os']), 'devices', '`device_id` = ?', array($device['device_id']));
|
||||
@@ -343,7 +343,7 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size,
|
||||
else
|
||||
{
|
||||
$updated = dbUpdate(array('storage_descr' => $descr, 'storage_type' => $type, 'storage_units' => $units, 'storage_size' => $size), 'storage', '`device_id` = ? AND `storage_index` = ? AND `storage_mib` = ?', array($device['device_id'], $index, $mib));
|
||||
if($updated) { echo("U"); } else { echo("."); }
|
||||
if ($updated) { echo("U"); } else { echo("."); }
|
||||
}
|
||||
$valid[$mib][$index] = 1;
|
||||
}
|
||||
|
@@ -7,12 +7,12 @@ if (!$os)
|
||||
|
||||
## Specific Linux-derivatives
|
||||
|
||||
if($os == "linux") {
|
||||
if ($os == "linux") {
|
||||
|
||||
## Check for QNAP Systems TurboNAS
|
||||
$entPhysicalMfgName = snmp_get($device, "ENTITY-MIB::entPhysicalMfgName.1", "-Osqnv");
|
||||
|
||||
if(strpos($entPhysicalMfgName, "QNAP") !== FALSE) { $os = "qnap";}
|
||||
if (strpos($entPhysicalMfgName, "QNAP") !== FALSE) { $os = "qnap";}
|
||||
elseif(strstr($sysObjectId, ".1.3.6.1.4.1.5528.100.20.10.2014")) { $os = "netbotz"; }
|
||||
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ echo("Port Stack: ");
|
||||
|
||||
$sql = "SELECT * FROM `ports_stack` WHERE `device_id` = '".$device['device_id']."'";
|
||||
$query = mysql_query($sql);
|
||||
while($entry = mysql_fetch_assoc($query))
|
||||
while ($entry = mysql_fetch_assoc($query))
|
||||
{
|
||||
$stack_db_array[$entry['interface_id_high']][$entry['interface_id_low']]['ifStackStatus'] = $entry['ifStackStatus'];
|
||||
}
|
||||
@@ -16,21 +16,21 @@ foreach($stack_poll_array as $interface_id_high => $entry_high)
|
||||
foreach($entry_high as $interface_id_low => $entry_low)
|
||||
{
|
||||
$ifStackStatus = $entry_low['ifStackStatus'];
|
||||
if(isset($stack_db_array[$interface_id_high][$interface_id_low]))
|
||||
if (isset($stack_db_array[$interface_id_high][$interface_id_low]))
|
||||
{
|
||||
if($stack_db_array[$interface_id_high][$interface_id_low]['ifStackStatus'] == $ifStackStatus)
|
||||
if ($stack_db_array[$interface_id_high][$interface_id_low]['ifStackStatus'] == $ifStackStatus)
|
||||
{
|
||||
echo(".");
|
||||
} else {
|
||||
mysql_query("UPDATE `ports_stack` SET `ifStackStatus` = '".$ifStackStatus."' WHERE `device_id` = '".$device['device_id']."' AND `interface_id_high` = '".$interface_id_high."' AND `interface_id_low` = '".$interface_id_low."'");
|
||||
echo("U");
|
||||
if($debug) { echo(mysql_error()); }
|
||||
if ($debug) { echo(mysql_error()); }
|
||||
}
|
||||
unset($stack_db_array[$interface_id_high][$interface_id_low]);
|
||||
} else {
|
||||
mysql_query("INSERT INTO `ports_stack` (`device_id`,`interface_id_high`,`interface_id_low`,`ifStackStatus`) VALUES ('".$device['device_id']."','".$interface_id_high."','".$interface_id_low."','".$ifStackStatus."')");
|
||||
echo("+");
|
||||
if($debug) { echo(mysql_error()); }
|
||||
if ($debug) { echo(mysql_error()); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ if (is_array($hrDevice_array))
|
||||
echo("Moved RRD ");
|
||||
}
|
||||
|
||||
if($device['os'] == "arista-eos" && $index == "1") { unset($descr); }
|
||||
if ($device['os'] == "arista-eos" && $index == "1") { unset($descr); }
|
||||
|
||||
if (isset($descr) && $descr != "An electronic chip that makes the computer work.")
|
||||
{
|
||||
|
@@ -22,9 +22,9 @@ function external_exec($command)
|
||||
{
|
||||
global $debug;
|
||||
|
||||
if($debug) { echo($command."\n"); }
|
||||
if ($debug) { echo($command."\n"); }
|
||||
$output = shell_exec($command);
|
||||
if($debug) { echo($output."\n"); }
|
||||
if ($debug) { echo($output."\n"); }
|
||||
|
||||
return $output;
|
||||
}
|
||||
@@ -325,6 +325,7 @@ function isSNMPable($device)
|
||||
function isPingable($hostname)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$status = shell_exec($config['fping'] . " $hostname 2>/dev/null");
|
||||
if (strstr($status, "alive"))
|
||||
{
|
||||
@@ -348,6 +349,7 @@ function is_odd($number)
|
||||
function isValidInterface($if)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$if = strtolower($if);
|
||||
$nullintf = 0;
|
||||
foreach ($config['bad_if'] as $bi)
|
||||
@@ -644,7 +646,7 @@ function is_port_valid($port, $device)
|
||||
if (strstr($if, $bi))
|
||||
{
|
||||
$valid = 0;
|
||||
if($debug) { echo("ignored : $bi : $if"); }
|
||||
if ($debug) { echo("ignored : $bi : $if"); }
|
||||
}
|
||||
}
|
||||
if (is_array($config['bad_if_regexp']))
|
||||
@@ -654,7 +656,7 @@ function is_port_valid($port, $device)
|
||||
if (preg_match($bi ."i", $if))
|
||||
{
|
||||
$valid = 0;
|
||||
if($debug) { echo("ignored : $bi : ".$if); }
|
||||
if ($debug) { echo("ignored : $bi : ".$if); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ foreach($ipsec_array as $index => $tunnel)
|
||||
|
||||
|
||||
|
||||
if(!is_array($tunnels[$tunnel['cikeTunRemoteValue']]))
|
||||
if (!is_array($tunnels[$tunnel['cikeTunRemoteValue']]))
|
||||
{
|
||||
$tunnel_id = dbInsert(array('device_id' => $device['device_id'], 'peer_addr' => $tunnel['cikeTunRemoteValue'], 'local_addr' => $tunnel['cikeTunLocalValue'], 'tunnel_name' => $tunnel['cikeTunLocalName']), 'ipsec_tunnels');
|
||||
} else {
|
||||
|
@@ -33,7 +33,7 @@ if (is_array($cefs))
|
||||
echo(" | |-".$path.": ".$cef_stat['cefSwitchingPath']);
|
||||
|
||||
|
||||
if(dbFetchCell("SELECT COUNT(*) FROM `cef_switching` WHERE `device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?", array($device['device_id'], $entity, $afi, $path)) != "1")
|
||||
if (dbFetchCell("SELECT COUNT(*) FROM `cef_switching` WHERE `device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?", array($device['device_id'], $entity, $afi, $path)) != "1")
|
||||
{
|
||||
dbInsert(array('device_id' => $device['device_id'], 'entPhysicalIndex' => $entity, 'afi' => $afi, 'cef_index' => $path, 'cef_path' => $cef_stat['cefSwitchingPath']), 'cef_switching');
|
||||
echo("+");
|
||||
@@ -74,7 +74,7 @@ if (is_array($cefs))
|
||||
$rrd_update = "N:".$cef_stat['cefSwitchingDrop'].":".$cef_stat['cefSwitchingPunt'].":".$cef_stat['cefSwitchingPunt2Host'];
|
||||
$ret = rrdtool_update("$filename", $rrd_update);
|
||||
|
||||
if($debug) { echo(" Values: ".$cef_stat['cefSwitchingDrop'].":".$cef_stat['cefSwitchingPunt'].":".$cef_stat['cefSwitchingPunt2Host']); }
|
||||
if ($debug) { echo(" Values: ".$cef_stat['cefSwitchingDrop'].":".$cef_stat['cefSwitchingPunt'].":".$cef_stat['cefSwitchingPunt2Host']); }
|
||||
|
||||
echo("\n");
|
||||
|
||||
|
@@ -8,7 +8,7 @@ function poll_sensor($device, $class, $unit)
|
||||
{
|
||||
echo("Checking $class " . $sensor['sensor_descr'] . "... ");
|
||||
|
||||
if($class == "temperature")
|
||||
if ($class == "temperature")
|
||||
{
|
||||
for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading
|
||||
{
|
||||
@@ -23,7 +23,7 @@ function poll_sensor($device, $class, $unit)
|
||||
$sensor_value = snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
|
||||
}
|
||||
|
||||
if($sensor_value == -32768) { echo("Invalid (-32768) "); $sensor_value = 0; }
|
||||
if ($sensor_value == -32768) { echo("Invalid (-32768) "); $sensor_value = 0; }
|
||||
|
||||
if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; }
|
||||
if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; }
|
||||
|
@@ -32,8 +32,8 @@ elseif ($device['os'] == "freebsd")
|
||||
{
|
||||
$poll_device[sysDescr] = str_replace(" 0 ", " ", $poll_device[sysDescr]);
|
||||
list(,,$version) = explode (" ", $poll_device[sysDescr]);
|
||||
if(strstr($poll_device[sysDescr], "i386")) { $hardware = "i386"; }
|
||||
else if(strstr($poll_device[sysDescr], "amd64")) { $hardware = "amd64"; }
|
||||
if (strstr($poll_device[sysDescr], "i386")) { $hardware = "i386"; }
|
||||
else if (strstr($poll_device[sysDescr], "amd64")) { $hardware = "amd64"; }
|
||||
else { $hardware = "i386"; }
|
||||
$features = "GENERIC";
|
||||
}
|
||||
|
@@ -285,7 +285,7 @@ if (is_array($ospf_nbrs_db))
|
||||
|
||||
if ($ospf_nbr_db['interface_id'] != $ospf_nbr_poll['interface_id'])
|
||||
{
|
||||
if($ospf_nbr_poll['interface_id']) {
|
||||
if ($ospf_nbr_poll['interface_id']) {
|
||||
$ospf_nbr_update = array('interface_id' => $ospf_nbr_poll['interface_id']);
|
||||
} else {
|
||||
$ospf_nbr_update = array('interface_id' => array('NULL'));
|
||||
|
@@ -309,14 +309,14 @@ foreach ($ports as $port)
|
||||
if ($config['enable_ports_poe']) { include("port-poe.inc.php"); }
|
||||
|
||||
/// Do Alcatel Detailed Stats
|
||||
if($device['os'] == "aos") { include("port-alcatel.inc.php"); }
|
||||
if ($device['os'] == "aos") { include("port-alcatel.inc.php"); }
|
||||
|
||||
|
||||
// Update Database
|
||||
if (count($port['update']))
|
||||
{
|
||||
$updated = dbUpdate($port['update'], 'ports', '`interface_id` = ?', array($port['interface_id']));
|
||||
if($debug) { echo("$updated updated"); }
|
||||
if ($debug) { echo("$updated updated"); }
|
||||
}
|
||||
// End Update Database
|
||||
|
||||
|
@@ -45,7 +45,7 @@ function ifLabel ($interface, $device = NULL)
|
||||
{
|
||||
$interface['label'] = $interface['ifName'];
|
||||
|
||||
if($interface['ifName'] == "")
|
||||
if ($interface['ifName'] == "")
|
||||
{
|
||||
$interface['label'] = $interface['ifDescr'];
|
||||
} else {
|
||||
@@ -977,7 +977,7 @@ function rewrite_adslLineType($adslLineType)
|
||||
|
||||
foreach($adslLineTypes as $type => $text)
|
||||
{
|
||||
if($adslLineType == $type)
|
||||
if ($adslLineType == $type)
|
||||
{
|
||||
$adslLineType = $text;
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
|
||||
function callsgraphSNOM ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
|
||||
global $config;
|
||||
|
||||
$database = $config['rrd_dir'] . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical ,"--alt-autoscale-max",
|
||||
@@ -16,7 +17,7 @@ function callsgraphSNOM ($rrd, $graph, $from, $to, $width, $height, $title, $ver
|
||||
"GPRINT:calls:LAST:Cu\: %2.0lf/min",
|
||||
"GPRINT:calls:AVERAGE:Av\: %2.0lf/min",
|
||||
"GPRINT:calls:MAX:Mx\: %2.0lf/min\\n");
|
||||
if($width <= "300") {$optsb = array("--font", "LEGEND:7:".$config['mono_font']."",
|
||||
if ($width <= "300") {$optsb = array("--font", "LEGEND:7:".$config['mono_font']."",
|
||||
"--font", "AXIS:6:".$config['mono_font']."",
|
||||
"--font-render-mode", "normal");}
|
||||
|
||||
@@ -24,7 +25,7 @@ function callsgraphSNOM ($rrd, $graph, $from, $to, $width, $height, $title, $ver
|
||||
|
||||
$ret = rrd_graph("$imgfile", $opts, count($opts));
|
||||
|
||||
if( !is_array($ret) ) {
|
||||
if ( !is_array($ret) ) {
|
||||
$err = rrd_error();
|
||||
echo("rrd_graph() ERROR: $err\n");
|
||||
return FALSE;
|
||||
|
@@ -8,13 +8,14 @@
|
||||
|
||||
function get_cache($host, $value){
|
||||
global $dev_cache;
|
||||
if(!isset($dev_cache[$host][$value])){
|
||||
|
||||
if (!isset($dev_cache[$host][$value])){
|
||||
switch($value){
|
||||
case 'device_id':
|
||||
//Try by hostname
|
||||
$dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ?', array($host, $host));
|
||||
//If failed, try by IP
|
||||
if(!is_numeric($dev_cache[$host]['device_id'])) {
|
||||
if (!is_numeric($dev_cache[$host]['device_id'])) {
|
||||
$dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `ipv4_addresses` AS A, `ports` AS I WHERE A.ipv4_address = ? AND I.interface_id = A.interface_id', array($host));
|
||||
}
|
||||
break;
|
||||
@@ -34,22 +35,23 @@ function get_cache($host, $value){
|
||||
|
||||
function process_syslog ($entry, $update) {
|
||||
global $config;
|
||||
|
||||
global $dev_cache;
|
||||
|
||||
foreach($config['syslog_filter'] as $bi)
|
||||
if(strpos($entry['msg'], $bi) !== FALSE){
|
||||
if (strpos($entry['msg'], $bi) !== FALSE){
|
||||
print_r($entry);
|
||||
echo('D-'.$bi);
|
||||
return $entry;
|
||||
}
|
||||
|
||||
$entry['device_id'] = get_cache($entry['host'], 'device_id');
|
||||
if($entry['device_id']) {
|
||||
if ($entry['device_id']) {
|
||||
$os = get_cache($entry['host'], 'os');
|
||||
|
||||
if(in_array($os, array('ios', 'iosxe', 'catos'))){
|
||||
if (in_array($os, array('ios', 'iosxe', 'catos'))){
|
||||
$matches = array();
|
||||
# if(preg_match('#%(?P<program>.*):( ?)(?P<msg>.*)#', $entry['msg'], $matches)){
|
||||
# if (preg_match('#%(?P<program>.*):( ?)(?P<msg>.*)#', $entry['msg'], $matches)){
|
||||
# $entry['msg'] = $matches['msg'];
|
||||
# $entry['program'] = $matches['program'];
|
||||
# }
|
||||
@@ -87,7 +89,7 @@ function process_syslog ($entry, $update) {
|
||||
} elseif($os == 'linux' and get_cache($entry['host'], 'version') == 'Point'){
|
||||
//Cisco WAP200 and similar
|
||||
$matches = array();
|
||||
if(preg_match('#Log: \[(?P<program>.*)\] - (?P<msg>.*)#', $entry['msg'], $matches)){
|
||||
if (preg_match('#Log: \[(?P<program>.*)\] - (?P<msg>.*)#', $entry['msg'], $matches)){
|
||||
$entry['msg'] = $matches['msg'];
|
||||
$entry['program'] = $matches['program'];
|
||||
}
|
||||
@@ -96,7 +98,7 @@ function process_syslog ($entry, $update) {
|
||||
} 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
|
||||
if($entry['facility'] == 'daemon' and preg_match('#/([0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]{4,} ([A-Z]([A-Za-z])+( ?)){2,}:#', $entry['msg'])){
|
||||
if ($entry['facility'] == 'daemon' and preg_match('#/([0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]{4,} ([A-Z]([A-Za-z])+( ?)){2,}:#', $entry['msg'])){
|
||||
$entry['program'] = 'OpenVPN';
|
||||
}
|
||||
//pop3-login: Login: user=<username>, method=PLAIN, rip=123.213.132.231, lip=123.213.132.231, TLS
|
||||
@@ -126,14 +128,14 @@ function process_syslog ($entry, $update) {
|
||||
unset($matches);
|
||||
}
|
||||
|
||||
if(!isset($entry['program'])){
|
||||
if (!isset($entry['program'])){
|
||||
$entry['program'] = $entry['msg'];
|
||||
unset($entry['msg']);
|
||||
}
|
||||
$entry['program'] = strtoupper($entry['program']);
|
||||
array_walk($entry, 'trim');
|
||||
|
||||
if($update)
|
||||
if ($update)
|
||||
dbInsert(
|
||||
array(
|
||||
'device_id' => $entry['device_id'],
|
||||
|
@@ -24,13 +24,13 @@ if($dataHandle)
|
||||
{
|
||||
$data.= fread($dataHandle, 4096);
|
||||
}
|
||||
if($data)
|
||||
if ($data)
|
||||
{
|
||||
list($omnipotence, $year, $month, $revision) = explode(".", $data);
|
||||
list($cur, $tag) = explode("-", $config['version']);
|
||||
list($cur_omnipotence, $cur_year, $cur_month, $cur_revision) = explode(".", $cur);
|
||||
|
||||
if($argv[1] == "--cron" || isset($options['q'])) {
|
||||
if ($argv[1] == "--cron" || isset($options['q'])) {
|
||||
|
||||
$fd = fopen($config['log_file'],'a');
|
||||
fputs($fd,$string . "\n");
|
||||
@@ -40,10 +40,10 @@ if($dataHandle)
|
||||
|
||||
} else {
|
||||
|
||||
if($cur != $data) {
|
||||
if ($cur != $data) {
|
||||
echo("Current Version : $cur_omnipotence.$cur_year.$cur_month.$cur_revision \n");
|
||||
|
||||
if($omnipotence > $cur_omnipotence) {
|
||||
if ($omnipotence > $cur_omnipotence) {
|
||||
echo("New version : $omnipotence.$year.$month.$revision\n");
|
||||
} elseif ($year > $cur_year) {
|
||||
echo("New version : $omnipotence.$year.$month.$revision\n");
|
||||
|
Reference in New Issue
Block a user