Merge pull request #2 from librenms/master

update to master
This commit is contained in:
deutor
2016-08-31 09:34:13 +02:00
committed by GitHub
co-authored by GitHub
512 changed files with 39530 additions and 5836 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
#### Please note
> Please read this information carefully.
> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.
- [ ] Have you signed the [Contributors agreement](http://docs.librenms.org/General/Contributing/)
- [ ] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)
+1
View File
@@ -22,3 +22,4 @@ nbproject
patches
rrd
/vendor
composer.phar
+7 -17
View File
@@ -3,33 +3,24 @@ matrix:
fast_finish: true
include:
- php: 7.0
env:
PHP_L=1
EXECUTE_BUILD_DOCS=false
- php: 5.3
env:
PHP_L_OLD=1
EXECUTE_BUILD_DOCS=false
SKIP_STYLE_CHECK=1
- php: 5.4
env:
PHP_L_OLD=1
EXECUTE_BUILD_DOCS=false
SKIP_STYLE_CHECK=1
- php: 5.5
env:
PHP_L=1
EXECUTE_BUILD_DOCS=false
SKIP_STYLE_CHECK=1
- php: 5.6
env:
PHP_L=1
PHP_CS=1
SKIP_STYLE_CHECK=1
EXECUTE_BUILD_DOCS=true
- php: hhvm
env:
PHP_L_OLD=1
EXECUTE_BUILD_DOCS=false
SKIP_STYLE_CHECK=1
allow_failures:
- php: 7.0
- php: hhvm
cache:
@@ -44,7 +35,6 @@ after_success:
- test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && test $EXECUTE_BUILD_DOCS == "true" && bash scripts/deploy-docs.sh
script:
- if [[ $PHP_L == 1 ]]; then find . -path './vendor' -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1; fi
- if [[ $PHP_L_OLD == 1 ]]; then find . -regextype posix-extended -regex "\./(lib/influxdb-php|vendor)" -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1; fi
- if [[ $PHP_CS == 1 ]]; then vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 --ignore=html/lib/* html; fi
- php scripts/pre-commit.php -p -l
- php scripts/pre-commit.php -p -s
- phpunit
+4
View File
@@ -121,6 +121,10 @@ LibreNMS contributors:
- Phil Regnauld <regnauld@x0.dk> (reegnauld)
- Russell Morris <github@rkmorris.us> (arrmo)
- Bennett Blodinger <bennett.blodinger@gmail.com> (benwa)
- Michael Hansen <nerdalertdk@gmail.com> (nerdalertdk)
- Daniel Cox <danielcoxman@gmail.com> (ospfbgp)
- Joseph Cunningham <joey.was@gmail.com> (joeywas)
- Michael Van Delft <librenms@xo.tc> (HybridAU)
[1]: http://observium.org/ "Observium web site"
Observium was written by:
+5 -5
View File
@@ -25,7 +25,6 @@
namespace LibreNMS;
/**
* Class ClassLoader
* @package LibreNMS
@@ -63,7 +62,7 @@ class ClassLoader
$file = str_replace(array('\\', '_'), DIRECTORY_SEPARATOR, $name) . '.php';
$fullFile = realpath(__DIR__ . '/..') . DIRECTORY_SEPARATOR . $file;
if($vdebug) {
if ($vdebug) {
echo __CLASS__ . " [[ $name > $fullFile ]]\n";
}
@@ -84,7 +83,7 @@ class ClassLoader
if (isset($this->classMap[$name])) {
$file = $this->classMap[$name];
if($vdebug) {
if ($vdebug) {
echo __CLASS__ . " (( $name > $file ))\n";
}
@@ -99,7 +98,7 @@ class ClassLoader
foreach (array_keys($this->dirMap[$namespace]) as $dir) {
$file = $dir . DIRECTORY_SEPARATOR . $class . '.php';
if($vdebug) {
if ($vdebug) {
echo __CLASS__ . " (( $name > $file ))\n";
}
@@ -180,7 +179,8 @@ class ClassLoader
* @param string $class the full class name to split
* @return array of the split class [namespace, classname]
*/
private function splitNamespace($class) {
private function splitNamespace($class)
{
$parts = explode('\\', $class);
$last = array_pop($parts);
return array(implode('\\', $parts), $last);
+41 -42
View File
@@ -25,7 +25,8 @@
namespace LibreNMS;
class Component {
class Component
{
/*
* These fields are used in the component table. They are returned in the array
* so that they can be modified but they can not be set as user attributes. We
@@ -40,12 +41,12 @@ class Component {
'error' => '',
);
public function getComponentType($TYPE=null) {
public function getComponentType($TYPE = null)
{
if (is_null($TYPE)) {
$SQL = "SELECT DISTINCT `type` as `name` FROM `component` ORDER BY `name`";
$row = dbFetchRow($SQL, array());
}
else {
} else {
$SQL = "SELECT DISTINCT `type` as `name` FROM `component` WHERE `type` = ? ORDER BY `name`";
$row = dbFetchRow($SQL, array($TYPE));
}
@@ -53,14 +54,14 @@ class Component {
if (!isset($row)) {
// We didn't find any component types
return false;
}
else {
} else {
// We found some..
return $row;
}
}
public function getComponents($device_id=null,$options=array()) {
public function getComponents($device_id = null, $options = array())
{
// Define our results array, this will be set even if no rows are returned.
$RESULT = array();
$PARAM = array();
@@ -87,25 +88,24 @@ class Component {
$SQL .= " ( ";
foreach ($options['filter'] as $field => $array) {
// Only add valid fields to the query
if (in_array($field,$validFields)) {
if (in_array($field, $validFields)) {
if ($array[0] == 'LIKE') {
$SQL .= "`".$field."` LIKE ? AND ";
$array[1] = "%".$array[1]."%";
}
else {
} else {
// Equals operator is the default
$SQL .= "`".$field."` = ? AND ";
}
array_push($PARAM,$array[1]);
array_push($PARAM, $array[1]);
}
}
// Strip the last " AND " before closing the bracket.
$SQL = substr($SQL,0,-5)." )";
$SQL = substr($SQL, 0, -5)." )";
}
if ($COUNT == 0) {
// Strip the " WHERE " that we didn't use.
$SQL = substr($SQL,0,-7);
$SQL = substr($SQL, 0, -7);
}
// sort column direction
@@ -149,7 +149,7 @@ class Component {
foreach ($RESULT as $k => $v) {
// k1 = component id, v1 = component array
foreach ($v as $k1 => $v1) {
if ( ($COUNT >= $options['limit'][0]) && ($COUNT < $options['limit'][0]+$options['limit'][1])) {
if (($COUNT >= $options['limit'][0]) && ($COUNT < $options['limit'][0]+$options['limit'][1])) {
$TEMP[$k][$k1] = $v1;
}
// We are counting components.
@@ -162,7 +162,8 @@ class Component {
return $RESULT;
}
public function getComponentStatus($device=null) {
public function getComponentStatus($device = null)
{
$sql_query = "SELECT status, count(status) as count FROM component WHERE";
$sql_param = array();
$add = 0;
@@ -191,12 +192,13 @@ class Component {
$count[$v['status']] = $v['count'];
}
d_echo("Component Count by Status: ".print_r($count,TRUE)."\n");
d_echo("Component Count by Status: ".print_r($count, true)."\n");
return $count;
}
public function getComponentStatusLog($component=null,$start=null,$end=null) {
if ( ($component == null) || ($start == null) || ($end == null) ) {
public function getComponentStatusLog($component = null, $start = null, $end = null)
{
if (($component == null) || ($start == null) || ($end == null)) {
// Error...
d_echo("Required arguments are missing. Component: ".$component.", Start: ".$start.", End: ".$end."\n");
return false;
@@ -211,8 +213,7 @@ class Component {
$result = dbFetchRow($sql_query, $sql_param);
if ($result == false) {
$return['initial'] = false;
}
else {
} else {
$return['initial'] = $result['status'];
}
@@ -221,11 +222,12 @@ class Component {
$sql_param = array($component,$start,$end);
$return['data'] = dbFetchRows($sql_query, $sql_param);
d_echo("Status Log Data: ".print_r($return,TRUE)."\n");
d_echo("Status Log Data: ".print_r($return, true)."\n");
return $return;
}
public function createComponent ($device_id,$TYPE) {
public function createComponent($device_id, $TYPE)
{
// Prepare our default values to be inserted.
$DATA = $this->reserved;
@@ -237,16 +239,17 @@ class Component {
$id = dbInsert($DATA, 'component');
// Add a default status log entry - we always start ok.
$this->createStatusLogEntry($id,0,'Component Created');
$this->createStatusLogEntry($id, 0, 'Component Created');
// Create a default component array based on what was inserted.
$ARRAY = array();
$ARRAY[$id] = $DATA;
unset ($ARRAY[$id]['device_id']); // This doesn't belong here.
unset($ARRAY[$id]['device_id']); // This doesn't belong here.
return $ARRAY;
}
public function createStatusLogEntry($component,$status,$message) {
public function createStatusLogEntry($component, $status, $message)
{
// Add an entry to the statuslog table for a particular component.
$DATA = array(
'component' => $component,
@@ -257,18 +260,19 @@ class Component {
return dbInsert($DATA, 'component_statuslog');
}
public function deleteComponent ($id) {
public function deleteComponent($id)
{
// Delete a component from the database.
return dbDelete('component', "`id` = ?",array($id));
return dbDelete('component', "`id` = ?", array($id));
}
public function setComponentPrefs ($device_id,$ARRAY) {
public function setComponentPrefs($device_id, $ARRAY)
{
// Compare the arrays. Update/Insert where necessary.
$OLD = $this->getComponents($device_id);
// Loop over each component.
foreach ($ARRAY as $COMPONENT => $AVP) {
// Make sure the component already exists.
if (!isset($OLD[$device_id][$COMPONENT])) {
// Error. Component doesn't exist in the database.
@@ -281,7 +285,7 @@ class Component {
// If the Status has changed we need to add a log entry
if ($AVP['status'] != $OLD[$device_id][$COMPONENT]['status']) {
d_echo("Status Changed - Old: ".$OLD[$device_id][$COMPONENT]['status'].", New: ".$AVP['status']."\n");
$this->createStatusLogEntry($COMPONENT,$AVP['status'],$AVP['error']);
$this->createStatusLogEntry($COMPONENT, $AVP['status'], $AVP['error']);
}
// Process our reserved components first.
@@ -289,7 +293,6 @@ class Component {
foreach ($this->reserved as $k => $v) {
// does the reserved field exist, if not skip.
if (isset($AVP[$k])) {
// Has the value changed?
if ($AVP[$k] != $OLD[$device_id][$COMPONENT][$k]) {
// The value has been modified, add it to our update array.
@@ -311,8 +314,8 @@ class Component {
foreach ($UPDATE as $k => $v) {
$MSG .= $k." => ".$v.",";
}
$MSG = substr($MSG,0,-1);
log_event($MSG,$device_id,'component',$COMPONENT);
$MSG = substr($MSG, 0, -1);
log_event($MSG, $device_id, 'component', $COMPONENT);
}
// Process our AVP Adds and Updates
@@ -325,32 +328,28 @@ class Component {
dbInsert($DATA, 'component_prefs');
// Log the addition to the Eventlog.
log_event ("Component: " . $AVP[$COMPONENT]['type'] . "(" . $COMPONENT . "). Attribute: " . $ATTR . ", was added with value: " . $VALUE, $device_id, 'component', $COMPONENT);
}
elseif ($OLD[$device_id][$COMPONENT][$ATTR] != $VALUE) {
log_event("Component: " . $AVP[$COMPONENT]['type'] . "(" . $COMPONENT . "). Attribute: " . $ATTR . ", was added with value: " . $VALUE, $device_id, 'component', $COMPONENT);
} elseif ($OLD[$device_id][$COMPONENT][$ATTR] != $VALUE) {
// Attribute exists but the value is different, need to update
$DATA = array('value'=>$VALUE);
dbUpdate($DATA, 'component_prefs', '`component` = ? AND `attribute` = ?', array($COMPONENT, $ATTR));
// Add the modification to the Eventlog.
log_event("Component: ".$AVP[$COMPONENT]['type']."(".$COMPONENT."). Attribute: ".$ATTR.", was modified from: ".$OLD[$COMPONENT][$ATTR].", to: ".$VALUE,$device_id,'component',$COMPONENT);
log_event("Component: ".$AVP[$COMPONENT]['type']."(".$COMPONENT."). Attribute: ".$ATTR.", was modified from: ".$OLD[$COMPONENT][$ATTR].", to: ".$VALUE, $device_id, 'component', $COMPONENT);
}
} // End Foreach AVP
// Process our Deletes.
$DELETE = array_diff_key($OLD[$device_id][$COMPONENT], $AVP);
foreach ($DELETE as $KEY => $VALUE) {
// As the Attribute has been removed from the array, we should remove it from the database.
dbDelete('component_prefs', "`component` = ? AND `attribute` = ?",array($COMPONENT,$KEY));
dbDelete('component_prefs', "`component` = ? AND `attribute` = ?", array($COMPONENT,$KEY));
// Log the addition to the Eventlog.
log_event ("Component: " . $AVP[$COMPONENT]['type'] . "(" . $COMPONENT . "). Attribute: " . $KEY . ", was deleted.", $COMPONENT);
log_event("Component: " . $AVP[$COMPONENT]['type'] . "(" . $COMPONENT . "). Attribute: " . $KEY . ", was deleted.", $COMPONENT);
}
}
return true;
}
}
@@ -25,7 +25,6 @@
namespace LibreNMS\Exceptions;
class FileExistsException extends \Exception
{
@@ -25,7 +25,6 @@
namespace LibreNMS\Exceptions;
class HostExistsException extends \Exception
{
@@ -25,7 +25,6 @@
namespace LibreNMS\Exceptions;
class HostIpExistsException extends HostExistsException
{
@@ -25,7 +25,6 @@
namespace LibreNMS\Exceptions;
class HostUnreachableException extends \Exception
{
protected $reasons = array();
@@ -25,7 +25,6 @@
namespace LibreNMS\Exceptions;
class HostUnreachablePingException extends HostUnreachableException
{
@@ -25,7 +25,6 @@
namespace LibreNMS\Exceptions;
class HostUnreachableSnmpException extends HostUnreachableException
{
@@ -25,7 +25,6 @@
namespace LibreNMS\Exceptions;
class InvalidPortAssocModeException extends \Exception
{
@@ -25,7 +25,6 @@
namespace LibreNMS\Exceptions;
class SnmpVersionUnsupportedException extends \Exception
{
+729
View File
@@ -0,0 +1,729 @@
<?php
/*
* Copyright (C) 2014 <[email protected]>
* Modified and Relicensed by <[email protected]> under the expressed
* permission by the Copyright-Holder <[email protected]>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* */
namespace LibreNMS;
class IRCBot
{
private $last_activity = '';
private $data = '';
private $authd = array();
private $debug = false;
private $server = '';
private $port = '';
private $ssl = false;
private $pass = '';
private $nick = 'LibreNMS';
private $chan = array();
private $commands = array(
'auth',
'quit',
'listdevices',
'device',
'port',
'down',
'version',
'status',
'log',
'help',
'reload',
'join',
);
private $external = array();
private $tick = 62500;
public function __construct()
{
global $config, $database_link;
$this->log('Setting up IRC-Bot..');
if (is_resource($database_link)) {
$this->sql = $database_link;
}
$this->config = $config;
$this->debug = $this->config['irc_debug'];
$this->config['irc_authtime'] = $this->config['irc_authtime'] ? $this->config['irc_authtime'] : 3;
$this->max_retry = $this->config['irc_maxretry'];
$this->server = $this->config['irc_host'];
if ($this->config['irc_port'][0] == '+') {
$this->ssl = true;
$this->port = substr($this->config['irc_port'], 1);
} else {
$this->port = $this->config['irc_port'];
}
if ($this->config['irc_nick']) {
$this->nick = $this->config['irc_nick'];
}
if ($this->config['irc_chan']) {
if (is_array($this->config['irc_chan'])) {
$this->chan = $this->config['irc_chan'];
} elseif (strstr($this->config['irc_chan'], ',')) {
$this->chan = explode(',', $this->config['irc_chan']);
} else {
$this->chan = array($this->config['irc_chan']);
}
}
if ($this->config['irc_alert_chan']) {
if (strstr($this->config['irc_alert_chan'], ',')) {
$this->config['irc_alert_chan'] = explode(',', $this->config['irc_alert_chan']);
} else {
$this->config['irc_alert_chan'] = array($this->config['irc_alert_chan']);
}
}
if ($this->config['irc_pass']) {
$this->pass = $this->config['irc_pass'];
}
$this->loadExternal();
$this->log('Starting IRC-Bot..');
$this->init();
}//end __construct()
private function loadExternal()
{
if (!$this->config['irc_external']) {
return true;
}
$this->log('Caching external commands...');
if (!is_array($this->config['irc_external'])) {
$this->config['irc_external'] = explode(',', $this->config['irc_external']);
}
foreach ($this->config['irc_external'] as $ext) {
if (($this->external[$ext] = file_get_contents('includes/ircbot/'.$ext.'.inc.php')) == '') {
unset($this->external[$ext]);
}
}
return $this->log('Cached '.sizeof($this->external).' commands.');
}//end load_external()
private function init()
{
if ($this->config['irc_alert']) {
$this->connectAlert();
}
$this->last_activity = time();
$this->j = 2;
$this->connect();
$this->log('Connected');
if ($this->pass) {
fwrite($this->socket['irc'], 'PASS '.$this->pass."\n\r");
}
$this->doAuth();
while (true) {
foreach ($this->socket as $n => $socket) {
if (!is_resource($socket) || feof($socket)) {
$this->log("Socket '$n' closed. Restarting.");
break 2;
}
}
$this->getData();
if ($this->config['irc_alert']) {
$this->alertData();
}
if ($this->config['irc_conn_timeout']) {
$inactive_seconds = time() - $this->last_activity;
$max_inactive = $this->config['irc_conn_timeout'];
if ($inactive_seconds > $max_inactive) {
$this->log("No data from server since " . $max_inactive . " seconds. Restarting.");
break;
}
}
usleep($this->tick);
}
return $this->init();
}//end init()
private function connectAlert()
{
$f = $this->config['install_dir'].'/.ircbot.alert';
if (( file_exists($f) && filetype($f) != 'fifo' && !unlink($f) ) || ( !file_exists($f) && !shell_exec("mkfifo $f && echo 1") )) {
$this->log('Error - Cannot create Alert-File');
return false;
}
if (($this->socket['alert'] = fopen($f, 'r+'))) {
$this->log('Opened Alert-File');
stream_set_blocking($this->socket['alert'], false);
return true;
}
$this->log('Error - Cannot open Alert-File');
return false;
}//end connect_alert()
private function read($buff)
{
$r = fread($this->socket[$buff], 64);
$this->buff[$buff] .= $r;
$r = strlen($r);
if (strstr($this->buff[$buff], "\n")) {
$tmp = explode("\n", $this->buff[$buff], 2);
$this->buff[$buff] = substr($this->buff[$buff], (strlen($tmp[0]) + 1));
if ($this->debug) {
$this->log("Returning buffer '$buff': '".trim($tmp[0])."'");
}
return $tmp[0];
}
if ($this->debug && $r > 0) {
$this->log("Expanding buffer '$buff' = '".trim($this->buff[$buff])."'");
}
return false;
}//end read()
private function alertData()
{
if (($alert = $this->read('alert')) !== false) {
$alert = json_decode($alert, true);
if (!is_array($alert)) {
return false;
}
switch ($alert['state']) :
case 3:
$severity_extended = '+';
break;
case 4:
$severity_extended = '-';
break;
default:
$severity_extended = '';
endswitch;
$severity = str_replace(array('warning', 'critical'), array(chr(3).'8Warning', chr(3).'4Critical'), $alert['severity']).$severity_extended.chr(3).' ';
if ($alert['state'] == 0 and $this->config['irc_alert_utf8']) {
$severity = str_replace(array('Warning', 'Critical'), array('W̶a̶r̶n̶i̶n̶g̶', 'C̶r̶i̶t̶i̶c̶a̶l̶'), $severity);
}
if ($this->config['irc_alert_chan']) {
foreach ($this->config['irc_alert_chan'] as $chan) {
$this->ircRaw('PRIVMSG '.$chan.' :'.$severity.trim($alert['title']).' - Rule: '.trim($alert['name'] ? $alert['name'] : $alert['rule']).(sizeof($alert['faults']) > 0 ? ' - Faults:' : ''));
foreach ($alert['faults'] as $k => $v) {
$this->ircRaw('PRIVMSG '.$chan.' :#'.$k.' '.$v['string']);
}
}
} else {
foreach ($this->authd as $nick => $data) {
if ($data['expire'] >= time()) {
$this->ircRaw('PRIVMSG '.$nick.' :'.$severity.trim($alert['title']).' - Rule: '.trim($alert['name'] ? $alert['name'] : $alert['rule']).(sizeof($alert['faults']) > 0 ? ' - Faults'.(sizeof($alert['faults']) > 3 ? ' (showing first 3 out of '.sizeof($alert['faults']).' )' : '' ).':' : ''));
foreach ($alert['faults'] as $k => $v) {
$this->ircRaw('PRIVMSG '.$nick.' :#'.$k.' '.$v['string']);
if ($k >= 3) {
break;
}
}
}
}
}
}//end if
}//end alertData()
private function getData()
{
if (($data = $this->read('irc')) !== false) {
$this->last_activity = time();
$this->data = $data;
$ex = explode(' ', $this->data);
if ($ex[0] == 'PING') {
return $this->ircRaw('PONG '.$ex[1]);
}
if ($ex[1] == 376 || $ex[1] == 422 || ($ex[1] == 'MODE' && $ex[2] == $this->nick)) {
if ($this->j == 2) {
$this->joinChan();
$this->j = 0;
}
}
$this->command = str_replace(array(chr(10), chr(13)), '', $ex[3]);
if (strstr($this->command, ':.')) {
$this->handleCommand();
}
}
}//end getData()
private function joinChan($chan = false)
{
if ($chan) {
$this->chan[] = $chan;
}
foreach ($this->chan as $chan) {
$this->ircRaw('JOIN '.$chan);
}
return true;
}//end joinChan()
private function handleCommand()
{
$this->command = str_replace(':.', '', $this->command);
$tmp = explode(':.'.$this->command.' ', $this->data);
$this->user = $this->getAuthdUser();
if ($this->isAuthd() || trim($this->command) == 'auth') {
$this->proceedCommand(str_replace("\n", '', trim($this->command)), trim($tmp[1]));
}
$this->authd[$this->getUser($this->data)] = $this->user;
return false;
}//end handleCommand()
private function proceedCommand($command, $params)
{
$command = strtolower($command);
if (in_array($command, $this->commands)) {
$this->chkdb();
$this->log($command." ( '".$params."' )");
return $this->{'_'.$command}($params);
} elseif ($this->external[$command]) {
$this->chkdb();
$this->log($command." ( '".$params."' ) [Ext]");
return eval($this->external[$command]);
}
return false;
}//end proceedCommand()
private function respond($msg)
{
$chan = $this->getChan($this->data);
return $this->sendMessage($msg, strstr($chan, '#') ? $chan : $this->getUser($this->data));
}//end respond()
private function getChan($param)
{
$data = explode('PRIVMSG ', $this->data, 3);
$data = explode(' ', $data[1], 2);
return $data[0];
}//end getChan()
private function getUser($param)
{
$arrData = explode('!', $param, 2);
return str_replace(':', '', $arrData[0]);
}//end getUser()
private function connect($try)
{
if ($try > $this->max_retry) {
$this->log('Failed too many connection attempts, aborting');
return die();
}
$this->log('Trying to connect to '.$this->server.':'.$this->port.($this->ssl ? ' (SSL)' : ''));
if ($this->socket['irc']) {
fclose($this->socket['irc']);
}
if ($this->ssl) {
$server = 'ssl://'.$this->server;
} else {
$server = $this->server;
}
if ($this->ssl && $this->config['irc_disable_ssl_check']) {
$ssl_context_params = array('ssl'=>array('allow_self_signed'=> true, 'verify_peer' => false, 'verify_peer_name' => false ));
$ssl_context = stream_context_create($ssl_context_params);
$this->socket['irc'] = stream_socket_client($server.':'.$this->port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $ssl_context);
} else {
$this->socket['irc'] = fsockopen($server, $this->port);
}
if (!is_resource($this->socket['irc'])) {
return $this->connect($try + 1);
} else {
stream_set_blocking($this->socket['irc'], false);
return true;
}
}//end connect()
private function doAuth()
{
if ($this->ircRaw('USER '.$this->nick.' 0 '.$this->nick.' :'.$this->nick) && $this->ircRaw('NICK '.$this->nick)) {
return true;
}
return false;
}//end doAuth()
private function sendMessage($message, $chan)
{
if ($this->debug) {
$this->log("Sending 'PRIVMSG ".trim($chan).' :'.trim($message)."'");
}
return $this->ircRaw('PRIVMSG '.trim($chan).' :'.trim($message));
}//end sendMessage()
private function log($msg)
{
echo '['.date('r').'] '.trim($msg)."\n";
return true;
}//end log()
private function chkdb()
{
if (!is_resource($this->sql)) {
if (($this->sql = mysqli_connect($this->config['db_host'], $this->config['db_user'], $this->config['db_pass'])) != false && mysqli_select_db($this->sql, $this->config['db_name'])) {
return true;
} else {
$this->log('Cannot connect to MySQL');
return die();
}
} else {
return true;
}
}//end chkdb()
private function isAuthd()
{
if ($this->user['expire'] >= time()) {
$this->user['expire'] = (time() + ($this->config['irc_authtime'] * 3600));
return true;
} else {
return false;
}
}//end isAuthd()
private function getAuthdUser()
{
return $this->authd[$this->getUser($this->data)];
}//end get_user()
private function ircRaw($params)
{
return fputs($this->socket['irc'], $params."\r\n");
}//end irc_raw()
private function _auth($params)
{
$params = explode(' ', $params, 2);
if (strlen($params[0]) == 64) {
if ($this->tokens[$this->getUser($this->data)] == $params[0]) {
$this->user['expire'] = (time() + ($this->config['irc_authtime'] * 3600));
$tmp = dbFetchRow('SELECT level FROM users WHERE user_id = ?', array($this->user['id']));
$this->user['level'] = $tmp['level'];
if ($this->user['level'] < 5) {
foreach (dbFetchRows('SELECT device_id FROM devices_perms WHERE user_id = ?', array($this->user['id'])) as $tmp) {
$this->user['devices'][] = $tmp['device_id'];
}
foreach (dbFetchRows('SELECT port_id FROM ports_perms WHERE user_id = ?', array($this->user['id'])) as $tmp) {
$this->user['ports'][] = $tmp['port_id'];
}
}
return $this->respond('Authenticated.');
} else {
return $this->respond('Nope.');
}
} else {
$user = dbFetchRow('SELECT `user_id`,`username`,`email` FROM `users` WHERE `username` = ?', array(mres($params[0])));
if ($user['email'] && $user['username'] == $params[0]) {
$token = hash('gost', openssl_random_pseudo_bytes(1024));
$this->tokens[$this->getUser($this->data)] = $token;
$this->user['name'] = $params[0];
$this->user['id'] = $user['user_id'];
if ($this->debug) {
$this->log("Auth for '".$params[0]."', ID: '".$user['user_id']."', Token: '".$token."', Mail: '".$user['email']."'");
}
if (send_mail($user['email'], 'LibreNMS IRC-Bot Authtoken', "Your Authtoken for the IRC-Bot:\r\n\r\n".$token."\r\n\r\n") === true) {
return $this->respond('Token sent!');
} else {
return $this->respond('Sorry, seems like mail doesnt like us.');
}
} else {
return $this->respond('Who are you again?');
}
}//end if
return false;
}//end _auth()
private function _reload()
{
if ($this->user['level'] == 10) {
global $config;
$config = array();
include 'includes/defaults.inc.php';
include 'config.php';
include 'includes/definitions.inc.php';
$this->respond('Reloading configuration & defaults');
if ($config != $this->config) {
return $this->__construct();
}
} else {
return $this->respond('Permission denied.');
}
}//end _reload()
private function _join($params)
{
if ($this->user['level'] == 10) {
return $this->joinChan($params);
} else {
return $this->respond('Permission denied.');
}
}//end _join()
private function _quit($params)
{
if ($this->user['level'] == 10) {
return die();
} else {
return $this->respond('Permission denied.');
}
}//end _quit()
private function _help($params)
{
foreach ($this->commands as $cmd) {
$msg .= ', '.$cmd;
}
$msg = substr($msg, 2);
return $this->respond("Available commands: $msg");
}//end _help()
private function _version($params)
{
return $this->respond($this->config['project_name_version'].', PHP: '.PHP_VERSION);
}//end _version()
private function _log($params)
{
$num = 1;
if ($params > 1) {
$num = $params;
}
if ($this->user['level'] < 5) {
$tmp = dbFetchRows('SELECT `event_id`,`host`,`datetime`,`message`,`type` FROM `eventlog` WHERE `host` IN ('.implode(',', $this->user['devices']).') ORDER BY `event_id` DESC LIMIT '.mres($num));
} else {
$tmp = dbFetchRows('SELECT `event_id`,`host`,`datetime`,`message`,`type` FROM `eventlog` ORDER BY `event_id` DESC LIMIT '.mres($num));
}
foreach ($tmp as $device) {
$hostid = dbFetchRow('SELECT `hostname` FROM `devices` WHERE `device_id` = '.$device['host']);
$this->respond($device['event_id'].' '.$hostid['hostname'].' '.$device['datetime'].' '.$device['message'].' '.$device['type']);
}
if (!$hostid) {
$this->respond('Nothing to see, maybe a bug?');
}
return true;
}//end _log()
private function _down($params)
{
if ($this->user['level'] < 5) {
$tmp = dbFetchRows('SELECT `hostname` FROM `devices` WHERE status=0 AND `device_id` IN ('.implode(',', $this->user['devices']).')');
} else {
$tmp = dbFetchRows('SELECT `hostname` FROM `devices` WHERE status=0');
}
foreach ($tmp as $db) {
if ($db['hostname']) {
$msg .= ', '.$db['hostname'];
}
}
$msg = substr($msg, 2);
$msg = $msg ? $msg : 'Nothing to show :)';
return $this->respond($msg);
}//end _down()
private function _device($params)
{
$params = explode(' ', $params);
$hostname = $params[0];
$device = dbFetchRow('SELECT * FROM `devices` WHERE `hostname` = ?', array($hostname));
if (!$device) {
return $this->respond('Error: Bad or Missing hostname, use .listdevices to show all devices.');
}
if ($this->user['level'] < 5 && !in_array($device['device_id'], $this->user['devices'])) {
return $this->respond('Error: Permission denied.');
}
$status = $device['status'] ? 'Up '.formatUptime($device['uptime']) : 'Down';
$status .= $device['ignore'] ? '*Ignored*' : '';
$status .= $device['disabled'] ? '*Disabled*' : '';
return $this->respond($device['os'].' '.$device['version'].' '.$device['features'].' '.$status);
}//end _device()
private function _port($params)
{
$params = explode(' ', $params);
$hostname = $params[0];
$ifname = $params[1];
if (!$hostname || !$ifname) {
return $this->respond('Error: Missing hostname or ifname.');
}
$device = dbFetchRow('SELECT * FROM `devices` WHERE `hostname` = ?', array($hostname));
$port = dbFetchRow('SELECT * FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ?) AND device_id = ?', array($ifname, $ifname, $device['device_id']));
if ($this->user['level'] < 5 && !in_array($port['port_id'], $this->user['ports']) && !in_array($device['device_id'], $this->user['devices'])) {
return $this->respond('Error: Permission denied.');
}
$bps_in = formatRates($port['ifInOctets_rate'] * 8);
$bps_out = formatRates($port['ifOutOctets_rate'] * 8);
$pps_in = format_bi($port['ifInUcastPkts_rate']);
$pps_out = format_bi($port['ifOutUcastPkts_rate']);
return $this->respond($port['ifAdminStatus'].'/'.$port['ifOperStatus'].' '.$bps_in.' > bps > '.$bps_out.' | '.$pps_in.'pps > PPS > '.$pps_out.'pps');
}//end _port()
private function _listdevices($params)
{
if ($this->user['level'] < 5) {
$tmp = dbFetchRows('SELECT `hostname` FROM `devices` WHERE `device_id` IN ('.implode(',', $this->user['devices']).')');
} else {
$tmp = dbFetchRows('SELECT `hostname` FROM `devices`');
}
foreach ($tmp as $device) {
$msg .= ', '.$device['hostname'];
}
$msg = substr($msg, 2);
$msg = $msg ? $msg : 'Nothing to show..?';
return $this->respond($msg);
}//end _listdevices()
private function _status($params)
{
$params = explode(' ', $params);
$statustype = $params[0];
if ($this->user['level'] < 5) {
$d_w = ' WHERE device_id IN ('.implode(',', $this->user['devices']).')';
$d_a = ' AND device_id IN ('.implode(',', $this->user['devices']).')';
$p_w = ' WHERE port_id IN ('.implode(',', $this->user['ports']).') OR device_id IN ('.implode(',', $this->user['devices']).')';
$p_a = ' AND (I.port_id IN ('.implode(',', $this->user['ports']).') OR I.device_id IN ('.implode(',', $this->user['devices']).'))';
}
switch ($statustype) {
case 'devices':
case 'device':
case 'dev':
$devcount = array_pop(dbFetchRow('SELECT count(*) FROM devices'.$d_w));
$devup = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE status = '1' AND `ignore` = '0'".$d_a));
$devdown = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE status = '0' AND `ignore` = '0'".$d_a));
$devign = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `ignore` = '1'".$d_a));
$devdis = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `disabled` = '1'".$d_a));
$msg = 'Devices: '.$devcount.' ('.$devup.' up, '.$devdown.' down, '.$devign.' ignored, '.$devdis.' disabled'.')';
break;
case 'ports':
case 'port':
case 'prt':
$prtcount = array_pop(dbFetchRow('SELECT count(*) FROM ports'.$p_w));
$prtup = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifOperStatus = 'up' AND I.ignore = '0' AND I.device_id = D.device_id AND D.ignore = '0'".$p_a));
$prtdown = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifOperStatus = 'down' AND I.ifAdminStatus = 'up' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'".$p_a));
$prtsht = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifAdminStatus = 'down' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'".$p_a));
$prtign = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '1' OR D.ignore = '1')".$p_a));
$prterr = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '0' OR D.ignore = '0') AND (I.ifInErrors_delta > '0' OR I.ifOutErrors_delta > '0')".$p_a));
$msg = 'Ports: '.$prtcount.' ('.$prtup.' up, '.$prtdown.' down, '.$prtign.' ignored, '.$prtsht.' shutdown'.')';
break;
case 'services':
case 'service':
case 'srv':
$srvcount = array_pop(dbFetchRow('SELECT count(service_id) FROM services'.$d_w));
$srvup = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_status = '1' AND service_ignore ='0'".$d_a));
$srvdown = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_status = '0' AND service_ignore = '0'".$d_a));
$srvign = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_ignore = '1'".$d_a));
$srvdis = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_disabled = '1'".$d_a));
$msg = 'Services: '.$srvcount.' ('.$srvup.' up, '.$srvdown.' down, '.$srvign.' ignored, '.$srvdis.' disabled'.')';
break;
default:
$msg = 'Error: STATUS requires one of the following: <devices|device|dev>|<ports|port|prt>|<services|service|src>';
break;
}//end switch
return $this->respond($msg);
}//end _status()
}//end class
+15 -19
View File
@@ -28,7 +28,8 @@ namespace LibreNMS;
use ArrayAccess;
class ObjectCache implements ArrayAccess {
class ObjectCache implements ArrayAccess
{
private $data = array();
@@ -39,13 +40,13 @@ class ObjectCache implements ArrayAccess {
* Initialize ObjectCache
* @param string $obj Name of Object
*/
public function __construct($obj) {
public function __construct($obj)
{
global $config;
$this->obj = $obj;
if (isset($GLOBALS['_ObjCache'][$obj])) {
$this->data = $GLOBALS['_ObjCacheSkell'][$obj];
}
else {
} else {
if (!is_array($GLOBALS['_ObjCacheSkell'])) {
$GLOBALS['_ObjCacheSkell'] = array();
}
@@ -64,7 +65,6 @@ class ObjectCache implements ArrayAccess {
}
}
}//end if
}//end __construct()
@@ -73,13 +73,13 @@ class ObjectCache implements ArrayAccess {
* @param string $obj Name of Data-Object
* @return boolean
*/
public function offsetExists($obj) {
public function offsetExists($obj)
{
if (isset($this->data[$obj])) {
return true;
}
return false;
}//end offsetExists()
@@ -88,15 +88,14 @@ class ObjectCache implements ArrayAccess {
* @param string $obj Name of Data-Object
* @return mixed
*/
public function offsetGet($obj) {
public function offsetGet($obj)
{
if (isset($this->data[$obj])) {
if (isset($this->data[$obj]['value'])) {
return $this->data[$obj]['value'];
}
else if (isset($GLOBALS['_ObjCache'][$this->obj][$obj]['value'])) {
} elseif (isset($GLOBALS['_ObjCache'][$this->obj][$obj]['value'])) {
return $GLOBALS['_ObjCache'][$this->obj][$obj]['value'];
}
else {
} else {
$GLOBALS['_ObjCache'][$this->obj][$obj]['value'] = dbFetchRows($this->data[$obj]['query'], $this->data[$obj]['params']);
if (sizeof($GLOBALS['_ObjCache'][$this->obj][$obj]['value']) == 1 && sizeof($GLOBALS['_ObjCache'][$this->obj][$obj]['value'][0]) == 1) {
$GLOBALS['_ObjCache'][$this->obj][$obj]['value'] = current($GLOBALS['_ObjCache'][$this->obj][$obj]['value'][0]);
@@ -104,7 +103,6 @@ class ObjectCache implements ArrayAccess {
return $GLOBALS['_ObjCache'][$this->obj][$obj]['value'];
}
}
}//end offsetGet()
@@ -114,14 +112,14 @@ class ObjectCache implements ArrayAccess {
* @param mixed $value Value
* @return boolean
*/
public function offsetSet($obj, $value) {
public function offsetSet($obj, $value)
{
if (!is_array($this->data[$obj])) {
$this->data[$obj] = array();
}
$this->data[$obj]['value'] = $value;
return $this->data[$obj]['value'];
}//end offsetSet()
@@ -130,11 +128,9 @@ class ObjectCache implements ArrayAccess {
* @param string $obj Name of Data-Object
* @return mixed
*/
public function offsetUnset($obj) {
public function offsetUnset($obj)
{
unset($this->data[$obj]['value']);
return true;
}//end offsetUnset()
}//end class
+237
View File
@@ -0,0 +1,237 @@
<?php
/**
* Proc.php
*
* Executes a process with proc_open() and guarantees it is terminated on exit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2016 Tony Murray
* @author Tony Murray <[email protected]>
*/
namespace LibreNMS;
use Exception;
class Proc
{
/**
* @var resource the process this object is responsible for
*/
private $_process;
/**
* @var array array of process pipes [stdin,stdout,stderr]
*/
private $_pipes;
/**
* @var bool if this process is synchronous (waits for output)
*/
private $_synchronous;
/**
* Create and run a new process
* Most arguments match proc_open()
*
* @param string $cmd the command to execute
* @param array $descriptorspec the definition of pipes to initialize
* @param null $cwd working directory to change to
* @param array|null $env array of environment variables to set
* @param bool $blocking set the output pipes to blocking (default: false)
* @throws Exception the command was unable to execute
*/
public function __construct($cmd, $descriptorspec, $cwd = null, $env = null, $blocking = false)
{
$this->_process = proc_open($cmd, $descriptorspec, $this->_pipes, $cwd, $env);
if (!is_resource($this->_process)) {
throw new Exception("Command failed: $cmd");
}
stream_set_blocking($this->_pipes[1], $blocking);
stream_set_blocking($this->_pipes[2], $blocking);
$this->_synchronous = true;
}
/**
* Called when this object goes out of scope or php exits
* If it is still running, terminate the process
*/
public function __destruct()
{
if ($this->isRunning()) {
$this->terminate();
}
}
/**
* Get one of the pipes
* 0 - stdin
* 1 - stdout
* 2 - stderr
*
* @param int $nr pipe number (0-2)
* @return resource the pipe handle
*/
public function pipe($nr)
{
return $this->_pipes[$nr];
}
/**
* Send a command to this process and return the output
* the output may not correspond to this command if this
* process is not synchronous
* If the command isn't terminated with a newline, add one
*
* @param $command
* @return array
*/
public function sendCommand($command)
{
if (!ends_with($command, PHP_EOL)) {
$command .= PHP_EOL;
}
$this->sendInput($command);
return $this->getOutput();
}
/**
* Send data to stdin
*
* @param string $data the string to send
*/
public function sendInput($data)
{
fwrite($this->_pipes[0], $data);
}
/**
* Gets the current output of the process
* If this process is set to synchronous, wait for output
*
* @param int $timeout time to wait for output, only applies if this process is synchronous
* @return array [stdout, stderr]
*/
public function getOutput($timeout = 15)
{
if ($this->_synchronous) {
$pipes = array($this->_pipes[1], $this->_pipes[2]);
$w = null;
$x = null;
stream_select($pipes, $w, $x, $timeout);
}
return array(stream_get_contents($this->_pipes[1]), stream_get_contents($this->_pipes[2]));
}
/**
* Attempt to gracefully close this process
* optionally send one last piece of input
* such as a quit command
*
* @param string $cmd the final command to send
* @return int the exit status of this process (-1 means error)
*/
public function close($cmd = null)
{
if (isset($cmd)) {
$this->sendInput($cmd);
}
fclose($this->_pipes[0]);
fclose($this->_pipes[1]);
fclose($this->_pipes[2]);
return proc_close($this->_process);
}
/**
* Forcibly close this process
* Please attempt to run close() instead of this
* This will be called when this object is destroyed if the process is still running
*
* @param int $signal the signal to send
* @throws Exception
*/
public function terminate($signal = 15)
{
$status = $this->getStatus();
fclose($this->_pipes[1]);
fclose($this->_pipes[2]);
$closed = proc_terminate($this->_process, $signal);
if (!$closed) {
// try harder
$pid = $status['pid'];
$killed = posix_kill($pid, 9); //9 is the SIGKILL signal
proc_close($this->_process);
if (!$killed) {
throw new Exception("Terminate failed!");
}
}
}
/**
* Get the status of this process
* see proc_get_status()
*
* @return array status array
*/
public function getStatus()
{
return proc_get_status($this->_process);
}
/**
* Check if this process is running
*
* @return bool
*/
public function isRunning()
{
if (!is_resource($this->_process)) {
return false;
}
$st = $this->getStatus();
return isset($st['running']);
}
/**
* If this process waits for output
* @return boolean
*/
public function isSynchronous()
{
return $this->_synchronous;
}
/**
* Set this process as synchronous, by default processes are synchronous
* It is advisable not to change this mid way as output could get mixed up
* or you could end up blocking until the getOutput timeout expires
*
* @param boolean $synchronous
*/
public function setSynchronous($synchronous)
{
$this->_synchronous = $synchronous;
}
}
+4 -2
View File
@@ -31,9 +31,11 @@ namespace LibreNMS;
* @method boolean isDir()
*
**/
class RRDRecursiveFilterIterator extends \RecursiveFilterIterator {
class RRDRecursiveFilterIterator extends \RecursiveFilterIterator
{
public function accept() {
public function accept()
{
$filename = $this->current()->getFilename();
if ($filename[0] === '.') {
// Ignore hidden files and directories
+7 -8
View File
@@ -45,12 +45,12 @@ if (isset($options['f']) && $options['f'] == 0) {
}
$port_assoc_mode = $config['default_port_association_mode'];
$valid_assoc_modes = get_port_assoc_modes ();
if (isset ($options['p'])) {
$valid_assoc_modes = get_port_assoc_modes();
if (isset($options['p'])) {
$port_assoc_mode = $options['p'];
if (! in_array ($port_assoc_mode, $valid_assoc_modes)) {
if (! in_array($port_assoc_mode, $valid_assoc_modes)) {
echo "Invalid port association mode '" . $port_assoc_mode . "'\n";
echo 'Valid modes: ' . join (', ', $valid_assoc_modes) . "\n";
echo 'Valid modes: ' . join(', ', $valid_assoc_modes) . "\n";
exit(1);
}
@@ -178,14 +178,13 @@ if (!empty($argv[1])) {
echo " $reason\n";
}
exit(2);
} catch (Exception $e){
} catch (Exception $e) {
print_error($e->getMessage());
exit(3);
}
} else {
c_echo(
"\n".$config['project_name_version'].' Add Host Tool
"\n".$config['project_name_version'].' Add Host Tool
Usage (SNMPv1/2c): ./addhost.php [-g <poller group>] [-f] [-p <port assoc mode>] <%Whostname%n> [community] [v1|v2c] [port] ['.implode('|', $config['snmp']['transports']).']
Usage (SNMPv3) : Config Defaults : ./addhost.php [-g <poller group>] [-f] [-p <port assoc mode>] <%Whostname%n> any v3 [user] [port] ['.implode('|', $config['snmp']['transports']).']
@@ -198,7 +197,7 @@ if (!empty($argv[1])) {
-p <port assoc mode> allow you to set a port association mode for this device. By default ports are associated by \'ifIndex\'.
For Linux/Unix based devices \'ifName\' or \'ifDescr\' might be useful for a stable iface mapping.
The default for this installation is \'' . $config['default_port_association_mode'] . '\'
Valid port assoc modes are: ' . join (', ', $valid_assoc_modes) . '
Valid port assoc modes are: ' . join(', ', $valid_assoc_modes) . '
%rRemember to run discovery for the host afterwards.%n
'
+4 -8
View File
@@ -22,8 +22,7 @@ require 'includes/functions.php';
if (file_exists('html/includes/authentication/'.$config['auth_mechanism'].'.inc.php')) {
include 'html/includes/authentication/'.$config['auth_mechanism'].'.inc.php';
}
else {
} else {
echo "ERROR: no valid auth_mechanism defined.\n";
exit();
}
@@ -34,15 +33,12 @@ if (auth_usermanagement()) {
if (adduser($argv[1], $argv[2], $argv[3], @$argv[4])) {
echo 'User '.$argv[1]." added successfully\n";
}
}
else {
} else {
echo 'User '.$argv[1]." already exists!\n";
}
}
else {
} else {
echo "Add User Tool\nUsage: ./adduser.php <username> <password> <level 1-10> [email]\n";
}
}
else {
} else {
echo "Auth module does not allow adding users!\n";
}//end if
+49 -72
View File
@@ -41,8 +41,7 @@ if (file_exists($config['install_dir'].'/.alerts.lock')) {
if ($lock === true) {
exit(1);
}
else {
} else {
file_put_contents($config['install_dir'].'/.alerts.lock', getmypid());
}
@@ -57,8 +56,7 @@ if (isset($options['d'])) {
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
}
else {
} else {
$debug = false;
// ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
@@ -86,7 +84,8 @@ unlink($config['install_dir'].'/.alerts.lock');
* @param integer $rule Rule-ID
* @return boolean
*/
function IsRuleValid($device, $rule) {
function IsRuleValid($device, $rule)
{
global $rulescache;
if (empty($rulescache[$device]) || !isset($rulescache[$device])) {
foreach (GetRules($device) as $chk) {
@@ -99,7 +98,6 @@ function IsRuleValid($device, $rule) {
}
return false;
}//end IsRuleValid()
@@ -108,7 +106,8 @@ function IsRuleValid($device, $rule) {
* @param array $alert
* @return boolean
*/
function IssueAlert($alert) {
function IssueAlert($alert)
{
global $config;
if (dbFetchCell('SELECT attrib_value FROM devices_attribs WHERE attrib_type = "disable_notify" && device_id = ?', array($alert['device_id'])) == '1') {
return true;
@@ -129,7 +128,6 @@ function IssueAlert($alert) {
}
return true;
}//end IssueAlert()
@@ -137,7 +135,8 @@ function IssueAlert($alert) {
* Issue ACK notification
* @return void
*/
function RunAcks() {
function RunAcks()
{
foreach (dbFetchRows('SELECT alerts.device_id, alerts.rule_id, alerts.state FROM alerts WHERE alerts.state = 2 && alerts.open = 1') as $alert) {
$tmp = array(
$alert['rule_id'],
@@ -156,7 +155,6 @@ function RunAcks() {
IssueAlert($alert);
dbUpdate(array('open' => 0), 'alerts', 'rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id']));
}
}//end RunAcks()
@@ -164,7 +162,8 @@ function RunAcks() {
* Run Follow-Up alerts
* @return void
*/
function RunFollowUp() {
function RunFollowUp()
{
global $config;
foreach (dbFetchRows('SELECT alerts.device_id, alerts.rule_id, alerts.state FROM alerts WHERE alerts.state != 2 && alerts.state > 0 && alerts.open = 0') as $alert) {
$tmp = array(
@@ -193,12 +192,11 @@ function RunFollowUp() {
if ($n > $o) {
$ret .= ' Worsens';
$state = 3;
$alert['details']['diff'] = array_diff($chk,$alert['details']['rule']);
}
elseif ($n < $o) {
$alert['details']['diff'] = array_diff($chk, $alert['details']['rule']);
} elseif ($n < $o) {
$ret .= ' Betters';
$state = 4;
$alert['details']['diff'] = array_diff($alert['details']['rule'],$chk);
$alert['details']['diff'] = array_diff($alert['details']['rule'], $chk);
}
if ($state > 0 && $n > 0) {
@@ -210,7 +208,6 @@ function RunFollowUp() {
echo $ret.' ('.$o.'/'.$n.")\r\n";
}
}//end foreach
}//end RunFollowUp()
@@ -218,7 +215,8 @@ function RunFollowUp() {
* Run all alerts
* @return void
*/
function RunAlerts() {
function RunAlerts()
{
global $config;
foreach (dbFetchRows('SELECT alerts.device_id, alerts.rule_id, alerts.state FROM alerts WHERE alerts.state != 2 && alerts.open = 1') as $alert) {
$tmp = array(
@@ -248,8 +246,7 @@ function RunAlerts() {
if (!empty($rextra['delay'])) {
if ((time() - strtotime($alert['time_logged']) + $config['alert']['tolerance_window']) < $rextra['delay'] || (!empty($alert['details']['delay']) && (time() - $alert['details']['delay'] + $config['alert']['tolerance_window']) < $rextra['delay'])) {
continue;
}
else {
} else {
$alert['details']['delay'] = time();
$updet = true;
}
@@ -263,8 +260,7 @@ function RunAlerts() {
$updet = true;
$noiss = false;
}
}
else {
} else {
// This is the new way
if (!empty($rextra['delay']) && (time() - strtotime($alert['time_logged']) + $config['alert']['tolerance_window']) < $rextra['delay']) {
continue;
@@ -273,8 +269,7 @@ function RunAlerts() {
if (!empty($rextra['interval'])) {
if (!empty($alert['details']['interval']) && (time() - $alert['details']['interval'] + $config['alert']['tolerance_window']) < $rextra['interval']) {
continue;
}
else {
} else {
$alert['details']['interval'] = time();
$updet = true;
}
@@ -318,7 +313,6 @@ function RunAlerts() {
dbUpdate(array('open' => 0), 'alerts', 'rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id']));
}
}//end foreach
}//end RunAlerts()
@@ -327,7 +321,8 @@ function RunAlerts() {
* @param array $obj Alert-Array
* @return void
*/
function ExtTransports($obj) {
function ExtTransports($obj)
{
global $config;
$tmp = false;
// To keep scrutinizer from naging because it doesnt understand eval
@@ -348,12 +343,10 @@ function ExtTransports($obj) {
if ($tmp === true) {
echo 'OK';
log_event('Issued '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id']);
}
elseif ($tmp === false) {
} elseif ($tmp === false) {
echo 'ERROR';
log_event('Could not issue '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id']);
}
else {
} else {
echo 'ERROR: '.$tmp."\r\n";
log_event('Could not issue '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."' Error: ".$tmp, $obj['device_id']);
}
@@ -361,7 +354,6 @@ function ExtTransports($obj) {
echo '; ';
}
}//end ExtTransports()
@@ -370,7 +362,8 @@ function ExtTransports($obj) {
* @param array $obj Alert-Array
* @return string
*/
function FormatAlertTpl($obj) {
function FormatAlertTpl($obj)
{
$tpl = $obj["template"];
$msg = '$ret .= "'.str_replace(array('{else}', '{/if}', '{/foreach}'), array('"; } else { $ret .= "', '"; } $ret .= "', '"; } $ret .= "'), addslashes($tpl)).'";';
$parsed = $msg;
@@ -381,23 +374,19 @@ function FormatAlertTpl($obj) {
while (++$x < $s) {
if ($msg[$x] == '{' && $buff == '') {
$buff .= $msg[$x];
}
elseif ($buff == '{ ') {
} elseif ($buff == '{ ') {
$buff = '';
}
elseif ($buff != '') {
} elseif ($buff != '') {
$buff .= $msg[$x];
}
if ($buff == '{if') {
$pos = $x;
$if = true;
}
elseif ($buff == '{foreach') {
} elseif ($buff == '{foreach') {
$pos = $x;
$for = true;
}
elseif ($buff == '{calc') {
} elseif ($buff == '{calc') {
$pos = $x;
$calc = true;
}
@@ -413,24 +402,21 @@ function FormatAlertTpl($obj) {
'"; if( ',
' ) { $ret .= "',
);
}
elseif ($for) {
} elseif ($for) {
$for = false;
$o = 8;
$native = array(
'"; foreach( ',
' as $key=>$value) { $ret .= "',
);
}
elseif ($calc) {
} elseif ($calc) {
$calc = false;
$o = 5;
$native = array(
'"; $ret .= (float) (0+(',
')); $ret .= "',
);
}
else {
} else {
continue;
}
@@ -443,7 +429,6 @@ function FormatAlertTpl($obj) {
$parsed = populate($parsed);
return RunJail($parsed, $obj);
}//end FormatAlertTpl()
@@ -452,7 +437,8 @@ function FormatAlertTpl($obj) {
* @param array $alert Alert-Result from DB
* @return array
*/
function DescribeAlert($alert) {
function DescribeAlert($alert)
{
$obj = array();
$i = 0;
$device = dbFetchRow('SELECT hostname, sysName, location, uptime FROM devices WHERE device_id = ?', array($alert['device_id']));
@@ -472,17 +458,14 @@ function DescribeAlert($alert) {
if ($alert['state'] >= 1) {
if (!empty($tpl['title'])) {
$obj['title'] = $tpl['title'];
}
else {
} else {
$obj['title'] = 'Alert for device '.$device['hostname'].' - '.($alert['name'] ? $alert['name'] : $alert['rule']);
}
if ($alert['state'] == 2) {
$obj['title'] .= ' got acknowledged';
}
elseif ($alert['state'] == 3) {
} elseif ($alert['state'] == 3) {
$obj['title'] .= ' got worse';
}
elseif ($alert['state'] == 4) {
} elseif ($alert['state'] == 4) {
$obj['title'] .= ' got better';
}
@@ -496,11 +479,10 @@ function DescribeAlert($alert) {
}
}
$obj['elapsed'] = TimeFormat(time() - strtotime($alert['time_logged']));
if( !empty($extra['diff']) ) {
if (!empty($extra['diff'])) {
$obj['diff'] = $extra['diff'];
}
}
elseif ($alert['state'] == 0) {
} elseif ($alert['state'] == 0) {
$id = dbFetchRow('SELECT alert_log.id,alert_log.time_logged,alert_log.details FROM alert_log WHERE alert_log.state != 2 && alert_log.state != 0 && alert_log.rule_id = ? && alert_log.device_id = ? && alert_log.id < ? ORDER BY id DESC LIMIT 1', array($alert['rule_id'], $alert['device_id'], $alert['id']));
if (empty($id['id'])) {
return false;
@@ -509,15 +491,13 @@ function DescribeAlert($alert) {
$extra = json_decode(gzuncompress($id['details']), true);
if (!empty($tpl['title_rec'])) {
$obj['title'] = $tpl['title_rec'];
}
else {
} else {
$obj['title'] = 'Device '.$device['hostname'].' recovered from '.($alert['name'] ? $alert['name'] : $alert['rule']);
}
$obj['elapsed'] = TimeFormat(strtotime($alert['time_logged']) - strtotime($id['time_logged']));
$obj['id'] = $id['id'];
$obj['faults'] = false;
}
else {
} else {
return 'Unknown State';
}//end if
$obj['uid'] = $alert['id'];
@@ -527,11 +507,10 @@ function DescribeAlert($alert) {
$obj['timestamp'] = $alert['time_logged'];
$obj['contacts'] = $extra['contacts'];
$obj['state'] = $alert['state'];
if (strstr($obj['title'],'%')) {
if (strstr($obj['title'], '%')) {
$obj['title'] = RunJail('$ret = "'.populate(addslashes($obj['title'])).'";', $obj);
}
return $obj;
}//end DescribeAlert()
@@ -540,7 +519,8 @@ function DescribeAlert($alert) {
* @param integer $secs Seconds elapsed
* @return string
*/
function TimeFormat($secs) {
function TimeFormat($secs)
{
$bit = array(
'y' => $secs / 31556926 % 12,
'w' => $secs / 604800 % 52,
@@ -561,7 +541,6 @@ function TimeFormat($secs) {
}
return join(' ', $ret);
}//end TimeFormat()
@@ -571,11 +550,11 @@ function TimeFormat($secs) {
* @param array $obj Object with variables
* @return string|mixed
*/
function RunJail($code, $obj) {
function RunJail($code, $obj)
{
$ret = '';
eval($code);
return $ret;
}//end RunJail()
@@ -585,21 +564,20 @@ function RunJail($code, $obj) {
* @param boolean $wrap Wrap variable for text-usage (default: true)
* @return string
*/
function populate($txt, $wrap=true) {
function populate($txt, $wrap = true)
{
preg_match_all('/%([\w\.]+)/', $txt, $m);
foreach ($m[1] as $tmp) {
$orig = $tmp;
$rep = false;
if ($tmp == 'key' || $tmp == 'value') {
$rep = '$'.$tmp;
}
else {
} else {
if (strstr($tmp, '.')) {
$tmp = explode('.', $tmp, 2);
$pre = '$'.$tmp[0];
$tmp = $tmp[1];
}
else {
} else {
$pre = '$obj';
}
@@ -613,5 +591,4 @@ function populate($txt, $wrap=true) {
}//end foreach
return $txt;
}//end populate()
+2 -4
View File
@@ -60,8 +60,7 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
$overuse = ($used - $allowed);
$overuse = (($overuse <= 0) ? '0' : $overuse);
$percent = round((($rate_data['rate_95th'] / $bill['bill_cdr']) * 100), 2);
}
else if ($bill['bill_type'] == 'quota') {
} elseif ($bill['bill_type'] == 'quota') {
$type = 'Quota';
$allowed = $bill['bill_quota'];
$used = $rate_data['total_data'];
@@ -113,8 +112,7 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
dbUpdate($update, 'bill_history', '`bill_hist_id` = ?', array($check['bill_hist_id']));
echo ' Updated history! ';
}
else {
} else {
$update = array(
'rate_95th' => $rate_data['rate_95th'],
'rate_95th_in' => $rate_data['rate_95th_in'],
+2 -3
View File
@@ -29,12 +29,11 @@ if ($select === false) {
$limit = 0;
while (!feof($sql_fh)) {
$line = fgetss($sql_fh);
if (isset($_SESSION['stage']) ) {
if (isset($_SESSION['stage'])) {
$limit++;
if (isset($_SESSION['offset']) && $limit < $_REQUEST['offset']) {
continue;
}
elseif ( time()-$_SESSION['last'] > 45 ) {
} elseif (time()-$_SESSION['last'] > 45) {
$_SESSION['offset'] = $limit;
$GLOBALS['refresh'] = '<b>Installing, please wait..</b><sub>'.date('r').'</sub><script>window.location.href = "install.php?offset='.$limit.'";</script>';
return;
+1 -2
View File
@@ -51,6 +51,5 @@ rrdtool_initialize();
foreach (dbFetchRows('SELECT * FROM `devices` AS D, `services` AS S WHERE S.device_id = D.device_id ORDER by D.device_id DESC') as $service) {
// Run the polling function
poll_service($service);
} //end foreach
rrdtool_terminate();
rrdtool_close();
+7 -3
View File
@@ -1,5 +1,9 @@
{
"require": {
"squizlabs/php_codesniffer": "*"
}
"require-dev": {
"squizlabs/php_codesniffer": "*",
"phpunit/phpunit": "4.*",
"jakub-onderka/php-parallel-lint": "*",
"jakub-onderka/php-console-highlighter": "*",
"fojuth/readmegen": "1.*"
}
}
+7 -12
View File
@@ -9,21 +9,13 @@ $config['db_pass'] = 'PASSWORD';
$config['db_name'] = 'librenms';
$config['db']['extension'] = 'mysqli';// mysql or mysqli
### Memcached config - We use this to store realtime usage
$config['memcached']['enable'] = FALSE;
$config['memcached']['host'] = 'localhost';
$config['memcached']['port'] = 11211;
// This is the user LibreNMS will run as
//Please ensure this user is created and has the correct permissions to your install
$config['user'] = 'librenms';
### Locations - it is recommended to keep the default
#$config['install_dir'] = "/opt/librenms";
### This should *only* be set if you want to *force* a particular hostname/port
### It will prevent the web interface being usable form any other hostname
#$config['base_url'] = "http://librenms.company.com";
$config['base_url'] = "/";
### Enable this to use rrdcached. Be sure rrd_dir is within the rrdcached dir
### and that your web server has permission to talk to rrdcached.
@@ -41,9 +33,6 @@ $config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth
#$config['nets'][] = "172.16.0.0/12";
#$config['nets'][] = "192.168.0.0/16";
# following is necessary for poller-wrapper
# poller-wrapper is released public domain
$config['poller-wrapper']['alerter'] = FALSE;
# Uncomment the next line to disable daily updates
#$config['update'] = 0;
@@ -55,3 +44,9 @@ $config['rrd_purge'] = 0;
# Set default port association mode for new devices (default: ifIndex)
#$config['default_port_association_mode'] = 'ifIndex';
# Enable the in-built billing extension
$config['enable_billing'] = 1;
# Enable the in-built services support (Nagios plugins)
$config['show_services'] = 1;
+3 -4
View File
@@ -12,14 +12,13 @@ $config_file = 'config.php';
// move to install dir
chdir(dirname($argv[0]));
function iscli() {
function iscli()
{
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
return true;
}
else {
} else {
return false;
}
}
// check if we are running through the CLI, otherwise abort
+4 -6
View File
@@ -24,8 +24,7 @@ if ($options['f'] === 'update') {
if ($config['update_channel'] == 'master') {
exit(1);
}
elseif ($config['update_channel'] == 'release') {
} elseif ($config['update_channel'] == 'release') {
exit(3);
}
exit(0);
@@ -54,8 +53,7 @@ if ($options['f'] === 'syslog') {
if (dbDelete('syslog', 'seq >= ? AND seq < ? AND timestamp < DATE_SUB(NOW(), INTERVAL ? DAY)', array($rows, $limit, $config['syslog_purge'])) > 0) {
$rows = $limit;
echo 'Syslog cleared for entries over '.$config['syslog_purge']." days 1000 limit\n";
}
else {
} else {
break;
}
}
@@ -145,8 +143,8 @@ if ($options['f'] === 'purgeusers') {
foreach (dbFetchRows("SELECT DISTINCT(`user`) FROM `authlog` WHERE `datetime` >= DATE_SUB(NOW(), INTERVAL ? DAY)", array($purge)) as $user) {
$users[] = $user['user'];
}
$del_users = '"'.implode('","',$users).'"';
if (dbDelete('users', "username NOT IN ($del_users)",array($del_users))) {
$del_users = '"'.implode('","', $users).'"';
if (dbDelete('users', "username NOT IN ($del_users)", array($del_users))) {
echo "Removed users that haven't logged in for $purge days";
}
}
+2 -4
View File
@@ -25,11 +25,9 @@ if ($argv[1]) {
$id = getidbyname($host);
if ($id) {
echo delete_device($id)."\n";
}
else {
} else {
echo "Host doesn't exist!\n";
}
}
else {
} else {
echo "Host Removal Tool\nUsage: ./delhost.php <hostname>\n";
}
+8 -14
View File
@@ -23,7 +23,7 @@ require 'includes/discovery/functions.inc.php';
$start = microtime(true);
$runtime_stats = array();
$sqlparams = array();
$options = getopt('h:m:i:n:d::v::a::q',array('os:','type:'));
$options = getopt('h:m:i:n:d::v::a::q', array('os:','type:'));
if (!isset($options['q'])) {
echo $config['project_name_version']." Discovery\n";
@@ -42,25 +42,20 @@ if (isset($options['h'])) {
if ($options['h'] == 'odd') {
$options['n'] = '1';
$options['i'] = '2';
}
else if ($options['h'] == 'even') {
} elseif ($options['h'] == 'even') {
$options['n'] = '0';
$options['i'] = '2';
}
else if ($options['h'] == 'all') {
} elseif ($options['h'] == 'all') {
$where = ' ';
$doing = 'all';
}
else if ($options['h'] == 'new') {
} elseif ($options['h'] == 'new') {
$where = 'AND `last_discovered` IS NULL';
$doing = 'new';
}
else if ($options['h']) {
} elseif ($options['h']) {
if (is_numeric($options['h'])) {
$where = "AND `device_id` = '".$options['h']."'";
$doing = $options['h'];
}
else {
} else {
$where = "AND `hostname` LIKE '".str_replace('*', '%', mres($options['h']))."'";
$doing = $options['h'];
}
@@ -92,8 +87,7 @@ if (isset($options['d']) || isset($options['v'])) {
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
}
else {
} else {
$debug = false;
// ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
@@ -129,7 +123,7 @@ if (!empty($config['distributed_poller_group'])) {
$where .= ' AND poller_group IN('.$config['distributed_poller_group'].')';
}
foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC",$sqlparams) as $device) {
foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC", $sqlparams) as $device) {
discover_device($device, $options);
}
+5 -11
View File
@@ -21,7 +21,6 @@ require 'includes/definitions.inc.php';
require 'includes/functions.php';
require 'includes/polling/functions.inc.php';
require 'includes/alerts.inc.php';
require 'includes/console_table.php';
$options = getopt('l:u:r::');
@@ -34,8 +33,7 @@ if (isset($options['l'])) {
}
echo $tbl->getTable();
}
else if ($options['l'] == 'groups') {
} elseif ($options['l'] == 'groups') {
$tbl = new Console_Table();
$tbl->setHeaders(array('ID', 'Group Name', 'Description'));
foreach (dbFetchRows('SELECT * FROM `poller_groups`') as $groups) {
@@ -44,25 +42,21 @@ if (isset($options['l'])) {
echo $tbl->getTable();
}
}
else if (isset($options['u']) && !empty($options['u'])) {
} elseif (isset($options['u']) && !empty($options['u'])) {
if (is_numeric($options['u'])) {
$db_column = 'id';
}
else {
} else {
$db_column = 'poller_name';
}
if (dbDelete('pollers', "`$db_column` = ?", array($options['u'])) >= 0) {
echo 'Poller '.$options['u']." has been removed\n";
}
}
else if (isset($options['r'])) {
} elseif (isset($options['r'])) {
if (dbInsert(array('poller_name' => $config['distributed_poller_name'], 'last_polled' => '0000-00-00 00:00:00', 'devices' => 0, 'time_taken' => 0), 'pollers') >= 0) {
echo 'Poller '.$config['distributed_poller_name']." has been registered\n";
}
}
else {
} else {
echo "-l pollers | groups List registered pollers or poller groups\n";
echo "-u <id> | <poller name> Unregister a poller\n";
echo "-r Register this install as a poller\n";
+123 -49
View File
@@ -52,6 +52,10 @@ source: API/API-Docs.md
- [`get_bill`](#api-route-23)
- [`resources`](#api-resources)
- [`list_arp`](#api-resources-list_arp)
- [`services`](#api-services)
- [`list_services`](#api-services-list_services)
- [`get_service_for_host`](#api-services-get_service_for_host)
Describes the API structure.
# <a name="api-structure">`Structure`</a> [`top`](#top)
@@ -786,56 +790,19 @@ Output:
```text
[
{
"status": "error",
"message": "Found 1 in group LinuxServers",
"count": 1,
"status": "ok",
"message": "Found 3 in group LinuxServers",
"count": 3,
"devices": [
{
"device_id": "1",
"hostname": "localhost",
"sysName": "hostname",
"community": "librenms",
"authlevel": null,
"authname": null,
"authpass": null,
"authalgo": null,
"cryptopass": null,
"cryptoalgo": null,
"snmpver": "v2c",
"port": "161",
"transport": "udp",
"timeout": null,
"retries": null,
"bgpLocalAs": null,
"sysObjectID": ".1.3.6.1.4.1.8072.3.2.10",
"sysDescr": "Linux li1045-133.members.linode.com 4.1.5-x86_64-linode61 #7 SMP Mon Aug 24 13:46:31 EDT 2015 x86_64",
"sysContact": "",
"version": "4.1.5-x86_64-linode61",
"hardware": "Generic x86 64-bit",
"features": "CentOS 7.1.1503",
"location": "",
"os": "linux",
"status": "1",
"status_reason": "",
"ignore": "0",
"disabled": "0",
"uptime": "4615964",
"agent_uptime": "0",
"last_polled": "2015-12-12 13:20:04",
"last_poll_attempted": null,
"last_polled_timetaken": "1.90",
"last_discovered_timetaken": "79.53",
"last_discovered": "2015-12-12 12:34:21",
"last_ping": "2015-12-12 13:20:04",
"last_ping_timetaken": "0.08",
"purpose": null,
"type": "server",
"serial": null,
"icon": null,
"poller_group": "0",
"override_sysLocation": "0",
"notes": "Nope"
}
{
"device_id": "15"
},
{
"device_id": "18"
},
{
"device_id": "20"
}
]
}
]
@@ -1440,3 +1407,110 @@ Output:
]
}
```
### <a name="api-services-list_services">Function: `list_services`</a> [`top`](#top)
Retrieve all services
Route: /api/v0/services
Input:
- state: only which have a certain state (valid options are 0=Ok, 1=Warning, 2=Critical).
- type: service type, used sql LIKE to find services, so for tcp, use type=tcp for http use type=http
Example:
```curl
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services?state=2
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services?state=0&type=tcp
```
Output:
```text
{
"status": "ok",
"err-msg": "",
"count": 1,
"services": [
[
{
"service_id": "13",
"device_id": "1",
"service_ip": "demo1.yourdomian.net",
"service_type": "ntp_peer",
"service_desc": "NTP",
"service_param": "-H 192.168.1.10",
"service_ignore": "0",
"service_status": "0",
"service_changed": "1470962470",
"service_message": "NTP OK: Offset -0.000717 secs",
"service_disabled": "0",
"service_ds": "{\"offset\":\"s\"}"
}
],
[
{
"service_id": "2",
"device_id": "2",
"service_ip": "demo2.yourdomian.net",
"service_type": "esxi_hardware.py",
"service_desc": "vmware hardware",
"service_param": "-H 192.168.1.11 -U USER -P PASS -p",
"service_ignore": "0",
"service_status": "0",
"service_changed": "1471702206",
"service_message": "OK - Server: Supermicro X9SCL/X9SCM s/n: 0123456789 System BIOS: 2.2 2015-02-20",
"service_disabled": "0",
"service_ds": "{\"P2Vol_0_Processor_1_Vcore\":\"\",\"P2Vol_1_System_Board_1_-12V\":\"\",\"P2Vol_2_System_Board_1_12V\":\"\",\"P2Vol_3_System_Board_1_3.3VCC\":\"\",\"P2Vol_4_System_Board_1_5VCC\":\"\",\"P2Vol_5_System_Board_1_AVCC\":\"\",\"P2Vol_6_System_Board_1_VBAT\":\"\",\"P2Vol_7_System_Board_1_"
}
]
]
}
```
### <a name="api-services-get_service_for_host">Function: `get_service_for_host`</a> [`top`](#top)
Retrieve services for device
Route: /api/v0/services/:hostname
- id or hostname is the specific device
Input:
- state: only which have a certain state (valid options are 0=Ok, 1=Warning, 2=Critical).
- type: service type, used sql LIKE to find services, so for tcp, use type=tcp for http use type=http
Example:
```curl
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services/:hostname
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services/:hostname?state=2
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services/:hostname?state=0&type=tcp
```
Output:
```text
{
"status": "ok",
"err-msg": "",
"count": 1,
"services": [
[
{
"service_id": "2",
"device_id": "2",
"service_ip": "demo2.yourdomian.net",
"service_type": "esxi_hardware.py",
"service_desc": "vmware hardware",
"service_param": "-H 192.168.1.11 -U USER -P PASS -p",
"service_ignore": "0",
"service_status": "0",
"service_changed": "1471702206",
"service_message": "OK - Server: Supermicro X9SCL/X9SCM s/n: 0123456789 System BIOS: 2.2 2015-02-20",
"service_disabled": "0",
"service_ds": "{\"P2Vol_0_Processor_1_Vcore\":\"\",\"P2Vol_1_System_Board_1_-12V\":\"\",\"P2Vol_2_System_Board_1_12V\":\"\",\"P2Vol_3_System_Board_1_3.3VCC\":\"\",\"P2Vol_4_System_Board_1_5VCC\":\"\",\"P2Vol_5_System_Board_1_AVCC\":\"\",\"P2Vol_6_System_Board_1_VBAT\":\"\",\"P2Vol_7_System_Board_1_"
}
]
]
}
```
+28
View File
@@ -0,0 +1,28 @@
Developing/Creating-Release.md
# Creating a release
### GitHub
You can create a new release on [GitHub](https://github.com/librenms/librenms/releases/new).
Enter the tag version that month, i.e for September 2016 you would enter `201609`.
Enter a title, we usually use `August 2016 Release`
Enter a placeholder for the body, we will edit this later.
### Create changelog
We utilise [Readmegen](https://github.com/fojuth/readmegen) to automatically populate the Changelog.
Install `readmegen` using `composer`:
```bash
./composer.phar update
```
You can now create the update change log by running (201608 was our last release):
```bash
./vendor/bin/readmegen --from 201608 --release 201609
```
Now commit and push the change that has been made to `doc\General\Changelog.md`
+27
View File
@@ -0,0 +1,27 @@
Developing/Merging-Pull-Requests.md
# Merging Pull Requests
### GitHub
We will now build the monthly change log from our GitHub commits. When merging a commit, please
ensure you:
- Click the `Merge pull request` button
- Give the merge a descriptive but short title
- For the commit message prepend it with one of the following tags for the pull request to appear in the changelog:
- devices: or newdevice: For new device support.
- feature: or feat: To indicate this is a new or updated feature
- webui: or web: To indicate this is an update to the WebUI
- fix: or bugfix: To show this is a bug fix.
- refactoring: or refactor: When the changes are refactoring a large portion of code
- You can reference an issue number with `#xyz`, i.e `#1234`
- Use the `Confirm squash and merge` button to merge.
### Example commits
#### Feature
feature: Added new availability map #4401
#### New device
newdevice: Added support for Cisco ASA #4402
+7 -11
View File
@@ -80,11 +80,13 @@ pull request then commit away.
```bash
git add path/to/new/files/or/folders
git commit -a -m 'Added feature to do X, Y and Z'
git checkout master
git push origin issue-123
```
If you need to rebase against master then you can do this with:
```bash
git pull upstream master
git push origin master
git checkout issue-123
git pull origin master
git push origin issue-123
```
@@ -97,13 +99,7 @@ Now you will be ready to submit a pull request from within GitHub. To do this, g
repo. Now select the branch you have just been working on (issue-123) from the drop down to the left and then click
'Pull Request'. Fill in the details to describe the work you have done and click 'Create pull request'.
Thanks for your first pull request :) Now, that might have been a simple update, if things get a bit more complicated
then you will need to break down your pull request into separate commits (still a single pull request). This is usually
done when:
- You want to add / update MIBS. Do this in a separate commit including the link to where you got them from.
- You are adding say 3 related features in one go, try and break them down into 3 separate commits.
- Icons for new OS support need to be added as a separate commit including a link to where you got the logo from.
Thanks for your first pull request :)
Ok, that should get you started on the contributing path. If you have any other questions then stop by our IRC Channel
on Freenode ##librenms.
+28
View File
@@ -0,0 +1,28 @@
source: Developing/Validating-Code.md
As part of the pull request process with GitHub we run some automated build tests to ensure that
the code is error free, standards [compliant](http://docs.librenms.org/Developing/Code-Guidelines/)
and our test suite builds successfully.
Rather than submit a pull request and wait for the results, you can run these checks yourself to ensure
a more seamless merge.
> All of these commands should be run from within the librenms directory and can be run as the librenms user
unless otherwise noted.
Install composer (you can skip this if composer is already installed).
`curl -sS https://getcomposer.org/installer | php`
Composer will now be installed into /opt/librenms/composer.phar.
Now install the dependencies we require:
`composer install`
Once composer is installed you can now run the code validation script:
`./scripts/pre-commit.php`
If you see `Tests ok, submit away :)` then all is well. If you see other output then it should contain
what you need to resolve the issues and re-test.
+12
View File
@@ -130,6 +130,18 @@ Placeholders:
- Transport name: `%transport`
- Contacts, must be iterated in a foreach, `%key` holds email and `%value` holds name: `%contacts`
> NOTE: Placeholder names which are contained within another need to be ordered correctly. As an example:
```text
Limit: %value.sensor_limit / %value.sensor_limit_low
```
Should be done as:
```text
Limit: %value.sensor_limit_low / %value.sensor_limit
```
The Default Template is a 'one-size-fit-all'. We highly recommend defining own templates for your rules to include more specific information.
Templates can be matched against several rules.
+5 -5
View File
@@ -28,7 +28,7 @@ Different applications support a variety of ways collect data: by direct connect
##### SNMP Extend
1. Download the script onto the desired host (the host must be added to LibreNMS devices)
```
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/apache-stats.py -o /etc/snmp/apache-stats.py
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/apache-stats.py -O /etc/snmp/apache-stats.py
```
2. Make the script executable (chmod +x /etc/snmp/apache-stats.py)
3. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add:
@@ -37,7 +37,7 @@ extend apache /etc/snmp/apache-stats.py
```
4. Restart snmpd on your host
5. On the device page in Librenms, edit your host and check the `Apache` under the Applications tab.
(In some cases urlgrabber needs to be installed, in Debian it can be achieved by: apt-get install python-urlgrabber)
### BIND9 aka named
@@ -88,7 +88,7 @@ extend dhcpstats /opt/dhcp-status.sh
##### SNMP Extend
1. Download the script onto the desired host (the host must be added to LibreNMS devices)
```
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/mailscanner.php -o /etc/snmp/mailscanner.php
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/mailscanner.php -O /etc/snmp/mailscanner.php
```
2. Make the script executable (chmod +x /etc/snmp/mailscanner.php)
3. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add:
@@ -158,7 +158,7 @@ Supports NTPD Server (not client, that is separate)
##### SNMP Extend
1. Download the script onto the desired host (the host must be added to LibreNMS devices)
```
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/ntpd-server.php -o /etc/snmp/ntpd-server.php
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/ntpd-server.php -O /etc/snmp/ntpd-server.php
```
2. Make the script executable (chmod +x /etc/snmp/ntdp-server.php)
3. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add:
@@ -222,7 +222,7 @@ This script uses `rec_control get-all` to collect stats.
### Proxmox
1. Download the script onto the desired host (the host must be added to LibreNMS devices)
`wget https://github.com/librenms/librenms-agent/blob/master/agent-local/proxmox -o /usr/local/bin/proxmox`
`wget https://github.com/librenms/librenms-agent/blob/master/agent-local/proxmox -O /usr/local/bin/proxmox`
2. Make the script executable: `chmod +x /usr/local/proxmox`
3. Edit your snmpd.conf file (usually `/etc/snmp/snmpd.conf`) and add:
`extend proxmox /usr/local/bin/proxmox`
+4 -4
View File
@@ -9,12 +9,12 @@ Patterns work in the same was as Entities within the alerting system, the format
as __tablename.columnname__. If you are ensure of what the entity is you want then have a browse around inside MySQL using `show tables` and `desc <tablename>`.
As a working example and a common question, let's assume you want to group devices by hostname. If you hostname format is dcX.[devicetype].example.com. You would use the pattern
devices.hostname. Select the condition which in this case would Like and then enter `dc1\..*\.example.com`. This would then match dc1.sw01.example.com, dc1.rtr01.example.com but not
`devices.hostname`. Select the condition which in this case would be `Like` and then enter `dc1\..*\.example.com`. This would then match dc1.sw01.example.com, dc1.rtr01.example.com but not
dc2.sw01.example.com.
#### Wildcards
As with alerts, the `Like` operation allows RegExp.
As with alerts, the `Like` operation allows MySQL Regular expressions.
A list of common entities is maintained in our [Alerting docs](http://docs.librenms.org/Extensions/Alerting/#entities).
@@ -25,7 +25,7 @@ Please see our [Alerting docs](http://docs.librenms.org/Extensions/Alerting/#syn
### Connection
If you only want to group based on one pattern then select And. If however you want to build a group based on multiple patterns then you can build a SQL like
query using And / Or. As an example, we want to base our group on the devices hostname AND it's type. Use the pattern as before, devices.hostname, select the condition which in this case would Like and then enter [email protected] then click And. Now enter devices.type in the pattern, select Equals and enter firewall. This would then match dc1.fw01.example.com but not dc1.sw01.example.com as that is a network type.
query using And / Or. As an example, we want to base our group on the devices hostname AND it's type. Use the pattern as before, `devices.hostname`, select the condition which in this case would be `Like` and then enter `[email protected]` then click And. Now enter `devices.type` in the pattern, select `Equals` and enter `firewall`. This would then match dc1.fw01.example.com but not dc1.sw01.example.com as that is a network type.
You can now select this group from the Devices -> All Devices link in the navigation at the top. You can also use the group to map alert rules to by creating an alert mapping
Overview -> Alerts -> Rule Mapping.
`Overview -> Alerts -> Rule Mapping`.
+6 -18
View File
@@ -1,23 +1,21 @@
source: Extensions/Globe-Frontpage.md
# Globe Frontpage Configuration
LibreNMS comes with a configurable geochart based frontpage to visualize where your gear is located geographically.
LibreNMS comes with a configurable geochart based widget to visualize where your equipment is located geographically.
### Experimental map
### World Map
An new experimental map is available, this requires you to have properly formatted addresses in sysLocation or sysLocation override. As part of the standard poller these addresses will be Geocoded by Google and stored in the database. To enable this please set the following config:
An new map is available, this requires you to have properly formatted addresses in sysLocation or sysLocation override. As part of the standard poller these addresses will be Geocoded by Google and stored in the database. To enable this please set the following config:
```php
$config['front_page'] = "pages/front/map.php";
$config['geoloc']['latlng'] = true;
$config['geoloc']['engine'] = "google";//Only one available at present
```
Location resolution happens as follows (when `$config['geoloc']['latlng'] == true;`):
1. if `device['location']` contains `[lat, lng]` (note the square brackets), that is used
1. if there is a location overide in the `locations` table where `locations.location == device['location']`, that is used
* currently, no web UI
1. attempt to resolve lat, lng using `$config['geoloc']['engine']`
1. If `device['location']` contains `[lat, lng]` (note the square brackets), that is used
1. If there is a location overide for the device in the WebUI and it contains `[lat, lng]` (note the square brackets), that is used.
1. Attempt to resolve lat, lng using `$config['geoloc']['engine']`
We have two current mapping engines available:
@@ -56,13 +54,3 @@ $config['mapael']['default_zoom'] = 20;
```
A list of maps can be found in html/js/maps/ or html/js/mapael-maps/.
### Standard Globe map
To enable it, set `$config['front_page'] = "pages/front/globe.php";` in your `config.php`.
You can use any of these config-parameters to adjust some aspects of it:
- `$config['frontpage_globe']['markers']` is used to change what is being shown on the Markers of the map. It can be either `devices` or `ports`
- `$config['frontpage_globe']['region']` defines the Region to chart. Any region supported by Google's GeoChart API is allowed (https://developers.google.com/chart/interactive/docs/gallery/geochart#continent-hierarchy-and-codes)
- `$config['frontpage_globe']['resolution']` can be 'countries', 'provinces' or 'metros' (latter two are mostly US only due to google-limits).
+3
View File
@@ -12,6 +12,9 @@ $config['memcached']['port'] = 11211;
```
By default values are kept for 4 Minutes inside the memcached, you can adjust this retention time by modifying the `$config['memcached']['ttl']` value to any desired amount of seconds.
> This means that you can see what appears to be stale data for up to 4 minutes. If you edit an alert rule for example then those changes may not show immediately.
It's strongly discouraged to set this above `300` (5 Minutes) to avoid interference with the polling, discovery and alerting processes.
If you use the Distributed Poller, you can point this to the same memcached instance. However a local memcached will perform better in any case.
+2 -2
View File
@@ -57,13 +57,13 @@ LibreNMS is able to reload the Oxidized list of nodes, each time a device is add
To do so, edit the option in Global Settings>External Settings>Oxidized Integration or add the following to your config.php.
```php
$config['oxidized']['reload_nodes'] = TRUE;
$config['oxidized']['reload_nodes'] = true;
```
#### Using Groups
To return a group to Oxidized you can do this by matching a regex for either hostname, os or location. The order is hostname is matched first, if nothing is found then os is tried and then location is attempted.
To return a group to Oxidized you can do this by matching a regex for either `hostname`, `os` or `location`. The order is `hostname` is matched first, if nothing is found then `os` is tried and then `location` is attempted.
The first match found will be used. To match on the device hostnames that contain 'lon-sw' or if the location contains 'London' then you would place the following within config.php:
```php
+2
View File
@@ -1,6 +1,8 @@
source: Extensions/Plugin-System.md
# Developing for the Plugin System
> This will most likely be deprecated in favour of adding the possible extensions to the core code base.
This documentation will hopefully give you a basis for how to write a plugin for LibreNMS.
A test plugin is available on GitHub: https://github.com/laf/Test
-2
View File
@@ -35,5 +35,3 @@ LibreNMS 3rd party acknowledgements
- html/graph-realtime.php: BSD (original?)
- html/includes/collectd/: GPLv2 only
- overLIB (html/js/overlib_mini.js): modified Artistic 1.0?
- scripts/*/mysql: GPLv2 only
- check_mk (scripts/check_mk*): GPLv2
+86
View File
@@ -1,4 +1,90 @@
source: General/Changelog.md
### August 2016
#### Bug fixes
- WebUI
- Fix Infoblox dhcp messages graph ([PR3898](https://github.com/librenms/librenms/pull/3898))
- Fix version_info output in Safari ([PR3914](https://github.com/librenms/librenms/pull/3914))
- Added missing apps to Application page ([PR3964](https://github.com/librenms/librenms/pull/3964))
- Discovery / Polling
- Clear our stale IPSEC sessions from the DB ([PR3904](https://github.com/librenms/librenms/pull/3904))
- Fixed some InfluxDB bugs in check-services and ports ([PR4031](https://github.com/librenms/librenms/pull/4031))
- Fixed Promox and Ceph rrd's ([PR4038](https://github.com/librenms/librenms/pull/4038), [PR4037](https://github.com/librenms/librenms/pull/4037), [PR4047](https://github.com/librenms/librenms/pull/4047), [PR4041](https://github.com/librenms/librenms/pull/4041))
- Fixed LLDP Remote port in discovery-protocols module ([PR4070](https://github.com/librenms/librenms/pull/4070))
- Billing
- Check if ifSpeed is returned for calculating billing ([PR3921](https://github.com/librenms/librenms/pull/3921))
- Applications
- NFS-V3 stats fixed ([PR3963](https://github.com/librenms/librenms/pull/3963))
- Misc
- Dell Equallogic storage fix ([PR3956](https://github.com/librenms/librenms/pull/3956))
- Fix syslog bug where entries would log to the wrong device ([PR3996](https://github.com/librenms/librenms/pull/3996))
#### Improvements
- Added / improved detection for:
- Cisco WAAS / WAVE ([PR3899](https://github.com/librenms/librenms/pull/3899))
- Maipu MyPower ([PR3909](https://github.com/librenms/librenms/pull/3909))
- TPLink Switches ([PR3919](https://github.com/librenms/librenms/pull/3919))
- Dell N3024 ([PR3941](https://github.com/librenms/librenms/pull/3941))
- Cisco FXOS ([PR3943](https://github.com/librenms/librenms/pull/3943))
- Brocade FABOS ([PR3959](https://github.com/librenms/librenms/pull/3959), [PR3988](https://github.com/librenms/librenms/pull/3988))
- JunOS ([PR3976](https://github.com/librenms/librenms/pull/3976))
- Dell PowerConnect ([PR3998](https://github.com/librenms/librenms/pull/3998), [PR4007](https://github.com/librenms/librenms/pull/4007))
- Comware ([PR3967](https://github.com/librenms/librenms/pull/3967))
- Calix E5 ([PR3864](https://github.com/librenms/librenms/pull/3864))
- Raisecom ([PR3992](https://github.com/librenms/librenms/pull/3864))
- Cisco ISE ([PR4063](https://github.com/librenms/librenms/pull/4063))
- Acano ([PR4064](https://github.com/librenms/librenms/pull/4064))
- McAfee SIEM Nitro ([PR4066](https://github.com/librenms/librenms/pull/4064))
- HP Bladesystem C3000/C7000 OA ([PR4035](https://github.com/librenms/librenms/pull/4035))
- Cisco VCS (Expressway) ([PR4086](https://github.com/librenms/librenms/pull/4086))
- Cisco Telepresence Conductor ([PR4087](https://github.com/librenms/librenms/pull/4087))
- Avaya VSP ([PR4048](https://github.com/librenms/librenms/pull/4048))
- Cisco/Tandberg Video Conferencing ([PR4065](https://github.com/librenms/librenms/pull/4065))
- Cisco Prime Infrastructure ([PR4088](https://github.com/librenms/librenms/pull/4088))
- HWGroup STE2 ([PR4116](https://github.com/librenms/librenms/pull/4116))
- HP 2530 Procurve / Arube ([PR4119](https://github.com/librenms/librenms/pull/4119))
- Brother Printers ([PR4141](https://github.com/librenms/librenms/pull/4141))
- Hytera Repeater ([PR4163](https://github.com/librenms/librenms/pull/4163))
- Sonus ([PR4176](https://github.com/librenms/librenms/pull/4176))
- Freeswitch ([PR4203](https://github.com/librenms/librenms/pull/4203))
- WebUI
- Improved OSPF display ([PR3908](https://github.com/librenms/librenms/pull/3908))
- Improved Apps overview page ([PR3954](https://github.com/librenms/librenms/pull/3954))
- Improved Syslog page ([PR3955](https://github.com/librenms/librenms/pull/3955), [PR3971](https://github.com/librenms/librenms/pull/3971))
- Rewrite availability map ([PR4043](https://github.com/librenms/librenms/pull/4043))
- Add predicted usage to billing overview ([PR4049](https://github.com/librenms/librenms/pull/4049))
- API
- Added services calls to API ([PR4215](https://github.com/librenms/librenms/pull/4215))
- Discovery / Polling
- Added CPU detection for Dell PowerConnect 8024F ([PR3966](https://github.com/librenms/librenms/pull/3966))
- Cisco VSS state discovery ([PR3977](https://github.com/librenms/librenms/pull/3977))
- Refactor of BGP Discovery and Polling (mainly JunOS) ([PR3938](https://github.com/librenms/librenms/pull/3938))
- Added Sensors for Brocade NOS ([PR3969](https://github.com/librenms/librenms/pull/3969))
- Cisco ASA HA States ([PR4012](https://github.com/librenms/librenms/pull/4012))
- Improved IPSLA Support ([PR4006](https://github.com/librenms/librenms/pull/4006))
- Added support for CISCO-NTP-MIB ([PR4005](https://github.com/librenms/librenms/pull/4005))
- Improved toner support for Ricoh devices ([PR4180](https://github.com/librenms/librenms/pull/4180))
- Documentation
- New doc site live http://docs.librenms.org/
- Added rsyslog 5 example to syslog docs ([PR3912](https://github.com/librenms/librenms/pull/3912))
- Application doc updates ([PR3928](https://github.com/librenms/librenms/pull/3928))
- Applications
- App OS Updates support ([PR3935](https://github.com/librenms/librenms/pull/3935))
- PowerDNS Recursor improvements ([PR3932](https://github.com/librenms/librenms/pull/3932))
- Add DHCP Stats support ([PR3970](https://github.com/librenms/librenms/pull/3970))
- Added snmp support to Memcached ([PR3949](https://github.com/librenms/librenms/pull/3949))
- Added Unbound support ([PR4074](https://github.com/librenms/librenms/pull/4074))
- Added snmp support to Proxmox ([PR4052](https://github.com/librenms/librenms/pull/4052))
- Added Raspberry Pi Sensor support ([PR4057](https://github.com/librenms/librenms/pull/4057))
- Updated NTPD support ([PR4077](https://github.com/librenms/librenms/pull/4077))
- Misc
- Added cleanup of old RRD files to daily.sh ([PR3907](https://github.com/librenms/librenms/pull/3907))
- Refactored addHost event logs ([PR3929](https://github.com/librenms/librenms/pull/3929), [PR3997](https://github.com/librenms/librenms/pull/3997))
- Refactored RRD Functions ([PR3800](https://github.com/librenms/librenms/pull/3800), [PR4081](https://github.com/librenms/librenms/pull/4081))
- Added support for nets-exclude in snmp-scan ([PR4000](https://github.com/librenms/librenms/pull/4045))
- Refactored files in html (Libraries and PSR2 style ([PR4071](https://github.com/librenms/librenms/pull/4071), [PR4101](https://github.com/librenms/librenms/pull/4101), [PR4117](https://github.com/librenms/librenms/pull/4117))
- Various IRC updates and fixes ([PR4200](https://github.com/librenms/librenms/pull/4200), [PR4204](https://github.com/librenms/librenms/pull/4204), [PR4201](https://github.com/librenms/librenms/pull/4201))
### July 2016
#### Bug fixes
+2 -4
View File
@@ -34,9 +34,9 @@ To agree with these assertions, please submit a GitHub pull request against
[AUTHORS.md][5], adding or altering a **single line** *containing your name,
email address, and GitHub user id* in the file (so that it can be matched to
your commits), and stating in the *commit log* (not the pull request text):
```
I agree to the conditions of the Contributor Agreement
contained in doc/General/Contributing.md.
I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md.
```
Local patches
@@ -61,8 +61,6 @@ the package information to the header.
```
<?php
/*
* Copyright (c) 2015 Internet Widgitz Pty Ltd <http://example.com/>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
-6
View File
@@ -50,9 +50,3 @@ Other components (needs details filled in):
- html/includes/collectd/: GPLv2 only
- overLIB (html/js/overlib_mini.js): modified Artistic 1.0?
- scripts/*/mysql: GPLv2 only
- check_mk (scripts/observium_agent*): GPLv2
- qTip (html/css/jquery.qtip.min.css and html/js/qtip/jquery.qtip.min.js): GPLv2
+16
View File
@@ -0,0 +1,16 @@
source: General/Releases.md
# LibreNMS Releases
We try to ensure that breaking changes aren't introduced by utilising various automated
code testing, syntax testing and unit testing along with manual code review. However
bugs can and do get introduced as well as major refactoring to improve the quality of
the code base.
With this in mind, we provide a monthly stable release which is released on or around
the last Sunday of the month. Code pull requests (aside from Bug fixes) are stopped days
leading up to the release to ensure that we have a clean working branch at that point.
The releases are titled after that month in the format `YYYYMM`, i.e `201608`. The
Changelog is also updated and will reference the release number and date so you can see
what changes have been made since the last release.
+3 -3
View File
@@ -4,7 +4,7 @@ source: General/Updating.md
If you would like to perform a manual update
then you can do this by running the following command as the **librenms** user:
./daily.sh
`./daily.sh`
This will update both the core LibreNMS files but also update the database
structure if updates are available.
@@ -13,12 +13,12 @@ structure if updates are available.
LibreNMS follows the master branch on github for daily updates.
You can change to the monthly releases by setting:
$config['update_channel'] = 'release';
`$config['update_channel'] = 'release';`
## Disabling automatic updates ##
LibreNMS by default performs updates on a daily basis. This can be disabled
by ensuring:
$config['update'] = 0;
`$config['update'] = 0;`
is no longer commented out.
@@ -59,8 +59,6 @@ Reasons why you might want to use LibreNMS instead of Observium:
"LibreNMS README"
[3]: http://fisheye.observium.org/rdiff/Observium?csid=3251&u&N
"Link to Observium license change"
[4]: https://github.com/librenms/librenms/blob/master/doc/General/Roadmap.md
"LibreNMS ROADMAP"
[5]: https://github.com/librenms/librenms/blob/master/LICENSE.txt
"LibreNMS copy of GPL v3"
[6]: http://www.gnu.org/philosophy/free-sw.html
@@ -145,7 +145,7 @@ systemctl enable httpd
systemctl enable mariadb
```
Now run validate your install and make sure everything is ok:
Run validate.php as root in the librenms directory:
```bash
cd /opt/librenms
@@ -162,10 +162,10 @@ We now suggest that you add localhost as your first device from within the WebUI
Now that you've installed LibreNMS, we'd suggest that you have a read of a few other docs to get you going:
- (Performance tuning)[http://docs.librenms.org/Support/Performance]
- (Alerting)[http://docs.librenms.org/Extensions/Alerting/]
- (Device Groups)[http://docs.librenms.org/Extensions/Device-Groups/]
- (Auto discovery)[http://docs.librenms.org/Extensions/Auto-Discovery/]
- [Performance tuning](http://docs.librenms.org/Support/Performance)
- [Alerting](http://docs.librenms.org/Extensions/Alerting/)
- [Device Groups](http://docs.librenms.org/Extensions/Device-Groups/)
- [Auto discovery](http://docs.librenms.org/Extensions/Auto-Discovery/)
#### Closing
@@ -156,7 +156,7 @@ systemctl enable nginx
systemctl enable mariadb
```
Now run validate your install and make sure everything is ok:
Run validate.php as root in the librenms directory:
```bash
cd /opt/librenms
@@ -173,10 +173,10 @@ We now suggest that you add localhost as your first device from within the WebUI
Now that you've installed LibreNMS, we'd suggest that you have a read of a few other docs to get you going:
- (Performance tuning)[http://docs.librenms.org/Support/Performance]
- (Alerting)[http://docs.librenms.org/Extensions/Alerting/]
- (Device Groups)[http://docs.librenms.org/Extensions/Device-Groups/]
- (Auto discovery)[http://docs.librenms.org/Extensions/Auto-Discovery/]
- [Performance tuning](http://docs.librenms.org/Support/Performance)
- [Alerting](http://docs.librenms.org/Extensions/Alerting/)
- [Device Groups](http://docs.librenms.org/Extensions/Device-Groups/)
- [Auto discovery](http://docs.librenms.org/Extensions/Auto-Discovery/)
#### Closing
@@ -105,8 +105,8 @@ Now head to: http://librenms.example.com/install.php and follow the on-screen in
#### Configure snmpd
```bash
cp /opt/librenms/snmpd.conf.example /etc/snmpd.conf
vim /etc/snmpd.conf
cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
vim /etc/snmp/snmpd.conf
```
Edit the text which says `RANDOMSTRINGGOESHERE` and set your own community string.
@@ -127,7 +127,7 @@ service snmpd restart
chown -R librenms:librenms /opt/librenms
```
Now run validate your install and make sure everything is ok:
Run validate.php as root in the librenms directory:
```bash
cd /opt/librenms
@@ -108,8 +108,8 @@ Now head to: http://librenms.example.com/install.php and follow the on-screen in
#### Configure snmpd
```bash
cp /opt/librenms/snmpd.conf.example /etc/snmpd.conf
vim /etc/snmpd.conf
cp /opt/librenms/snmpd.conf.example /etc/snmpd/snmpd.conf
vim /etc/snmpd/snmpd.conf
```
Edit the text which says `RANDOMSTRINGGOESHERE` and set your own community string.
@@ -130,7 +130,7 @@ service snmpd restart
chown -R librenms:librenms /opt/librenms
```
Now run validate your install and make sure everything is ok:
Run validate.php as root in the librenms directory:
```bash
cd /opt/librenms
+1 -1
View File
@@ -9,7 +9,7 @@ We have some pre-built VirtualBox images you can use to get started:
If you want to install yourself then we have some new documentation which should make it easy.
> Please note the following docs are new and may not be 100% complate, please provide feedback on your experience.
> Please note the following docs are new and may not be 100% complete, please provide feedback on your experience.
[Ubuntu 16.04 Apache](http://docs.librenms.org/Installation/Installation-Ubuntu-1604-Apache/)
+17 -16
View File
@@ -6,18 +6,21 @@ This document will explain how to use discovery.php to debug issues or manually
#### Command options
```bash
-h <device id> | <device hostname wildcard> Poll single device
-h odd Poll odd numbered devices (same as -i 2 -n 0)
-h even Poll even numbered devices (same as -i 2 -n 1)
-h all Poll all devices
-h new Poll all devices that have not had a discovery run before
-h odd Poll odd numbered devices (same as -i 2 -n 0)
-h even Poll even numbered devices (same as -i 2 -n 1)
-h all Poll all devices
-h new Poll all devices that have not had a discovery run before
--os <os_name> Poll devices only with specified operating system
--type <type> Poll devices only with specified type
-i <instances> -n <number> Poll as instance <number> of <instances>
Instances start at 0. 0-3 for -n 4
-i <instances> -n <number> Poll as instance <number> of <instances>
Instances start at 0. 0-3 for -n 4
Debugging and testing options:
-d Enable debugging output
-v Enable verbose debugging output
-m Specify single module to be run
Debugging and testing options:
-d Enable debugging output
-m Specify single module to be run
```
`-h` Use this to specify a device via either id or hostname (including wildcard using *). You can also specify odd and
@@ -26,15 +29,16 @@ new will poll only those devices that have recently been added or have been sele
`-i` This can be used to stagger the discovery process.
`-d` Enables debugging output (verbose output) so that you can see what is happening during a discovery run. This includes
things like rrd updates, SQL queries and response from snmp.
`-d` Enables debugging output (verbose output but with most sensitive data masked) so that you can see what is happening during a discovery run. This includes things like rrd updates, SQL queries and response from snmp.
`-v` Enables verbose debugging output with all data in tact.
`-m` This enables you to specify the module you want to run for discovery.
#### Discovery config
These are the default discovery config items. You can globally disable a module by setting it to 0. If you just want to
disable it for one device then you can do this within the WebUI -> Settings -> Modules.
disable it for one device then you can do this within the WebUI -> Device -> Settings -> Modules.
```php
$config['discovery_modules']['os'] = 1;
@@ -160,15 +164,12 @@ Multiple Modules
./discovery.php -h localhost -m ports,entity-physical -d
```
It is then advisable to sanitise the output before pasting it somewhere as the debug output will contain snmp details
amongst other items including port descriptions.
Using `-d` shouldn't output much sensitive information, `-v` will so it is then advisable to sanitise the output before pasting it somewhere as the debug output will contain snmp details amongst other items including port descriptions.
The output will contain:
DB Updates
RRD Updates
SNMP Response
### SNMP Scan
+7 -5
View File
@@ -2,7 +2,7 @@ source: Install Validation.md
Install validation
------------------
With a lot of configuration possibilities and at present the only way to do this being by manually editing config.php then it's not
With a lot of configuration possibilities, manually editing config.php means it's not
uncommon that mistakes get made. It's also impossible to validate user input in config.php when you're just using a text editor :)
So, to try and help with some of the general issues people come across we've put together a simple validation tool which at present will:
@@ -22,10 +22,12 @@ Optionally you can also pass -m and a module name for that to be tested. Current
- dist-poller - This will test your distributed poller configuration.
- rrdcheck - This will test your rrd files to see if they are unreadable or corrupted (source of broken graphs).
Output, this is color coded to try and make things a little easier:
You can run validate.php as `root` by executing `./validate.php` within your install directory.
Green OK - This is a good thing, you can skip over these :)
The output will provide you either a clean bill of health or a list of things you need to fix:
Yellow WARN - You probably want to check this out.
OK - This is a good thing, you can skip over these :)
Red FAIL - This is going to need your attention!
WARN - You probably want to check this out.
FAIL - This is going to need your attention!
+6 -4
View File
@@ -17,7 +17,9 @@ This document will explain how to use poller.php to debug issues or manually run
Debugging and testing options:
-r Do not create or update RRDs
-f Do not insert data into InfluxDB
-d Enable debugging output
-v Enable verbose debugging output
-m Specify module(s) to be run
```
@@ -28,8 +30,9 @@ even. all will run poller against all devices.
`-r` This option will suppress the creation or update of RRD files.
`-d` Enables debugging output (verbose output) so that you can see what is happening during a poller run. This includes
things like rrd updates, SQL queries and response from snmp.
`-d` Enables debugging output (verbose output but with most sensitive data masked) so that you can see what is happening during a poller run. This includes things like rrd updates, SQL queries and response from snmp.
`-v` Enables verbose debugging output with all data in tact.
`-m` This enables you to specify the module you want to run for poller.
@@ -170,8 +173,7 @@ Multiple Modules
./poller.php -h localhost -m ports,entity-physical -d
```
It is then advisable to sanitise the output before pasting it somewhere as the debug output will contain snmp details
amongst other items including port descriptions.
Using `-d` shouldn't output much sensitive information, `-v` will so it is then advisable to sanitise the output before pasting it somewhere as the debug output will contain snmp details amongst other items including port descriptions.
The output will contain:
-2
View File
@@ -105,8 +105,6 @@ Polling
At this step we should see all the values retrieved in LibreNMS.
#### FULL SUPPORT FOR A NEW OS
### MIB
+3 -4
View File
@@ -8,10 +8,9 @@ body {
overflow-x: hidden !important;
}
/* pushdown the content when the header flows to two lines */
.navbar-fixed-top {
top: -70px;
position: relative;
/* push down the content when the header flows to two lines */
.bs-sidebar {
margin-top: 45px;
}
/* hide the menu called hidden, used to generate unlinked docs */
+9
View File
@@ -154,6 +154,15 @@ $app->group(
}
);
// End Resources
// Service section
$app->group(
'/services',
function () use ($app) {
$app->get('/:hostname', 'authToken', 'list_services')->name('get_service_for_host');
}
);
$app->get('/services', 'authToken', 'list_services')->name('list_services');
// End Service
}
);
$app->get('/v0', 'authToken', 'show_endpoints');
+2 -6
View File
@@ -1881,6 +1881,7 @@ label {
padding:8px;
border-radius:5px;
text-align:center;
white-space: nowrap;
}
.device-availability.up, .service-availability.up {
@@ -1948,11 +1949,6 @@ label {
padding-left:10px;
}
.page-availability-report-service {
float:right;
text-align:right;
}
.widget-availability {
float:left;
margin:2px;
@@ -1997,4 +1993,4 @@ label {
width:12px;
float:left;
background-color: #D9534F;
}
}
+5 -2
View File
@@ -32,9 +32,9 @@ if (isset($_GET['debug'])) {
require_once '../includes/defaults.inc.php';
require_once '../config.php';
require_once '../includes/common.php';
require_once '../includes/definitions.inc.php';
require_once '../includes/common.php';
require_once '../includes/dbFacile.php';
require_once '../includes/rewrites.php';
require_once 'includes/functions.inc.php';
@@ -42,9 +42,12 @@ require_once '../includes/rrdtool.inc.php';
if ($config['allow_unauth_graphs'] != true) {
require_once 'includes/authenticate.inc.php';
}
rrdtool_initialize(false);
require 'includes/graphs/graph.inc.php';
$console_color = new Console_Color2();
rrdtool_close();
$end = microtime(true);
$run = ($end - $start);
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1005 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

+68
View File
@@ -1222,6 +1222,7 @@ function get_devices_by_group()
$message = 'No devices found in group ' . $name;
} else {
$message = "Found $count in group $name";
$status = 'ok';
$code = 200;
}
}
@@ -1299,3 +1300,70 @@ function list_arp()
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function list_services()
{
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$status = 'ok';
$code = 200;
$message = '';
$host_par = array();
$sql_param = array();
$services = array();
$where = '';
$devicewhere = '';
// Filter BY STATE
if (isset($_GET['state'])) {
$where = " AND S.service_status= ? AND S.service_disabled='0' AND S.service_ignore='0'";
$host_par[] = $_GET['state'];
if (!is_numeric($_GET['state'])) {
$status = 'error';
$message = "No valid service state provided, valid option is 0=Ok, 1=Warning, 2=Critical";
}
}
// GET BY HOST
if (isset($router['hostname'])) {
$hostname = $router['hostname'];
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$where .= " AND S.device_id = ?";
$host_par[] = $device_id;
if (!is_numeric($device_id)) {
$status = 'error';
$message = "No valid hostname or device id provided";
}
}
// DEVICE
$host_sql = 'SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id '.$where.' GROUP BY D.hostname ORDER BY D.hostname';
// SERVICE
foreach (dbFetchRows($host_sql, $host_par) as $device) {
$device_id = $device['device_id'];
$sql_param[0] = $device_id;
// FILTER BY TYPE
if (isset($_GET['type'])) {
$devicewhere = " AND `service_type` LIKE ?";
$sql_param[1] = $_GET['type'];
}
$services = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param);
}
$count = count($services);
$output = array(
'status' => $status,
'err-msg' => $message,
'count' => $count,
'services' => $services,
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
+74 -42
View File
@@ -12,9 +12,25 @@
* the source code distribution for details.
*/
$select_modes = array(
'0' => 'only devices',
'1' => 'only services',
'2' => 'devices and services',
);
if (defined('SHOW_SETTINGS')) {
$current_mode = isset($widget_settings['mode']) ? $widget_settings['mode'] : 0;
$current_width = isset($widget_settings['tile_width']) ? $widget_settings['tile_width'] : 10;
if (isset($widget_settings['mode'])) {
$mode = $widget_settings['mode'];
} else {
$mode = 0;
}
if (isset($widget_settings['tile_width'])) {
$current_width = $widget_settings['tile_width'];
} else {
$current_width = 10;
}
$common_output[] = '
<form class="form-horizontal" onsubmit="return widget_settings(this)">
<div class="form-group">
@@ -31,12 +47,15 @@ if (defined('SHOW_SETTINGS')) {
if ($config['show_services'] == 0) {
$common_output[] = '<option value="0" selected="selected">only devices</option>';
} else {
$common_output[] = '
<option value="0" '.($current_mode == 0 ? 'selected':'').'>only devices</option>
<option value="1"' .($current_mode == 1 ? 'selected':'').'>only services</option>
<option value="2"' .($current_mode == 2 ? 'selected':'').'>devices and services</option>';
foreach ($select_modes as $mode_select => $option) {
if ($mode_select == $mode) {
$selected = 'selected';
} else {
$selected = '';
}
$common_output[] = '<option value="'.$mode_select.'" '.$selected.'>'.$option.'</option>';
}
}
$common_output[] ='
</select>
</div>
@@ -50,7 +69,12 @@ if (defined('SHOW_SETTINGS')) {
$sql = dbFetchRow('SELECT `settings` FROM `users_widgets` WHERE `user_id` = ? AND `widget_id` = ?', array($_SESSION["user_id"], '1'));
$widget_mode = json_decode($sql['settings']);
$mode = isset($_SESSION["mapView"]) ? $_SESSION["mapView"] : $widget_mode->{'mode'};
if (isset($_SESSION["mapView"])) {
$mode = $_SESSION["mapView"];
} else {
$mode = $widget_mode->{'mode'};
}
$host_up_count = 0;
$host_warn_count = 0;
@@ -59,9 +83,17 @@ if (defined('SHOW_SETTINGS')) {
$service_warn_count = 0;
$service_down_count = 0;
if ($config['webui']['availability_map_sort_status'] == 1) {
$deviceOrderBy = 'status';
$serviceOrderBy = '`S`.`service_status` DESC';
} else {
$deviceOrderBy = 'hostname';
$serviceOrderBy = '`D`.`hostname`';
}
if ($mode == 0 || $mode == 2) {
// Only show devices if mode is 0 or 2 (Only Devices or both)
$sql = 'SELECT `D`.`hostname`,`D`.`device_id`,`D`.`status`,`D`.`uptime`, `D`.`os`, `D`.`icon` FROM `devices` AS `D`';
$sql = 'SELECT `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`status`, `D`.`uptime`, `D`.`os`, `D`.`icon` FROM `devices` AS `D`';
if (is_normal_user() === true) {
$sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND';
$param = array(
@@ -70,7 +102,7 @@ if (defined('SHOW_SETTINGS')) {
} else {
$sql .= ' WHERE';
}
$sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `hostname`";
$sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `".$deviceOrderBy."`";
$temp_output = array();
foreach (dbFetchRows($sql, $param) as $device) {
@@ -101,7 +133,7 @@ if (defined('SHOW_SETTINGS')) {
<div class="device-availability '.$deviceState.'">
<span class="availability-label label '.$deviceLabel.' label-font-border">'.$deviceState.'</span>
<span class="device-icon">'.$deviceIcon.'</span><br>
<span class="small">'.$device["hostname"].'</span>
<span class="small">'.shorthost(ip_to_sysname($device, $device['hostname'])).'</span>
</div>
</a>';
} else {
@@ -117,7 +149,7 @@ if (defined('SHOW_SETTINGS')) {
}
if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) {
$service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `D`.`hostname`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D where `S`.`device_id` = `D`.`device_id`;';
$service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D where `S`.`device_id` = `D`.`device_id` ORDER BY '.$serviceOrderBy.';';
$services = dbFetchRows($service_query);
if (count($services) > 0) {
foreach ($services as $service) {
@@ -142,22 +174,22 @@ if (defined('SHOW_SETTINGS')) {
if ($directpage == "yes") {
$deviceIcon = getImage($service);
$temp_output[] = '
<a href="' . generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])) . '" title="' . $service['hostname'] . " - " . $service['service_type'] . " - " . $service['service_desc'] . '">
<div class="service-availability ' . $serviceState . '">
<span class="service-name-label label ' . $serviceLabel . ' label-font-border">' . $service["service_type"] . '</span>
<span class="availability-label label ' . $serviceLabel . ' label-font-border">' . $serviceState . '</span>
<span class="device-icon">' . $deviceIcon . '</span><br>
<span class="small">' . $service["hostname"] . '</span>
<a href="'.generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])).'" title="'.$service['hostname']." - ".$service['service_type']." - ".$service['service_desc'].'">
<div class="service-availability '.$serviceState.'">
<span class="service-name-label label '.$serviceLabel.' label-font-border">'.$service["service_type"].'</span>
<span class="availability-label label '.$serviceLabel.' label-font-border">'.$serviceState.'</span>
<span class="device-icon">'.$deviceIcon.'</span><br>
<span class="small">'.shorthost(ip_to_sysname($service, $service['hostname'])).'</span>
</div>
</a>';
} else {
$temp_output[] = '
<a href="' . generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])) . '" title="' . $service['hostname'] . " - " . $service['service_type'] . " - " . $service['service_desc'] . '">
<span class="label ' . $serviceLabel . ' widget-availability label-font-border">' . $service['service_type'] . ' - ' . $serviceState . '</span>
<a href="'.generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])).'" title="'.$service['hostname']." - ".$service['service_type']." - ".$service['service_desc'].'">
<span class="label '.$serviceLabel.' widget-availability label-font-border">'.$service['service_type'].' - '.$serviceState.'</span>
</a>';
}
} else {
$temp_output[] = '<a href="' . generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])) . '" title="' . $service['hostname'] . " - " . $service['service_type'] . " - " . $service['service_desc'] . '"><div class="'.$serviceLabelOld.'"></div></a>';
$temp_output[] = '<a href="'.generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])).'" title="'.$service['hostname']." - ".$service['service_type']." - ".$service['service_desc'].'"><div class="'.$serviceLabelOld.'"></div></a>';
}
}
} else {
@@ -165,8 +197,6 @@ if (defined('SHOW_SETTINGS')) {
}
}
if ($directpage == "yes") {
$temp_header[] = '
<div class="page-availability-title-left">
@@ -174,12 +204,16 @@ if (defined('SHOW_SETTINGS')) {
<select id="mode" class="page-availability-report-select" name="mode">';
if ($config['show_services'] == 0) {
$temp_header[] = '<option value="0" '.($mode == 0 ? 'selected':'').'>only devices</option>';
$temp_header[] = '<option value="0" selected>only devices</option>';
} else {
$temp_header[] = '
<option value="0" '.($mode == 0 ? 'selected':'').'>only devices</option>
<option value="1"' .($mode == 1 ? 'selected':'').'>only services</option>
<option value="2"' .($mode == 2 ? 'selected':'').'>devices and services</option>';
foreach ($select_modes as $mode_select => $option) {
if ($mode_select == $mode) {
$selected = 'selected';
} else {
$selected = '';
}
$temp_header[] = '<option value="'.$mode_select.'" '.$selected.'>'.$option.'</option>';
}
}
$temp_header[] =
@@ -188,14 +222,17 @@ if (defined('SHOW_SETTINGS')) {
<div class="page-availability-title-right">';
}
if ($directpage == "yes") {
$deviceClass = 'page-availability-report-host';
$serviceClass = 'page-availability-report-host';
} else {
$deviceClass = 'widget-availability-host';
$serviceClass = 'widget-availability-service';
}
if ($mode == 0 || $mode == 2) {
if ($directpage == "yes") {
$headerClass = 'page-availability-report-host';
} else {
$headerClass = 'widget-availability-host';
}
$temp_header[] = '
<div class="'.$headerClass.'">
$temp_header[] = '
<div class="'.$deviceClass.'">
<span>Total hosts</span>
<span class="label label-success label-font-border label-border">up: '.$host_up_count.'</span>
<span class="label label-warning label-font-border label-border">warn: '.$host_warn_count.'</span>
@@ -204,13 +241,8 @@ if (defined('SHOW_SETTINGS')) {
}
if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) {
if ($directpage == "yes") {
$headerClass = 'page-availability-report-service';
} else {
$headerClass = 'widget-availability-service';
}
$temp_header[] = '
<div class="'.$headerClass.'">
$temp_header[] = '
<div class="'.$serviceClass.'">
<span>Total services</span>
<span class="label label-success label-font-border label-border">up: '.$service_up_count.'</span>
<span class="label label-warning label-font-border label-border">warn: '.$service_warn_count.'</span>
@@ -0,0 +1,35 @@
<?php
require 'includes/graphs/common.inc.php';
$scale_min = 0;
$colours = 'blue';
$nototal = (($width < 224) ? 1 : 0);
$unit_text = 'Inbound Calls/sec';
$rrd_filename = rrd_name($device['hostname'], array('app', 'freeswitch', 'stats', $app['app_id']));
$array = array(
'in_okay' => array(
'descr' => 'Okay',
'colour' => '008800FF',
),
'in_failed' => array(
'descr' => 'Failed',
'colour' => '880000FF',
),
);
$i = 0;
if (rrdtool_check_rrd_exists($rrd_filename)) {
foreach ($array as $ds => $vars) {
$rrd_list[$i]['filename'] = $rrd_filename;
$rrd_list[$i]['descr'] = $vars['descr'];
$rrd_list[$i]['ds'] = $ds;
$rrd_list[$i]['colour'] = $vars['colour'];
$i++;
}
} else {
echo "file missing: $file";
}
require 'includes/graphs/generic_multi_simplex_seperated.inc.php';
@@ -0,0 +1,35 @@
<?php
require 'includes/graphs/common.inc.php';
$scale_min = 0;
$colours = 'blue';
$nototal = (($width < 224) ? 1 : 0);
$unit_text = 'Outbound Calls/sec';
$rrd_filename = rrd_name($device['hostname'], array('app', 'freeswitch', 'stats', $app['app_id']));
$array = array(
'out_okay' => array(
'descr' => 'Okay',
'colour' => '008800FF',
),
'out_failed' => array(
'descr' => 'Failed',
'colour' => '880000FF',
),
);
$i = 0;
if (rrdtool_check_rrd_exists($rrd_filename)) {
foreach ($array as $ds => $vars) {
$rrd_list[$i]['filename'] = $rrd_filename;
$rrd_list[$i]['descr'] = $vars['descr'];
$rrd_list[$i]['ds'] = $ds;
$rrd_list[$i]['colour'] = $vars['colour'];
$i++;
}
} else {
echo "file missing: $file";
}
require 'includes/graphs/generic_multi_simplex_seperated.inc.php';
@@ -0,0 +1,14 @@
<?php
require 'includes/graphs/common.inc.php';
$scale_min = 0;
$ds = 'peak';
$colour_area = '9DDA52';
$colour_line = '2EAC6D';
$colour_area_max = 'FFEE99';
$graph_max = 10000;
$unit_text = 'Peak Calls';
$rrd_filename = rrd_name($device['hostname'], array('app', 'freeswitch', 'stats', $app['app_id']));
require 'includes/graphs/generic_simplex.inc.php';
-3
View File
@@ -397,9 +397,6 @@ $config_file = <<<"EOD"
#\$config\['nets'\]\[\] = "172.16.0.0/12";
#\$config\['nets'\]\[\] = "192.168.0.0/16";
# following is necessary for poller-wrapper
# poller-wrapper is released public domain
\$config\['poller-wrapper'\]\['alerter'\] = FALSE;
# Uncomment the next line to disable daily updates
#\$config\['update'\] = 0;
EOD;
+1 -1
View File
@@ -30,7 +30,7 @@ class PasswordHash {
var $portable_hashes;
var $random_state;
function PasswordHash($iteration_count_log2, $portable_hashes)
function __construct($iteration_count_log2, $portable_hashes)
{
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
+2 -2
View File
@@ -588,7 +588,7 @@ class GeSHi {
* {@link GeSHi->set_language_path()}
* @since 1.0.0
*/
function GeSHi($source = '', $language = '', $path = '') {
function __construct($source = '', $language = '', $path = '') {
if (!empty($source)) {
$this->set_source($source);
}
@@ -4616,4 +4616,4 @@ if (!function_exists('geshi_highlight')) {
}
}
?>
?>
+2 -2
View File
@@ -43,7 +43,7 @@ class ImgData_Squares extends ImgData {
protected $maxidx = 7 ;
protected $imgdata ;
function ImgData_Squares () {
function __construct() {
//==========================================================
//sq_lblue.png
//==========================================================
@@ -171,4 +171,4 @@ class ImgData_Squares extends ImgData {
}
}
?>
?>
+1 -1
View File
@@ -652,7 +652,7 @@ class GroupBarPlot extends BarPlot {
private $plots, $nbrplots=0;
//---------------
// CONSTRUCTOR
function GroupBarPlot($plots) {
function __construct($plots) {
$this->width=0.7;
$this->plots = $plots;
$this->nbrplots = count($plots);
+2 -2
View File
@@ -291,7 +291,7 @@ class FlagImages {
private $iFlagData ;
private $iOrdIdx=array();
function FlagImages($aSize=FLAGSIZE1) {
function __construct($aSize=FLAGSIZE1) {
switch($aSize) {
case FLAGSIZE1 :
case FLAGSIZE2 :
@@ -397,4 +397,4 @@ class FlagImages {
?>
?>
+1 -1
View File
@@ -59,7 +59,7 @@ class LinePlot extends Plot{
//---------------
// CONSTRUCTOR
function LinePlot($datay,$datax=false) {
function __construct($datay,$datax=false) {
parent::__construct($datay,$datax);
$this->mark = new PlotMark() ;
$this->color = ColorFactory::getColor();
+1 -1
View File
@@ -155,7 +155,7 @@ class LogTicks extends Ticks{
private $ticklabels_pos = array();
//---------------
// CONSTRUCTOR
function LogTicks() {
function __construct() {
}
//---------------
// PUBLIC METHODS
+6
View File
@@ -83,6 +83,12 @@ $graphs['dhcp-stats'] = array(
'stats',
);
$graphs['freeswitch'] = array(
'peak',
'callsIn',
'callsOut',
);
print_optionbar_start();
echo "<span style='font-weight: bold;'>Apps</span> &#187; ";
+28
View File
@@ -0,0 +1,28 @@
<?php
global $config;
$graphs = array(
'freeswitch_peak' => 'Freeswitch - Peak Calls',
'freeswitch_callsIn' => 'Freeswitch - Inbound Calls',
'freeswitch_callsOut' => 'Freeswitch - Outbound Calls'
);
foreach ($graphs as $key => $text) {
$graph_type = $key;
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = 'application_'.$key;
echo '<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">'.$text.'</h3>
</div>
<div class="panel-body">
<div class="row">';
include 'includes/print-graphrow.inc.php';
echo '</div>';
echo '</div>';
echo '</div>';
}
+2 -1
View File
@@ -26,7 +26,7 @@ if ($tmp != 0) {
$default_dash = $tmp;
} elseif ((int)$config['webui']['default_dashboard_id']) {
// if the user hasn't set their default page, and there is a global default set
$default_dash = (int)$config['webui']['default_dashboard_id'];
$default_dash = dbFetchCell('SELECT `dashboard_id` FROM `dashboards` WHERE `dashboard_id` = ?', array((int)$config['webui']['default_dashboard_id']));
}
if ($default_dash == 0 && dbFetchCell(
'SELECT dashboard_id FROM dashboards WHERE user_id=?',
@@ -326,6 +326,7 @@ foreach (dbFetchRows("SELECT * FROM `widgets` ORDER BY `widget_title`") as $widg
$('.place_widget').on('click', function(event, state) {
var widget_id = $(this).data('widget_id');
event.preventDefault();
$.ajax({
type: 'POST',
url: 'ajax_form.php',
+4
View File
@@ -23,6 +23,10 @@ $availability_map_conf = array(
'descr' => 'Availability map old view',
'type' => 'checkbox',
),
array('name' => 'webui.availability_map_sort_status',
'descr' => 'Sort devices by status',
'type' => 'checkbox',
),
);
$dashboard_conf = array(
+95 -103
View File
@@ -31,53 +31,53 @@ include_once($config['install_dir'].'/html/includes/authentication/'.$config['au
* @param string $rule Rule to generate SQL for
* @return string|boolean
*/
function GenSQL($rule) {
function GenSQL($rule)
{
$rule = RunMacros($rule);
if( empty($rule) ) {
if (empty($rule)) {
//Cannot resolve Macros due to recursion. Rule is invalid.
return false;
}
//Pretty-print rule to dissect easier
$pretty = array('*' => '*', '(' => ' ( ', ')' => ' ) ', '/' => '/', '&&' => ' && ', '||' => ' || ', 'DATE_SUB ( NOW ( )' => 'DATE_SUB( NOW()');
$rule = str_replace(array_keys($pretty),$pretty,$rule);
$tmp = explode(" ",$rule);
$rule = str_replace(array_keys($pretty), $pretty, $rule);
$tmp = explode(" ", $rule);
$tables = array();
foreach( $tmp as $opt ) {
if( strstr($opt,'%') && strstr($opt,'.') ) {
$tmpp = explode(".",$opt,2);
$tmpp[0] = str_replace("%","",$tmpp[0]);
$tables[] = mres(str_replace("(","",$tmpp[0]));
$rule = str_replace($opt,$tmpp[0].'.'.$tmpp[1],$rule);
foreach ($tmp as $opt) {
if (strstr($opt, '%') && strstr($opt, '.')) {
$tmpp = explode(".", $opt, 2);
$tmpp[0] = str_replace("%", "", $tmpp[0]);
$tables[] = mres(str_replace("(", "", $tmpp[0]));
$rule = str_replace($opt, $tmpp[0].'.'.$tmpp[1], $rule);
}
}
$tables = array_keys(array_flip($tables));
if( dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?',array($tables[0],'device_id')) != 1 ) {
if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', array($tables[0],'device_id')) != 1) {
//Our first table has no valid glue, append the 'devices' table to it!
array_unshift($tables, 'devices');
}
$x = sizeof($tables)-1;
$i = 0;
$join = "";
while( $i < $x ) {
if( isset($tables[$i+1]) ) {
$gtmp = ResolveGlues(array($tables[$i+1]),'device_id');
if( $gtmp === false ) {
while ($i < $x) {
if (isset($tables[$i+1])) {
$gtmp = ResolveGlues(array($tables[$i+1]), 'device_id');
if ($gtmp === false) {
//Cannot resolve glue-chain. Rule is invalid.
return false;
}
$last = "";
$qry = "";
foreach( $gtmp as $glue ) {
if( empty($last) ) {
list($tmp,$last) = explode('.',$glue);
foreach ($gtmp as $glue) {
if (empty($last)) {
list($tmp,$last) = explode('.', $glue);
$qry .= $glue.' = ';
}
else {
list($tmp,$new) = explode('.',$glue);
} else {
list($tmp,$new) = explode('.', $glue);
$qry .= $tmp.'.'.$last.' && '.$tmp.'.'.$new.' = ';
$last = $new;
}
if( !in_array($tmp, $tables) ) {
if (!in_array($tmp, $tables)) {
$tables[] = $tmp;
}
}
@@ -85,7 +85,7 @@ function GenSQL($rule) {
}
$i++;
}
$sql = "SELECT * FROM ".implode(",",$tables)." WHERE (".$join."".str_replace("(","",$tables[0]).".device_id = ?) && (".str_replace(array("%","@","!~","~"),array("",".*","NOT REGEXP","REGEXP"),$rule).")";
$sql = "SELECT * FROM ".implode(",", $tables)." WHERE (".$join."".str_replace("(", "", $tables[0]).".device_id = ?) && (".str_replace(array("%","@","!~","~"), array("",".*","NOT REGEXP","REGEXP"), $rule).")";
return $sql;
}
@@ -95,19 +95,19 @@ function GenSQL($rule) {
* @param int $x Recursion-Anchor
* @return string|boolean
*/
function RunMacros($rule,$x=1) {
function RunMacros($rule, $x = 1)
{
global $config;
krsort($config['alert']['macros']['rule']);
foreach( $config['alert']['macros']['rule'] as $macro=>$value ) {
if( !strstr($macro," ") ) {
$rule = str_replace('%macros.'.$macro,'('.$value.')',$rule);
foreach ($config['alert']['macros']['rule'] as $macro => $value) {
if (!strstr($macro, " ")) {
$rule = str_replace('%macros.'.$macro, '('.$value.')', $rule);
}
}
if( strstr($rule,"%macros") ) {
if( ++$x < 30 ) {
$rule = RunMacros($rule,$x);
}
else {
if (strstr($rule, "%macros")) {
if (++$x < 30) {
$rule = RunMacros($rule, $x);
} else {
return false;
}
}
@@ -119,15 +119,16 @@ function RunMacros($rule,$x=1) {
* @param int $device Device-ID
* @return array
*/
function GetRules($device) {
function GetRules($device)
{
$groups = GetGroupsFromDevice($device);
$params = array($device,$device);
$where = "";
foreach( $groups as $group ) {
foreach ($groups as $group) {
$where .= " || alert_map.target = ?";
$params[] = 'g'.$group;
}
return dbFetchRows('SELECT alert_rules.* FROM alert_rules LEFT JOIN alert_map ON alert_rules.id=alert_map.rule WHERE alert_rules.disabled = 0 && ( (alert_rules.device_id = -1 || alert_rules.device_id = ? ) || alert_map.target = ? '.$where.' )',$params);
return dbFetchRows('SELECT alert_rules.* FROM alert_rules LEFT JOIN alert_map ON alert_rules.id=alert_map.rule WHERE alert_rules.disabled = 0 && ( (alert_rules.device_id = -1 || alert_rules.device_id = ? ) || alert_map.target = ? '.$where.' )', $params);
}
/**
@@ -135,15 +136,16 @@ function GetRules($device) {
* @param int $device Device-ID
* @return int
*/
function IsMaintenance( $device ) {
function IsMaintenance($device)
{
$groups = GetGroupsFromDevice($device);
$params = array($device);
$where = "";
foreach( $groups as $group ) {
foreach ($groups as $group) {
$where .= " || alert_schedule_items.target = ?";
$params[] = 'g'.$group;
}
return dbFetchCell('SELECT alert_schedule.schedule_id FROM alert_schedule LEFT JOIN alert_schedule_items ON alert_schedule.schedule_id=alert_schedule_items.schedule_id WHERE ( alert_schedule_items.target = ?'.$where.' ) && NOW() BETWEEN alert_schedule.start AND alert_schedule.end LIMIT 1',$params);
return dbFetchCell('SELECT alert_schedule.schedule_id FROM alert_schedule LEFT JOIN alert_schedule_items ON alert_schedule.schedule_id=alert_schedule_items.schedule_id WHERE ( alert_schedule_items.target = ?'.$where.' ) && NOW() BETWEEN alert_schedule.start AND alert_schedule.end LIMIT 1', $params);
}
/**
@@ -151,64 +153,57 @@ function IsMaintenance( $device ) {
* @param int $device Device-ID
* @return void
*/
function RunRules($device) {
if( IsMaintenance($device) > 0 ) {
function RunRules($device)
{
if (IsMaintenance($device) > 0) {
echo "Under Maintenance, Skipping alerts.\r\n";
return false;
}
foreach( GetRules($device) as $rule ) {
foreach (GetRules($device) as $rule) {
echo " #".$rule['id'].":";
$inv = json_decode($rule['extra'],true);
if( isset($inv['invert']) ) {
$inv = json_decode($rule['extra'], true);
if (isset($inv['invert'])) {
$inv = (bool) $inv['invert'];
}
else {
} else {
$inv = false;
}
$chk = dbFetchRow("SELECT state FROM alerts WHERE rule_id = ? && device_id = ? ORDER BY id DESC LIMIT 1", array($rule['id'], $device));
$sql = GenSQL($rule['rule']);
$qry = dbFetchRows($sql,array($device));
$qry = dbFetchRows($sql, array($device));
if (isset($qry[0]['ip'])) {
$qry[0]['ip'] = inet6_ntop($qry[0]['ip']);
}
$s = sizeof($qry);
if( $s == 0 && $inv === false ) {
if ($s == 0 && $inv === false) {
$doalert = false;
} elseif ($s > 0 && $inv === false) {
$doalert = true;
} elseif ($s == 0 && $inv === true) {
$doalert = true;
} else { //( $s > 0 && $inv == false ) {
$doalert = false;
}
elseif( $s > 0 && $inv === false ) {
$doalert = true;
}
elseif( $s == 0 && $inv === true ) {
$doalert = true;
}
else { //( $s > 0 && $inv == false ) {
$doalert = false;
}
if( $doalert ) {
if( $chk['state'] === "2" ) {
if ($doalert) {
if ($chk['state'] === "2") {
echo " SKIP ";
}
elseif( $chk['state'] >= "1" ) {
} elseif ($chk['state'] >= "1") {
echo " NOCHG ";
}
else {
$extra = gzcompress(json_encode(array('contacts' => GetContacts($qry), 'rule'=>$qry)),9);
if( dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'details' => $extra),'alert_log') ) {
if( !dbUpdate(array('state' => 1, 'open' => 1),'alerts','device_id = ? && rule_id = ?', array($device,$rule['id'])) ) {
dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1,'alerted' => 0),'alerts');
} else {
$extra = gzcompress(json_encode(array('contacts' => GetContacts($qry), 'rule'=>$qry)), 9);
if (dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'details' => $extra), 'alert_log')) {
if (!dbUpdate(array('state' => 1, 'open' => 1), 'alerts', 'device_id = ? && rule_id = ?', array($device,$rule['id']))) {
dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1,'alerted' => 0), 'alerts');
}
echo " ALERT ";
}
}
}
else {
if( $chk['state'] === "0" ) {
} else {
if ($chk['state'] === "0") {
echo " NOCHG ";
}
else {
if( dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id']),'alert_log') ){
if( !dbUpdate(array('state' => 0, 'open' => 1),'alerts','device_id = ? && rule_id = ?', array($device,$rule['id'])) ) {
dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1, 'alerted' => 0),'alerts');
} else {
if (dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id']), 'alert_log')) {
if (!dbUpdate(array('state' => 0, 'open' => 1), 'alerts', 'device_id = ? && rule_id = ?', array($device,$rule['id']))) {
dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1, 'alerted' => 0), 'alerts');
}
echo " OK ";
}
@@ -222,62 +217,59 @@ function RunRules($device) {
* @param array $results Rule-Result
* @return array
*/
function GetContacts($results) {
function GetContacts($results)
{
global $config;
if( sizeof($results) == 0 ) {
if (sizeof($results) == 0) {
return array();
}
if( $config['alert']['default_only'] == true || $config['alerts']['email']['default_only'] == true ) {
if ($config['alert']['default_only'] == true || $config['alerts']['email']['default_only'] == true) {
return array(''.($config['alert']['default_mail'] ? $config['alert']['default_mail'] : $config['alerts']['email']['default']) => 'NOC');
}
$users = get_userlist();
$contacts = array();
$uids = array();
foreach( $results as $result ) {
$tmp = NULL;
if( is_numeric($result["bill_id"]) ) {
$tmpa = dbFetchRows("SELECT user_id FROM bill_perms WHERE bill_id = ?",array($result["bill_id"]));
foreach( $tmpa as $tmp ) {
foreach ($results as $result) {
$tmp = null;
if (is_numeric($result["bill_id"])) {
$tmpa = dbFetchRows("SELECT user_id FROM bill_perms WHERE bill_id = ?", array($result["bill_id"]));
foreach ($tmpa as $tmp) {
$uids[$tmp['user_id']] = $tmp['user_id'];
}
}
if( is_numeric($result["port_id"]) ) {
$tmpa = dbFetchRows("SELECT user_id FROM ports_perms WHERE access_level >= 0 AND port_id = ?",array($result["port_id"]));
foreach( $tmpa as $tmp ) {
if (is_numeric($result["port_id"])) {
$tmpa = dbFetchRows("SELECT user_id FROM ports_perms WHERE access_level >= 0 AND port_id = ?", array($result["port_id"]));
foreach ($tmpa as $tmp) {
$uids[$tmp['user_id']] = $tmp['user_id'];
}
}
if( is_numeric($result["device_id"]) ) {
if( $config['alert']['syscontact'] == true ) {
if( dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_bool' AND device_id = ?",array($result["device_id"])) === "1" ) {
$tmpa = dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_string' AND device_id = ?",array($result["device_id"]));
}
else {
$tmpa = dbFetchCell("SELECT sysContact FROM devices WHERE device_id = ?",array($result["device_id"]));
if (is_numeric($result["device_id"])) {
if ($config['alert']['syscontact'] == true) {
if (dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_bool' AND device_id = ?", array($result["device_id"])) === "1") {
$tmpa = dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_string' AND device_id = ?", array($result["device_id"]));
} else {
$tmpa = dbFetchCell("SELECT sysContact FROM devices WHERE device_id = ?", array($result["device_id"]));
}
$contacts[$tmpa] = "NOC";
}
$tmpa = dbFetchRows("SELECT user_id FROM devices_perms WHERE access_level >= 0 AND device_id = ?", array($result["device_id"]));
foreach( $tmpa as $tmp ) {
foreach ($tmpa as $tmp) {
$uids[$tmp['user_id']] = $tmp['user_id'];
}
}
}
foreach( $users as $user ) {
if( empty($user['email']) ) {
foreach ($users as $user) {
if (empty($user['email'])) {
continue;
}
elseif( empty($user['realname']) ) {
} elseif (empty($user['realname'])) {
$user['realname'] = $user['username'];
}
$user['level'] = get_userlevel($user['username']);
if( $config["alert"]["globals"] && ( $user['level'] >= 5 && $user['level'] < 10 ) ) {
if ($config["alert"]["globals"] && ( $user['level'] >= 5 && $user['level'] < 10 )) {
$contacts[$user['email']] = $user['realname'];
}
elseif( $config["alert"]["admins"] && $user['level'] == 10 ) {
} elseif ($config["alert"]["admins"] && $user['level'] == 10) {
$contacts[$user['email']] = $user['realname'];
}
elseif( in_array($user['user_id'],$uids) ) {
} elseif (in_array($user['user_id'], $uids)) {
$contacts[$user['email']] = $user['realname'];
}
}
@@ -287,7 +279,7 @@ function GetContacts($results) {
if (strstr($email, ',')) {
$split_contacts = preg_split("/[,\s]+/", $email);
foreach ($split_contacts as $split_email) {
if(!empty($split_email)) {
if (!empty($split_email)) {
$tmp_contacts[$split_email] = $name;
}
}
+30 -32
View File
@@ -1,23 +1,24 @@
<?php
function format_bytes_billing($value) {
function format_bytes_billing($value)
{
global $config;
return format_number($value, $config['billing']['base']).'B';
}//end format_bytes_billing()
function format_bytes_billing_short($value) {
function format_bytes_billing_short($value)
{
global $config;
return format_number($value, $config['billing']['base'], 2, 3);
}//end format_bytes_billing_short()
function getDates($dayofmonth, $months=0) {
function getDates($dayofmonth, $months = 0)
{
$dayofmonth = zeropad($dayofmonth);
$year = date('Y');
$month = date('m');
@@ -27,8 +28,7 @@ function getDates($dayofmonth, $months=0) {
$date_end = date_create($year.'-'.$month.'-'.$dayofmonth);
$date_start = date_create($year.'-'.$month.'-'.$dayofmonth);
date_add($date_end, date_interval_create_from_date_string('1 month'));
}
else {
} else {
// Billing day will happen this month, therefore started last month
$date_end = date_create($year.'-'.$month.'-'.$dayofmonth);
$date_start = date_create($year.'-'.$month.'-'.$dayofmonth);
@@ -59,10 +59,10 @@ function getDates($dayofmonth, $months=0) {
$return['3'] = $last_to;
return ($return);
}//end getDates()
function getPredictedUsage($bill_day, $cur_used) {
function getPredictedUsage($bill_day, $cur_used)
{
$tmp = getDates($bill_day, 0);
$start = new DateTime($tmp[0], new DateTimeZone(date_default_timezone_get()));
@@ -71,10 +71,10 @@ function getPredictedUsage($bill_day, $cur_used) {
$total = $end->diff($start)->format("%a");
$since = $now->diff($start)->format("%a");
return($cur_used/$since*$total);
}
function getValue($host, $port, $id, $inout) {
function getValue($host, $port, $id, $inout)
{
global $config;
$oid = 'IF-MIB::ifHC'.$inout.'Octets.'.$id;
@@ -87,10 +87,10 @@ function getValue($host, $port, $id, $inout) {
}
return $value;
}//end getValue()
function getLastPortCounter($port_id, $bill_id) {
function getLastPortCounter($port_id, $bill_id)
{
$return = array();
$row = dbFetchRow("SELECT timestamp, in_counter, in_delta, out_counter, out_delta FROM bill_port_counters WHERE `port_id` = ? AND `bill_id` = ?", array($port_id, $bill_id));
if (!is_null($row)) {
@@ -100,15 +100,15 @@ function getLastPortCounter($port_id, $bill_id) {
$return[out_counter] = $row['out_counter'];
$return[out_delta] = $row['out_delta'];
$return[state] = 'ok';
}
else {
} else {
$return[state] = 'failed';
}
return $return;
}//end getLastPortCounter()
function getLastMeasurement($bill_id) {
function getLastMeasurement($bill_id)
{
$return = array();
$row = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id = ? ORDER BY timestamp DESC LIMIT 1", array($bill_id));
if (!is_null($row)) {
@@ -117,15 +117,15 @@ function getLastMeasurement($bill_id) {
$return[delta_out] = $row['delta_out'];
$return[timestamp] = $row['timestamp'];
$return[state] = 'ok';
}
else {
} else {
$return[state] = 'failed';
}
return ($return);
}//end getLastMeasurement()
function get95thin($bill_id, $datefrom, $dateto) {
function get95thin($bill_id, $datefrom, $dateto)
{
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."'";
$mq_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'";
$measurements = dbFetchCell($mq_sql);
@@ -137,11 +137,11 @@ function get95thin($bill_id, $datefrom, $dateto) {
$m_95th = $a_95th[$measurement_95th];
return (round($m_95th, 2));
}//end get95thin()
function get95thout($bill_id, $datefrom, $dateto) {
function get95thout($bill_id, $datefrom, $dateto)
{
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."'";
$mq_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'";
$measurements = dbFetchCell($mq_sql);
@@ -154,11 +154,11 @@ function get95thout($bill_id, $datefrom, $dateto) {
$m_95th = $a_95th[$measurement_95th];
return (round($m_95th, 2));
}//end get95thout()
function getRates($bill_id, $datefrom, $dateto) {
function getRates($bill_id, $datefrom, $dateto)
{
$data = array();
$mq_text = 'SELECT count(delta) FROM bill_data ';
$mq_text .= " WHERE bill_id = '".mres($bill_id)."'";
@@ -184,8 +184,7 @@ function getRates($bill_id, $datefrom, $dateto) {
if ($data['rate_95th_out'] > $data['rate_95th_in']) {
$data['rate_95th'] = $data['rate_95th_out'];
$data['dir_95th'] = 'out';
}
else {
} else {
$data['rate_95th'] = $data['rate_95th_in'];
$data['dir_95th'] = 'in';
}
@@ -199,26 +198,25 @@ function getRates($bill_id, $datefrom, $dateto) {
// print_r($data);
return ($data);
}//end getRates()
function getTotal($bill_id, $datefrom, $dateto) {
function getTotal($bill_id, $datefrom, $dateto)
{
$mtot = dbFetchCell("SELECT SUM(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'");
return ($mtot);
}//end getTotal()
function getSum($bill_id, $datefrom, $dateto) {
function getSum($bill_id, $datefrom, $dateto)
{
$sum = dbFetchRow("SELECT SUM(period) as period, SUM(delta) as total, SUM(in_delta) as inbound, SUM(out_delta) as outbound FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'");
return ($sum);
}//end getSum()
function getPeriod($bill_id, $datefrom, $dateto) {
function getPeriod($bill_id, $datefrom, $dateto)
{
$ptot = dbFetchCell("SELECT SUM(period) FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'");
return ($ptot);
}//end getPeriod()
+1 -2
View File
@@ -10,8 +10,7 @@ if ($_SESSION['userlevel'] >= 5) {
$data['ignored'] = array('query' => "SELECT COUNT(*) FROM devices WHERE `ignore` = '1' AND `disabled` = '0'");
$data['disabled'] = array('query' => "SELECT COUNT(*) FROM devices WHERE `disabled` = '1'");
}
else {
} else {
$data['count'] = array(
'query' => 'SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id`',
'params' => array($_SESSION['user_id']),
-1
View File
@@ -44,4 +44,3 @@ $data['read'] = array(
'query' => 'select notifications.* from notifications inner join notifications_attribs on notifications.notifications_id = notifications_attribs.notifications_id where notifications_attribs.user_id = ? && ( notifications_attribs.key = "read" && notifications_attribs.value = 1) && not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.key = "sticky" && notifications_attribs.value = "1") order by notifications_attribs.attrib_id desc',
'params' => array( $_SESSION['user_id'] )
);
+1 -2
View File
@@ -12,8 +12,7 @@ if ($_SESSION['userlevel'] >= 5) {
$data['errored'] = array('query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')");
$data['ignored'] = array('query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND (I.`ignore` = '1' OR D.`ignore` = '1')");
}
else {
} else {
$data['count'] = array(
'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id`",
'params' => array($_SESSION['user_id']),
+1 -2
View File
@@ -6,8 +6,7 @@ if ($_SESSION['userlevel'] >= 5) {
$data['down'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '0' AND `service_disabled` = '0' AND `service_status` = '2'");
$data['ignored'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '1' AND `service_disabled` = '0'");
$data['disabled'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_disabled` = '1'");
}
else {
} else {
$data['count'] = array(
'query' => 'SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id`',
'params' => array($_SESSION['user_id']),
+1 -2
View File
@@ -91,8 +91,7 @@ if ($enabled == 1) {
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($post);
}
else if ($enabled == 2) {
} elseif ($enabled == 2) {
$uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'");
$fields = "uuid=$uuid";
+320 -256
View File
File diff suppressed because it is too large Load Diff
-1
View File
@@ -71,4 +71,3 @@ function data_update($device, $measurement, $tags, $fields)
rrdtool_data_update($device, $measurement, $tags, $fields);
influx_update($device, $measurement, rrd_array_filter($tags), $fields);
} // data_update
+50 -61
View File
@@ -23,19 +23,18 @@
* */
function dbQuery($sql, $parameters=array()) {
function dbQuery($sql, $parameters = array())
{
global $fullSql, $debug, $sql_debug;
$fullSql = dbMakeQuery($sql, $parameters);
if ($debug) {
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
if (preg_match('/(INSERT INTO `alert_log`).*(details)/i',$fullSql)) {
if (preg_match('/(INSERT INTO `alert_log`).*(details)/i', $fullSql)) {
echo "\nINSERT INTO `alert_log` entry masked due to binary data\n";
}
else {
} else {
c_echo("\nSQL[%y".$fullSql.'%n] ');
}
}
else {
} else {
$sql_debug[] = $fullSql;
}
}
@@ -60,7 +59,6 @@ function dbQuery($sql, $parameters=array()) {
}
return $result;
}//end dbQuery()
@@ -70,7 +68,8 @@ function dbQuery($sql, $parameters=array()) {
* */
function dbInsert($data, $table) {
function dbInsert($data, $table)
{
global $fullSql;
global $db_stats;
// the following block swaps the parameters if they were given in the wrong order.
@@ -93,8 +92,7 @@ function dbInsert($data, $table) {
$id = mysql_insert_id();
dbCommitTransaction();
// return $id;
}
else {
} else {
if ($table != 'Contact') {
trigger_error('QDB - Insert failed.', E_USER_WARNING);
}
@@ -109,7 +107,6 @@ function dbInsert($data, $table) {
$db_stats['insert']++;
return $id;
}//end dbInsert()
@@ -120,7 +117,8 @@ function dbInsert($data, $table) {
* */
function dbBulkInsert($data, $table) {
function dbBulkInsert($data, $table)
{
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)
@@ -164,7 +162,6 @@ function dbBulkInsert($data, $table) {
$db_stats['insert']++;
return $result;
}//end dbBulkInsert()
@@ -174,7 +171,8 @@ function dbBulkInsert($data, $table) {
* */
function dbUpdate($data, $table, $where=null, $parameters=array()) {
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.
@@ -205,8 +203,7 @@ function dbUpdate($data, $table, $where=null, $parameters=array()) {
$time_start = microtime(true);
if (dbQuery($sql, $data)) {
$return = mysql_affected_rows();
}
else {
} else {
// echo("$fullSql");
trigger_error('QDB - Update failed.', E_USER_WARNING);
$return = false;
@@ -217,11 +214,11 @@ function dbUpdate($data, $table, $where=null, $parameters=array()) {
$db_stats['update']++;
return $return;
}//end dbUpdate()
function dbDelete($table, $where=null, $parameters=array()) {
function dbDelete($table, $where = null, $parameters = array())
{
$sql = 'DELETE FROM `'.$table.'`';
if ($where) {
$sql .= ' WHERE '.$where;
@@ -229,11 +226,9 @@ function dbDelete($table, $where=null, $parameters=array()) {
if (dbQuery($sql, $parameters)) {
return mysql_affected_rows();
}
else {
} else {
return false;
}
}//end dbDelete()
@@ -243,11 +238,12 @@ function dbDelete($table, $where=null, $parameters=array()) {
* */
function dbFetchRows($sql, $parameters=array(), $nocache=false) {
function dbFetchRows($sql, $parameters = array(), $nocache = false)
{
global $db_stats, $config;
if ($config['memcached']['enable'] && $nocache === false) {
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
$result = $config['memcached']['resource']->get(hash('sha512', $sql.'|'.serialize($parameters)));
if (!empty($result)) {
return $result;
}
@@ -264,7 +260,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) {
mysql_free_result($result);
if ($config['memcached']['enable'] && $nocache === false) {
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']);
$config['memcached']['resource']->set(hash('sha512', $sql.'|'.serialize($parameters)), $rows, $config['memcached']['ttl']);
}
return $rows;
}
@@ -278,7 +274,6 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) {
// no records, thus return empty array
// which should evaluate to false, and will prevent foreach notices/warnings
return array();
}//end dbFetchRows()
@@ -288,7 +283,8 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) {
* */
function dbFetch($sql, $parameters=array(), $nocache=false) {
function dbFetch($sql, $parameters = array(), $nocache = false)
{
return dbFetchRows($sql, $parameters, $nocache);
/*
// for now, don't do the iterator thing
@@ -300,7 +296,6 @@ function dbFetch($sql, $parameters=array(), $nocache=false) {
return null; // ??
}
*/
}//end dbFetch()
@@ -310,11 +305,12 @@ function dbFetch($sql, $parameters=array(), $nocache=false) {
* */
function dbFetchRow($sql=null, $parameters=array(), $nocache=false) {
function dbFetchRow($sql = null, $parameters = array(), $nocache = false)
{
global $db_stats, $config;
if ($config['memcached']['enable'] && $nocache === false) {
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
$result = $config['memcached']['resource']->get(hash('sha512', $sql.'|'.serialize($parameters)));
if (!empty($result)) {
return $result;
}
@@ -331,16 +327,14 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) {
$db_stats['fetchrow']++;
if ($config['memcached']['enable'] && $nocache === false) {
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']);
$config['memcached']['resource']->set(hash('sha512', $sql.'|'.serialize($parameters)), $row, $config['memcached']['ttl']);
}
return $row;
}
else {
} else {
return null;
}
$time_start = microtime(true);
}//end dbFetchRow()
@@ -349,7 +343,8 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) {
* */
function dbFetchCell($sql, $parameters=array(), $nocache=false) {
function dbFetchCell($sql, $parameters = array(), $nocache = false)
{
global $db_stats;
$time_start = microtime(true);
$row = dbFetchRow($sql, $parameters, $nocache);
@@ -364,7 +359,6 @@ function dbFetchCell($sql, $parameters=array(), $nocache=false) {
$db_stats['fetchcell']++;
return null;
}//end dbFetchCell()
@@ -374,7 +368,8 @@ function dbFetchCell($sql, $parameters=array(), $nocache=false) {
* */
function dbFetchColumn($sql, $parameters=array(), $nocache=false) {
function dbFetchColumn($sql, $parameters = array(), $nocache = false)
{
global $db_stats;
$time_start = microtime(true);
$cells = array();
@@ -388,7 +383,6 @@ function dbFetchColumn($sql, $parameters=array(), $nocache=false) {
$db_stats['fetchcol']++;
return $cells;
}//end dbFetchColumn()
@@ -399,7 +393,8 @@ function dbFetchColumn($sql, $parameters=array(), $nocache=false) {
*/
function dbFetchKeyValue($sql, $parameters=array()) {
function dbFetchKeyValue($sql, $parameters = array())
{
$data = array();
foreach (dbFetch($sql, $parameters) as $row) {
$key = array_shift($row);
@@ -407,8 +402,7 @@ function dbFetchKeyValue($sql, $parameters=array()) {
// if there were only 2 fields in the result
// use the second for the value
$data[$key] = array_shift($row);
}
else {
} else {
// if more than 2 fields were fetched
// use the array of the rest as the value
$data[$key] = $row;
@@ -416,7 +410,6 @@ function dbFetchKeyValue($sql, $parameters=array()) {
}
return $data;
}//end dbFetchKeyValue()
@@ -426,7 +419,8 @@ function dbFetchKeyValue($sql, $parameters=array()) {
*/
function dbMakeQuery($sql, $parameters) {
function dbMakeQuery($sql, $parameters)
{
// bypass extra logic if we have no parameters
if (sizeof($parameters) == 0) {
return $sql;
@@ -439,8 +433,7 @@ function dbMakeQuery($sql, $parameters) {
foreach ($parameters as $key => $value) {
if (is_numeric($key)) {
$questionParams[] = $value;
}
else {
} else {
$namedParams[':'.$key] = $value;
}
}
@@ -462,19 +455,18 @@ function dbMakeQuery($sql, $parameters) {
$test = $result[$j];
if ($test == '?') {
$query .= array_shift($questionParams);
}
else {
} else {
$query .= $namedParams[$test];
}
}
}
return $query;
}//end dbMakeQuery()
function dbPrepareData($data) {
function dbPrepareData($data)
{
$values = array();
foreach ($data as $key => $value) {
@@ -493,14 +485,12 @@ function dbPrepareData($data) {
// continue;
if ($escape) {
$values[$key] = "'".mysql_real_escape_string($value)."'";
}
else {
} else {
$values[$key] = $value;
}
}
return $values;
}//end dbPrepareData()
@@ -510,37 +500,36 @@ function dbPrepareData($data) {
*/
function dbPlaceHolders($values) {
function dbPlaceHolders($values)
{
$data = array();
foreach ($values as $key => $value) {
if (is_numeric($key)) {
$data[] = '?';
}
else {
} else {
$data[] = ':'.$key;
}
}
return $data;
}//end dbPlaceHolders()
function dbBeginTransaction() {
function dbBeginTransaction()
{
mysql_query('begin');
}//end dbBeginTransaction()
function dbCommitTransaction() {
function dbCommitTransaction()
{
mysql_query('commit');
}//end dbCommitTransaction()
function dbRollbackTransaction() {
function dbRollbackTransaction()
{
mysql_query('rollback');
}//end dbRollbackTransaction()
+51 -62
View File
@@ -23,19 +23,18 @@
* */
function dbQuery($sql, $parameters=array()) {
function dbQuery($sql, $parameters = array())
{
global $fullSql, $debug, $sql_debug, $database_link;
$fullSql = dbMakeQuery($sql, $parameters);
if ($debug) {
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
if (preg_match('/(INSERT INTO `alert_log`).*(details)/i',$fullSql)) {
if (preg_match('/(INSERT INTO `alert_log`).*(details)/i', $fullSql)) {
echo "\nINSERT INTO `alert_log` entry masked due to binary data\n";
}
else {
} else {
c_echo("\nSQL[%y".$fullSql.'%n] ');
}
}
else {
} else {
$sql_debug[] = $fullSql;
}
}
@@ -60,7 +59,6 @@ function dbQuery($sql, $parameters=array()) {
}
return $result;
}//end dbQuery()
@@ -70,7 +68,8 @@ function dbQuery($sql, $parameters=array()) {
* */
function dbInsert($data, $table) {
function dbInsert($data, $table)
{
global $fullSql, $database_link;
global $db_stats;
// the following block swaps the parameters if they were given in the wrong order.
@@ -93,8 +92,7 @@ function dbInsert($data, $table) {
$id = mysqli_insert_id($database_link);
dbCommitTransaction();
// return $id;
}
else {
} else {
if ($table != 'Contact') {
trigger_error('QDB - Insert failed.', E_USER_WARNING);
}
@@ -109,7 +107,6 @@ function dbInsert($data, $table) {
$db_stats['insert']++;
return $id;
}//end dbInsert()
@@ -120,7 +117,8 @@ function dbInsert($data, $table) {
* */
function dbBulkInsert($data, $table) {
function dbBulkInsert($data, $table)
{
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)
@@ -164,7 +162,6 @@ function dbBulkInsert($data, $table) {
$db_stats['insert']++;
return $result;
}//end dbBulkInsert()
@@ -174,7 +171,8 @@ function dbBulkInsert($data, $table) {
* */
function dbUpdate($data, $table, $where=null, $parameters=array()) {
function dbUpdate($data, $table, $where = null, $parameters = array())
{
global $fullSql, $database_link;
global $db_stats;
// the following block swaps the parameters if they were given in the wrong order.
@@ -205,8 +203,7 @@ function dbUpdate($data, $table, $where=null, $parameters=array()) {
$time_start = microtime(true);
if (dbQuery($sql, $data)) {
$return = mysqli_affected_rows($database_link);
}
else {
} else {
// echo("$fullSql");
trigger_error('QDB - Update failed.', E_USER_WARNING);
$return = false;
@@ -217,11 +214,11 @@ function dbUpdate($data, $table, $where=null, $parameters=array()) {
$db_stats['update']++;
return $return;
}//end dbUpdate()
function dbDelete($table, $where=null, $parameters=array()) {
function dbDelete($table, $where = null, $parameters = array())
{
global $database_link;
$sql = 'DELETE FROM `'.$table.'`';
if ($where) {
@@ -230,11 +227,9 @@ function dbDelete($table, $where=null, $parameters=array()) {
if (dbQuery($sql, $parameters)) {
return mysqli_affected_rows($database_link);
}
else {
} else {
return false;
}
}//end dbDelete()
@@ -244,11 +239,12 @@ function dbDelete($table, $where=null, $parameters=array()) {
* */
function dbFetchRows($sql, $parameters=array(), $nocache=false) {
function dbFetchRows($sql, $parameters = array(), $nocache = false)
{
global $db_stats, $config;
if ($config['memcached']['enable'] && $nocache === false) {
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
$result = $config['memcached']['resource']->get(hash('sha512', $sql.'|'.serialize($parameters)));
if (!empty($result)) {
return $result;
}
@@ -265,7 +261,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) {
mysqli_free_result($result);
if ($config['memcached']['enable'] && $nocache === false) {
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']);
$config['memcached']['resource']->set(hash('sha512', $sql.'|'.serialize($parameters)), $rows, $config['memcached']['ttl']);
}
return $rows;
}
@@ -279,7 +275,6 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) {
// no records, thus return empty array
// which should evaluate to false, and will prevent foreach notices/warnings
return array();
}//end dbFetchRows()
@@ -289,7 +284,8 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) {
* */
function dbFetch($sql, $parameters=array(), $nocache=false) {
function dbFetch($sql, $parameters = array(), $nocache = false)
{
return dbFetchRows($sql, $parameters, $nocache);
/*
// for now, don't do the iterator thing
@@ -301,7 +297,6 @@ function dbFetch($sql, $parameters=array(), $nocache=false) {
return null; // ??
}
*/
}//end dbFetch()
@@ -311,11 +306,12 @@ function dbFetch($sql, $parameters=array(), $nocache=false) {
* */
function dbFetchRow($sql=null, $parameters=array(), $nocache=false) {
function dbFetchRow($sql = null, $parameters = array(), $nocache = false)
{
global $db_stats, $config;
if ($config['memcached']['enable'] && $nocache === false) {
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
$result = $config['memcached']['resource']->get(hash('sha512', $sql.'|'.serialize($parameters)));
if (!empty($result)) {
return $result;
}
@@ -332,16 +328,14 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) {
$db_stats['fetchrow']++;
if ($config['memcached']['enable'] && $nocache === false) {
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']);
$config['memcached']['resource']->set(hash('sha512', $sql.'|'.serialize($parameters)), $row, $config['memcached']['ttl']);
}
return $row;
}
else {
} else {
return null;
}
$time_start = microtime(true);
}//end dbFetchRow()
@@ -350,7 +344,8 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) {
* */
function dbFetchCell($sql, $parameters=array(), $nocache=false) {
function dbFetchCell($sql, $parameters = array(), $nocache = false)
{
global $db_stats, $config;
$time_start = microtime(true);
@@ -366,7 +361,6 @@ function dbFetchCell($sql, $parameters=array(), $nocache=false) {
$db_stats['fetchcell']++;
return null;
}//end dbFetchCell()
@@ -376,7 +370,8 @@ function dbFetchCell($sql, $parameters=array(), $nocache=false) {
* */
function dbFetchColumn($sql, $parameters=array(), $nocache=false) {
function dbFetchColumn($sql, $parameters = array(), $nocache = false)
{
global $db_stats;
$time_start = microtime(true);
$cells = array();
@@ -390,7 +385,6 @@ function dbFetchColumn($sql, $parameters=array(), $nocache=false) {
$db_stats['fetchcol']++;
return $cells;
}//end dbFetchColumn()
@@ -401,7 +395,8 @@ function dbFetchColumn($sql, $parameters=array(), $nocache=false) {
*/
function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) {
function dbFetchKeyValue($sql, $parameters = array(), $nocache = false)
{
$data = array();
foreach (dbFetch($sql, $parameters, $nocache) as $row) {
$key = array_shift($row);
@@ -409,8 +404,7 @@ function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) {
// if there were only 2 fields in the result
// use the second for the value
$data[$key] = array_shift($row);
}
else {
} else {
// if more than 2 fields were fetched
// use the array of the rest as the value
$data[$key] = $row;
@@ -418,7 +412,6 @@ function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) {
}
return $data;
}//end dbFetchKeyValue()
@@ -428,7 +421,8 @@ function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) {
*/
function dbMakeQuery($sql, $parameters) {
function dbMakeQuery($sql, $parameters)
{
// bypass extra logic if we have no parameters
if (sizeof($parameters) == 0) {
return $sql;
@@ -441,8 +435,7 @@ function dbMakeQuery($sql, $parameters) {
foreach ($parameters as $key => $value) {
if (is_numeric($key)) {
$questionParams[] = $value;
}
else {
} else {
$namedParams[':'.$key] = $value;
}
}
@@ -464,19 +457,18 @@ function dbMakeQuery($sql, $parameters) {
$test = $result[$j];
if ($test == '?') {
$query .= array_shift($questionParams);
}
else {
} else {
$query .= $namedParams[$test];
}
}
}
return $query;
}//end dbMakeQuery()
function dbPrepareData($data) {
function dbPrepareData($data)
{
global $database_link;
$values = array();
@@ -495,15 +487,13 @@ function dbPrepareData($data) {
// if(!in_array($key, $columns)) // skip invalid fields
// continue;
if ($escape) {
$values[$key] = "'".mysqli_real_escape_string($database_link,$value)."'";
}
else {
$values[$key] = "'".mysqli_real_escape_string($database_link, $value)."'";
} else {
$values[$key] = $value;
}
}
return $values;
}//end dbPrepareData()
@@ -513,40 +503,39 @@ function dbPrepareData($data) {
*/
function dbPlaceHolders($values) {
function dbPlaceHolders($values)
{
$data = array();
foreach ($values as $key => $value) {
if (is_numeric($key)) {
$data[] = '?';
}
else {
} else {
$data[] = ':'.$key;
}
}
return $data;
}//end dbPlaceHolders()
function dbBeginTransaction() {
function dbBeginTransaction()
{
global $database_link;
mysqli_query($database_link, 'begin');
}//end dbBeginTransaction()
function dbCommitTransaction() {
function dbCommitTransaction()
{
global $database_link;
mysqli_query($database_link, 'commit');
}//end dbCommitTransaction()
function dbRollbackTransaction() {
function dbRollbackTransaction()
{
global $database_link;
mysqli_query($database_link, 'rollback');
}//end dbRollbackTransaction()
+1 -2
View File
@@ -2,8 +2,7 @@
if (file_exists($config['install_dir'].'/includes/dbFacile.'.$config['db']['extension'].'.php')) {
require_once $config['install_dir'].'/includes/dbFacile.'.$config['db']['extension'].'.php';
}
else {
} else {
echo $config['db']['extension'] . " extension not found\n";
exit;
}
+9 -10
View File
@@ -23,7 +23,8 @@
//
error_reporting(E_ERROR|E_PARSE|E_CORE_ERROR|E_COMPILE_ERROR);
function set_debug($debug) {
function set_debug($debug)
{
if (isset($debug)) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
@@ -39,10 +40,10 @@ $config['install_dir'] = realpath(__DIR__ . '/..');
// initialize the class loader and add custom mappings
require_once $config['install_dir'] . '/LibreNMS/ClassLoader.php';
$classLoader = new LibreNMS\ClassLoader();
$classLoader->registerClass('Console_Color2', $config['install_dir'] . '/includes/console_colour.php');
$classLoader->registerClass('Console_Table', $config['install_dir'] . '/includes/console_table.php');
$classLoader->registerClass('PHPMailer', $config['install_dir'] . "/includes/phpmailer/class.phpmailer.php");
$classLoader->registerClass('SMTP', $config['install_dir'] . "/includes/phpmailer/class.smtp.php");
$classLoader->registerClass('Console_Color2', $config['install_dir'] . '/lib/console_colour.php');
$classLoader->registerClass('Console_Table', $config['install_dir'] . '/lib/console_table.php');
$classLoader->registerClass('PHPMailer', $config['install_dir'] . "/lib/phpmailer/class.phpmailer.php");
$classLoader->registerClass('SMTP', $config['install_dir'] . "/lib/phpmailer/class.smtp.php");
$classLoader->registerClass('PasswordHash', $config['install_dir'] . '/html/lib/PasswordHash.php');
$classLoader->register();
@@ -107,8 +108,7 @@ if (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT'])) {
if (strpos($_SERVER['SERVER_NAME'], ':')) {
// Literal IPv6
$config['base_url'] = 'http://['.$_SERVER['SERVER_NAME'].']'.($_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : '').'/';
}
else {
} else {
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : '').'/';
}
}
@@ -172,7 +172,7 @@ $config['show_services'] = 0;
$config['ports_page_default'] = 'details';
// eg "details" or "basic"
// Adding Host Settings
$config['addhost_alwayscheckip'] = FALSE; # TRUE - check for duplicate ips even when adding host by name. FALSE- only check when adding host by ip.
$config['addhost_alwayscheckip'] = false; # TRUE - check for duplicate ips even when adding host by name. FALSE- only check when adding host by ip.
// SNMP Settings - Timeouts/Retries disabled as default
// $config['snmp']['timeout'] = 1; # timeout in seconds
// $config['snmp']['retries'] = 5; # how many times to retry the query
@@ -883,7 +883,7 @@ $config['update_channel'] = 'master';
$config['default_port_association_mode'] = 'ifIndex';
// Ignore ports which can't be mapped using a devices port_association_mode
// See include/polling/ports.inc.php for a lenghty explanation.
$config['ignore_unmapable_port'] = False;
$config['ignore_unmapable_port'] = false;
// InfluxDB default configuration
$config['influxdb']['timeout'] = 0;
@@ -891,4 +891,3 @@ $config['influxdb']['verifySSL'] = false;
// Xirrus - Disable station/client polling if true as it may take a long time on larger/heavily used APs.
$config['xirrus_disable_stations'] = false;
+70 -34
View File
@@ -1,13 +1,13 @@
<?php
require_once $config['install_dir'].'/includes/common.php';
require_once $config['install_dir'].'/includes/dbFacile.php';
require_once $config['install_dir'].'/includes/mergecnf.inc.php';
// Connect to database
if ($config['db']['extension'] == 'mysqli') {
$database_link = mysqli_connect('p:'.$config['db_host'], $config['db_user'], $config['db_pass']);
}
else {
} else {
$database_link = mysql_pconnect($config['db_host'], $config['db_user'], $config['db_pass']);
}
@@ -15,17 +15,15 @@ if (!$database_link) {
echo '<h2>MySQL Error</h2>';
if ($config['db']['extension'] == 'mysqli') {
echo mysqli_error($database_link);
}
else {
} else {
echo mysql_error();
}
die;
die;
}
if ($config['db']['extension'] == 'mysqli') {
$database_db = mysqli_select_db($database_link, $config['db_name']);
}
else {
} else {
$database_db = mysql_select_db($config['db_name'], $database_link);
}
@@ -34,8 +32,7 @@ if ($config['memcached']['enable'] === true) {
$config['memcached']['ttl'] = 60;
$config['memcached']['resource'] = new Memcached();
$config['memcached']['resource']->addServer($config['memcached']['host'], $config['memcached']['port']);
}
else {
} else {
echo "WARNING: You have enabled memcached but have not installed the PHP bindings. Disabling memcached support.\n";
echo "Try 'apt-get install php5-memcached' or 'pecl install memcached'. You will need the php5-dev and libmemcached-dev packages to use pecl.\n\n";
$config['memcached']['enable'] = 0;
@@ -299,6 +296,17 @@ $config['os'][$os]['icon'] = 'buffalo';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Device Traffic';
$os = 'ddnos';
$config['os'][$os]['text'] = 'DDN Storage';
$config['os'][$os]['type'] = 'storage';
$config['os'][$os]['icon'] = 'ddn';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Device Traffic';
$config['os'][$os]['over'][1]['graph'] = 'device_processor';
$config['os'][$os]['over'][1]['text'] = 'Processor Usage';
$config['os'][$os]['over'][2]['graph'] = 'device_mempool';
$config['os'][$os]['over'][2]['text'] = 'Memory Usage';
// Other Unix-based OSes here please.
$os = 'freebsd';
$config['os'][$os]['type'] = 'server';
@@ -575,9 +583,9 @@ $config['os'][$os]['over'][4]['text'] = 'Number of Clients';
$config['os'][$os]['icon'] = 'cisco';
$os = 'vcs';
$config['os'][$os]['text'] = 'Video Communication Server';
$config['os'][$os]['type'] = 'collaboration';
$config['os'][$os]['icon'] = 'cisco';
$config['os'][$os]['text'] = 'Video Communication Server';
$config['os'][$os]['type'] = 'collaboration';
$config['os'][$os]['icon'] = 'cisco';
$os = 'acano';
$config['os'][$os]['group'] = 'cisco';
@@ -630,22 +638,33 @@ $config['os'][$os]['over'][2]['graph'] = 'device_mempool';
$config['os'][$os]['over'][2]['text'] = 'Memory Usage';
$os = 'primeinfrastructure';
$config['os'][$os]['text'] = 'Prime Infrastructure';
$config['os'][$os]['type'] = 'server';
$config['os'][$os]['icon'] = 'cisco';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Device Traffic';
$config['os'][$os]['over'][1]['graph'] = 'device_processor';
$config['os'][$os]['over'][1]['text'] = 'CPU Usage';
$config['os'][$os]['over'][2]['graph'] = 'device_mempool';
$config['os'][$os]['over'][2]['text'] = 'Memory Usage';
$config['os'][$os]['over'][3]['graph'] = 'device_storage';
$config['os'][$os]['over'][3]['text'] = 'Storage Usage';
$config['os'][$os]['text'] = 'Prime Infrastructure';
$config['os'][$os]['type'] = 'server';
$config['os'][$os]['icon'] = 'cisco';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Device Traffic';
$config['os'][$os]['over'][1]['graph'] = 'device_processor';
$config['os'][$os]['over'][1]['text'] = 'CPU Usage';
$config['os'][$os]['over'][2]['graph'] = 'device_mempool';
$config['os'][$os]['over'][2]['text'] = 'Memory Usage';
$config['os'][$os]['over'][3]['graph'] = 'device_storage';
$config['os'][$os]['over'][3]['text'] = 'Storage Usage';
$os = 'tpconductor';
$config['os'][$os]['text'] = 'TelePresence Conductor';
$config['os'][$os]['type'] = 'collaboration';
$config['os'][$os]['icon'] = 'cisco';
$config['os'][$os]['text'] = 'TelePresence Conductor';
$config['os'][$os]['type'] = 'collaboration';
$config['os'][$os]['icon'] = 'cisco';
$os = 'cimc';
$config['os'][$os]['text'] = 'Cisco Integrated Management Controller';
$config['os'][$os]['type'] = 'server';
$config['os'][$os]['icon'] = 'cisco';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Device Traffic';
$config['os'][$os]['over'][1]['graph'] = 'device_processor';
$config['os'][$os]['over'][1]['text'] = 'CPU Usage';
$config['os'][$os]['over'][2]['graph'] = 'device_mempool';
$config['os'][$os]['over'][2]['text'] = 'Memory Usage';
// Brocade NOS
$os = 'nos';
@@ -1018,7 +1037,7 @@ $config['os'][$os]['type'] = 'network';
$config['os'][$os]['icon'] = 'avaya';
$os = 'avaya-vsp';
$config['os'][$os]['text'] = 'Avaya VSP';
$config['os'][$os]['text'] = 'Avaya VOSS';
$config['os'][$os]['type'] = 'network';
$config['os'][$os]['icon'] = 'avaya';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
@@ -1493,6 +1512,15 @@ $config['os'][$os]['icon'] = 'ricoh';
$config['os'][$os]['over'][0]['graph'] = 'device_toner';
$config['os'][$os]['over'][0]['text'] = 'Toner';
// lanier is a rebadged ricoh
$os = 'lanier';
$config['os'][$os]['group'] = 'printer';
$config['os'][$os]['text'] = 'Lanier Printer';
$config['os'][$os]['type'] = 'printer';
$config['os'][$os]['icon'] = 'lanier';
$config['os'][$os]['over'][0]['graph'] = 'device_toner';
$config['os'][$os]['over'][0]['text'] = 'Toner';
$os = 'nrg';
$config['os'][$os]['group'] = 'printer';
$config['os'][$os]['text'] = 'NRG Printer';
@@ -1526,13 +1554,6 @@ $config['os'][$os]['icon'] = 'hp';
$config['os'][$os]['over'][0]['graph'] = 'device_toner';
$config['os'][$os]['over'][0]['text'] = 'Toner';
$os = 'richoh';
$config['os'][$os]['group'] = 'printer';
$config['os'][$os]['text'] = 'Ricoh Printer';
$config['os'][$os]['type'] = 'printer';
$config['os'][$os]['over'][0]['graph'] = 'device_toner';
$config['os'][$os]['over'][0]['text'] = 'Toner';
$os = 'okilan';
$config['os'][$os]['group'] = 'printer';
$config['os'][$os]['text'] = 'OKI Printer';
@@ -1728,6 +1749,10 @@ $config['os'][$os]['icon'] = 'ubiquiti';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Device Traffic';
$config['os'][$os]['ifname'] = 1;
$config['os'][$os]['over'][1]['graph'] = 'device_processor';
$config['os'][$os]['over'][1]['text'] = 'CPU Usage';
$config['os'][$os]['over'][2]['graph'] = 'device_mempool';
$config['os'][$os]['over'][2]['text'] = 'Memory Usage';
// Fiberhome
$os = 'fiberhome';
@@ -2015,6 +2040,17 @@ $config['os'][$os]['text'] = 'Sonus SBC';
$config['os'][$os]['type'] = 'appliance';
$config['os'][$os]['icon'] = 'sonus';
// Fujitsu Primergy Switch
$os = 'fujitsupyos';
$config['os'][$os]['text'] = 'Fujitsu';
$config['os'][$os]['type'] = 'network';
$config['os'][$os]['icon'] = 'fujitsu';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Device Traffic';
$config['os'][$os]['over'][1]['graph'] = 'device_processor';
$config['os'][$os]['over'][1]['text'] = 'CPU Usage';
$config['os'][$os]['over'][2]['graph'] = 'device_mempool';
$config['os'][$os]['over'][2]['text'] = 'Memory Usage';
// Graph Types
require_once $config['install_dir'].'/includes/load_db_graph_types.inc.php';
+29 -32
View File
@@ -76,10 +76,11 @@ function EditDeviceGroup($group_id, $name = null, $desc = null, $pattern = null)
* @param string $search What to searchid for
* @return string
*/
function GenGroupSQL($pattern, $search='',$extra=0) {
function GenGroupSQL($pattern, $search = '', $extra = 0)
{
$pattern = RunGroupMacros($pattern);
if ($pattern === false) {
return false;
return false;
}
$tmp = explode(' ', $pattern);
$tables = array();
@@ -96,33 +97,32 @@ function GenGroupSQL($pattern, $search='',$extra=0) {
$pattern = rtrim($pattern, '||');
$tables = array_keys(array_flip($tables));
if( dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?',array($tables[0],'device_id')) != 1 ) {
if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', array($tables[0],'device_id')) != 1) {
//Our first table has no valid glue, append the 'devices' table to it!
array_unshift($tables, 'devices');
}
$x = sizeof($tables)-1;
$i = 0;
$join = "";
while( $i < $x ) {
if( isset($tables[$i+1]) ) {
$gtmp = ResolveGlues(array($tables[$i+1]),'device_id');
if( $gtmp === false ) {
while ($i < $x) {
if (isset($tables[$i+1])) {
$gtmp = ResolveGlues(array($tables[$i+1]), 'device_id');
if ($gtmp === false) {
//Cannot resolve glue-chain. Rule is invalid.
return false;
}
$last = "";
$qry = "";
foreach( $gtmp as $glue ) {
if( empty($last) ) {
list($tmp,$last) = explode('.',$glue);
foreach ($gtmp as $glue) {
if (empty($last)) {
list($tmp,$last) = explode('.', $glue);
$qry .= $glue.' = ';
}
else {
list($tmp,$new) = explode('.',$glue);
} else {
list($tmp,$new) = explode('.', $glue);
$qry .= $tmp.'.'.$last.' && '.$tmp.'.'.$new.' = ';
$last = $new;
}
if( !in_array($tmp, $tables) ) {
if (!in_array($tmp, $tables)) {
$tables[] = $tmp;
}
}
@@ -134,14 +134,13 @@ function GenGroupSQL($pattern, $search='',$extra=0) {
$sql_extra = ",`devices`.*";
}
if (!empty($search)) {
$search = str_replace("(","",$tables[0]).'.'.$search. ' AND';
$search = str_replace("(", "", $tables[0]).'.'.$search. ' AND';
}
if (!empty($join)) {
$join = '('.rtrim($join, ' && ').') &&';
}
$sql = 'SELECT DISTINCT('.str_replace('(', '', $tables[0]).'.device_id)'.$sql_extra.' FROM '.implode(',', $tables).' WHERE '.$join.' '.$search.' ('.str_replace(array('%', '@', '!~', '~'), array('', '.*', 'NOT REGEXP', 'REGEXP'), $pattern).')';
return $sql;
}//end GenGroupSQL()
@@ -160,7 +159,6 @@ function QueryDevicesFromGroup($group_id)
}
return false;
}//end QueryDevicesFromGroup()
/**
@@ -183,9 +181,9 @@ function GetDevicesFromGroup($group_id, $nested = false)
* Get all Device-Groups
* @return array
*/
function GetDeviceGroups() {
function GetDeviceGroups()
{
return dbFetchRows('SELECT * FROM device_groups ORDER BY name');
}//end GetDeviceGroups()
/**
@@ -194,21 +192,20 @@ function GetDeviceGroups() {
* @param int $extra Return extra info about the groups (name, desc, pattern)
* @return array
*/
function QueryGroupsFromDevice($device_id,$extra=0) {
function QueryGroupsFromDevice($device_id, $extra = 0)
{
$ret = array();
foreach (GetDeviceGroups() as $group) {
if (dbFetchCell(GenGroupSQL($group['pattern'], 'device_id=?',$extra).' LIMIT 1', array($device_id)) == $device_id) {
if (dbFetchCell(GenGroupSQL($group['pattern'], 'device_id=?', $extra).' LIMIT 1', array($device_id)) == $device_id) {
if ($extra === 0) {
$ret[] = $group['id'];
}
else {
} else {
$ret[] = $group;
}
}
}
return $ret;
}//end QueryGroupsFromDevice()
/**
@@ -234,17 +231,18 @@ function GetGroupsFromDevice($device_id, $extra = 0)
* @param int $x Recursion-Anchor
* @return string|boolean
*/
function RunGroupMacros($rule,$x=1) {
function RunGroupMacros($rule, $x = 1)
{
global $config;
krsort($config['alert']['macros']['group']);
foreach( $config['alert']['macros']['group'] as $macro=>$value ) {
if( !strstr($macro," ") ) {
$rule = str_replace('%macros.'.$macro,'('.$value.')',$rule);
foreach ($config['alert']['macros']['group'] as $macro => $value) {
if (!strstr($macro, " ")) {
$rule = str_replace('%macros.'.$macro, '('.$value.')', $rule);
}
}
if( strstr($rule,"%macros") ) {
if( ++$x < 30 ) {
$rule = RunGroupMacros($rule,$x);
if (strstr($rule, "%macros")) {
if (++$x < 30) {
$rule = RunGroupMacros($rule, $x);
} else {
return false;
}
@@ -279,7 +277,6 @@ function UpdateGroupsForDevice($device_id)
if (!empty($removed_groups)) {
dbDelete('device_group_device', '`device_id`=? AND `device_group_id` IN (?)', array($device_id, array(implode(',', $removed_groups))));
}
}
/**
+59 -61
View File
@@ -2,90 +2,88 @@
unset($mac_table);
if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) {
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
}
else {
} else {
$vrfs_lite_cisco = array(array('context_name'=>null));
}
foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name']=$vrf['context_name'];
$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB');
$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data));
$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data));
$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB');
$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data));
$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data));
foreach (explode("\n", $ipNetToMedia_data) as $data) {
list($oid, $mac) = explode(' ', $data);
list($if, $first, $second, $third, $fourth) = explode('.', $oid);
$ip = $first.'.'.$second.'.'.$third.'.'.$fourth;
if ($ip != '...') {
$interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if));
foreach (explode("\n", $ipNetToMedia_data) as $data) {
list($oid, $mac) = explode(' ', $data);
list($if, $first, $second, $third, $fourth) = explode('.', $oid);
$ip = $first.'.'.$second.'.'.$third.'.'.$fourth;
if ($ip != '...') {
$interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if));
list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac);
$m_a = zeropad($m_a);
$m_b = zeropad($m_b);
$m_c = zeropad($m_c);
$m_d = zeropad($m_d);
$m_e = zeropad($m_e);
$m_f = zeropad($m_f);
$md_a = hexdec($m_a);
$md_b = hexdec($m_b);
$md_c = hexdec($m_c);
$md_d = hexdec($m_d);
$md_e = hexdec($m_e);
$md_f = hexdec($m_f);
$mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f";
list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac);
$m_a = zeropad($m_a);
$m_b = zeropad($m_b);
$m_c = zeropad($m_c);
$m_d = zeropad($m_d);
$m_e = zeropad($m_e);
$m_f = zeropad($m_f);
$md_a = hexdec($m_a);
$md_b = hexdec($m_b);
$md_c = hexdec($m_c);
$md_d = hexdec($m_d);
$md_e = hexdec($m_e);
$md_f = hexdec($m_f);
$mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f";
$mac_table[$if][$mac]['ip'] = $ip;
$mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f";
$clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f;
$mac_table[$if][$mac]['cleanmac'] = $clean_mac;
$port_id = $interface['port_id'];
$mac_table[$port_id][$clean_mac] = 1;
$mac_table[$if][$mac]['ip'] = $ip;
$mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f";
$clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f;
$mac_table[$if][$mac]['cleanmac'] = $clean_mac;
$port_id = $interface['port_id'];
$mac_table[$port_id][$clean_mac] = 1;
if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) {
// Commented below, no longer needed but leaving for reference.
// $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'";
$old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id']));
if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) {
// Commented below, no longer needed but leaving for reference.
// $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'";
$old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id']));
if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n");
if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n");
log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']);
}
log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']);
}
dbUpdate(array('mac_address' => $clean_mac, 'context_name' => $device['context_name']), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip));
echo '.';
}
else if (isset($interface['port_id'])) {
echo '+';
// echo("Add MAC $mac\n");
$insert_data = array(
dbUpdate(array('mac_address' => $clean_mac, 'context_name' => $device['context_name']), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip));
echo '.';
} elseif (isset($interface['port_id'])) {
echo '+';
// echo("Add MAC $mac\n");
$insert_data = array(
'port_id' => $interface['port_id'],
'mac_address' => $clean_mac,
'ipv4_address' => $ip,
'context_name' => $device['context_name'],
);
dbInsert($insert_data, 'ipv4_mac');
dbInsert($insert_data, 'ipv4_mac');
}//end if
}//end if
}//end if
}//end foreach
}//end foreach
$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'";
foreach (dbFetchRows($sql) as $entry) {
$entry_mac = $entry['mac_address'];
$entry_if = $entry['port_id'];
if (!$mac_table[$entry_if][$entry_mac]) {
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac));
d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']);
$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'";
foreach (dbFetchRows($sql) as $entry) {
$entry_mac = $entry['mac_address'];
$entry_if = $entry['port_id'];
if (!$mac_table[$entry_if][$entry_mac]) {
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac));
d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']);
echo '-';
echo '-';
}
}
}
echo "\n";
unset($mac);
echo "\n";
unset($mac);
unset($device['context_name']);
}
unset($vrfs_c);
+194 -199
View File
@@ -2,10 +2,9 @@
if ($config['enable_bgp']) {
// Discover BGP peers
if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) {
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
}
else{
} else {
$vrfs_lite_cisco = array(array('context_name'=>null));
}
@@ -13,232 +12,228 @@ if ($config['enable_bgp']) {
foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name'] = $vrf['context_name'];
if (is_numeric($bgpLocalAs)) {
echo "AS$bgpLocalAs ";
if ($bgpLocalAs != $device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id']));
echo 'Updated AS ';
if (is_numeric($bgpLocalAs)) {
echo "AS$bgpLocalAs ";
if ($bgpLocalAs != $device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id']));
echo 'Updated AS ';
}
$peer2 = false;
if ($device['os'] !== 'junos') {
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']);
if (empty($peers_data)) {
$peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']);
} else {
$peer2 = true;
}
$peer2 = false;
if ($device['os'] !== 'junos') {
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']);
if (empty($peers_data)) {
$peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']);
}
else {
$peer2 = true;
d_echo("Peers : $peers_data \n");
$peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data));
$peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers));
foreach (explode("\n", $peers) as $peer) {
if ($peer2 === true) {
list($ver, $peer) = explode('.', $peer, 2);
}
d_echo("Peers : $peers_data \n");
list($peer_ip, $peer_as) = explode(' ', $peer);
if (strstr($peer_ip, ':')) {
$peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip);
$peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp);
$peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip));
}
$peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data));
$peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers));
if ($peer && $peer_ip != '0.0.0.0') {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
'ver' => $ver,
);
}
}
} elseif ($device['os'] == 'junos') {
// Juniper BGP4-V2 MIB
// FIXME: needs a big cleanup! also see below.
// FIXME: is .0.ipv6 the only possible value here?
$result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
$peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.', '', $result));
foreach (explode("\n", $peers) as $peer) {
list($peer_ip_snmp, $peer_as) = explode(' ', $peer);
// Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs.
$octets = count(explode(".", $peer_ip_snmp));
if ($octets > 11) {
// ipv6
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16)))));
} else {
// ipv4
$peer_ip = implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 4)));
}
if ($peer) {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
);
}
}
}
} else {
echo 'No BGP on host';
if ($device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id']));
echo ' (Removed ASN) ';
}
}
// Process disovered peers
if (isset($peerlist)) {
foreach ($peerlist as $peer) {
$astext = get_astext($peer['as']);
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') {
$add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'], 'context_name' => $device['context_name']), 'bgpPeers');
if ($config['autodiscovery']['bgp'] === true) {
$name = gethostbyaddr($peer['ip']);
$remote_device_id = discover_new_device($name, $device, 'BGP');
}
echo '+';
} else {
$update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip']));
echo '.';
}
if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') {
if ($device['os_group'] == 'cisco') {
// Get afi/safi and populate cbgp on cisco ios (xe/xr)
unset($af_list);
foreach (explode("\n", $peers) as $peer) {
if ($peer2 === true) {
list($ver, $peer) = explode('.', $peer, 2);
}
list($peer_ip, $peer_as) = explode(' ', $peer);
if (strstr($peer_ip, ':')) {
$peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip);
$peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp);
$peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip));
}
if ($peer && $peer_ip != '0.0.0.0') {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
'ver' => $ver,
);
}
}
} elseif ($device['os'] == 'junos') {
// Juniper BGP4-V2 MIB
// FIXME: needs a big cleanup! also see below.
// FIXME: is .0.ipv6 the only possible value here?
$result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
$peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.', '', $result));
foreach (explode("\n", $peers) as $peer) {
list($peer_ip_snmp, $peer_as) = explode(' ', $peer);
// Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs.
$octets = count(explode(".", $peer_ip_snmp));
if ($octets > 11) {
// ipv6
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16)))));
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
} else {
// ipv4
$peer_ip = implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 4)));
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
}
if ($peer) {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
);
}
}
}
}
else {
echo 'No BGP on host';
if ($device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id']));
echo ' (Removed ASN) ';
}
}
// Process disovered peers
if (isset($peerlist)) {
foreach ($peerlist as $peer) {
$astext = get_astext($peer['as']);
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') {
$add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'], 'context_name' => $device['context_name']), 'bgpPeers');
if ($config['autodiscovery']['bgp'] === true) {
$name = gethostbyaddr($peer['ip']);
$remote_device_id = discover_new_device($name, $device, 'BGP');
}
echo '+';
}
else {
$update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip']));
echo '.';
}
if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') {
if ($device['os_group'] == 'cisco') {
// Get afi/safi and populate cbgp on cisco ios (xe/xr)
unset($af_list);
d_echo('afi data :: ');
d_echo($af_data);
foreach ($af_data as $k => $v) {
if ($peer2 === true) {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
}
else {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
list(,$k) = explode('.', $k, 2);
}
d_echo('afi data :: ');
d_echo($af_data);
d_echo("AFISAFI = $k\n");
foreach ($af_data as $k => $v) {
if ($peer2 === true) {
list(,$k) = explode('.', $k, 2);
}
d_echo("AFISAFI = $k\n");
$afisafi_tmp = explode('.', $k);
$safi = array_pop($afisafi_tmp);
$afi = array_pop($afisafi_tmp);
$bgp_ip = str_replace(".$afi.$safi", '', $k);
$bgp_ip = preg_replace('/:/', ' ', $bgp_ip);
$bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip);
$bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip));
if ($afi && $safi && $bgp_ip == $peer['ip']) {
$af_list[$bgp_ip][$afi][$safi] = 1;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) {
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp');
}
}
}
}
if ($device['os'] == 'junos') {
$safis[1] = 'unicast';
$safis[2] = 'multicast';
if (!isset($j_peerIndexes)) {
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerEntry', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
print_r($j_bgp);
foreach ($j_bgp as $index => $entry) {
switch ($entry['jnxBgpM2PeerRemoteAddrType']) {
case 'ipv4':
$ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr']));
d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex'];
break;
case 'ipv6':
$ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"');
$ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4);
$ip6 = Net_IPv6::compress($ip6);
d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex'];
break;
default:
echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n";
break;
}
}
}
if (!isset($j_afisafi)) {
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
foreach (array_keys($j_prefixes) as $key) {
list($index,$afisafi) = explode('.', $key, 2);
$j_afisafi[$index][] = $afisafi;
}
}
foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) {
list ($afi,$safi) = explode('.', $afisafi);
$safi = $safis[$safi];
$af_list[$afi][$safi] = 1;
$afisafi_tmp = explode('.', $k);
$safi = array_pop($afisafi_tmp);
$afi = array_pop($afisafi_tmp);
$bgp_ip = str_replace(".$afi.$safi", '', $k);
$bgp_ip = preg_replace('/:/', ' ', $bgp_ip);
$bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip);
$bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip));
if ($afi && $safi && $bgp_ip == $peer['ip']) {
$af_list[$bgp_ip][$afi][$safi] = 1;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) {
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp');
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp');
}
}
}
$af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'";
foreach (dbFetchRows($af_query) as $entry) {
$afi = $entry['afi'];
$safi = $entry['safi'];
if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi));
}
}
}
}
unset($j_afisafi);
unset($j_prefixes);
unset($j_bgp);
unset($j_peerIndexes);
if ($device['os'] == 'junos') {
$safis[1] = 'unicast';
$safis[2] = 'multicast';
if (!isset($j_peerIndexes)) {
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerEntry', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
print_r($j_bgp);
foreach ($j_bgp as $index => $entry) {
switch ($entry['jnxBgpM2PeerRemoteAddrType']) {
case 'ipv4':
$ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr']));
d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex'];
break;
case 'ipv6':
$ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"');
$ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4);
$ip6 = Net_IPv6::compress($ip6);
d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex'];
break;
default:
echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n";
break;
}
}
}
if (!isset($j_afisafi)) {
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
foreach (array_keys($j_prefixes) as $key) {
list($index,$afisafi) = explode('.', $key, 2);
$j_afisafi[$index][] = $afisafi;
}
}
foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) {
list ($afi,$safi) = explode('.', $afisafi);
$safi = $safis[$safi];
$af_list[$afi][$safi] = 1;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) {
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp');
}
}
}
$af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'";
foreach (dbFetchRows($af_query) as $entry) {
$afi = $entry['afi'];
$safi = $entry['safi'];
if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi));
}
}
}
}
unset($j_afisafi);
unset($j_prefixes);
unset($j_bgp);
unset($j_peerIndexes);
}
// Delete removed peers
$sql = "SELECT * FROM bgpPeers WHERE device_id = '".$device['device_id']."' AND context_name = '".$device['context_name']."'";
foreach (dbFetchRows($sql) as $entry) {
unset($exists);
$i = 0;
while ($i < count($peerlist) && !isset($exists)) {
if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) {
$exists = 1;
}
$i++;
foreach (dbFetchRows($sql) as $entry) {
unset($exists);
$i = 0;
while ($i < count($peerlist) && !isset($exists)) {
if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) {
$exists = 1;
}
if (!isset($exists)) {
dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
echo '-';
}
$i++;
}
if (!isset($exists)) {
dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
echo '-';
}
}
unset($peerlist);
echo "\n";

Some files were not shown because too many files have changed in this diff Show More