Apply fixes from StyleCI (#12120)

This commit is contained in:
Jellyfrog
2020-09-21 15:40:17 +02:00
committed by GitHub
parent 77c531527c
commit 82f43cb98d
1733 changed files with 18337 additions and 18540 deletions

View File

@ -208,6 +208,7 @@ class CiHelper
// Disabled in favor of styleci
echo "Style check disabled.\n";
return 0;
$cs_cmd = [

View File

@ -7,13 +7,11 @@ function format_bytes_billing($value)
return format_number($value, Config::get('billing.base')) . 'B';
}//end format_bytes_billing()
function format_bytes_billing_short($value)
{
return format_number($value, Config::get('billing.base'), 2, 3);
}//end format_bytes_billing_short()
function getDates($dayofmonth, $months = 0)
{
$dayofmonth = zeropad($dayofmonth);
@ -49,31 +47,31 @@ function getDates($dayofmonth, $months = 0)
$last_from = date_format($date_start, 'Ymd') . '000000';
$last_to = date_format($date_end, 'Ymd') . '235959';
$return = array();
$return = [];
$return['0'] = $date_from;
$return['1'] = $date_to;
$return['2'] = $last_from;
$return['3'] = $last_to;
return ($return);
return $return;
}//end getDates()
function getPredictedUsage($bill_day, $cur_used)
{
$tmp = getDates($bill_day, 0);
$start = new DateTime($tmp[0], new DateTimeZone(date_default_timezone_get()));
$end = new DateTime($tmp[1], new DateTimeZone(date_default_timezone_get()));
$now = new DateTime(date("Y-m-d"), new DateTimeZone(date_default_timezone_get()));
$total = $end->diff($start)->format("%a");
$since = $now->diff($start)->format("%a");
return($cur_used/$since*$total);
return $cur_used / $since * $total;
}
function getValue($host, $port, $id, $inout)
{
$oid = 'IF-MIB::ifHC' . $inout . 'Octets.' . $id;
$device = dbFetchRow("SELECT * from `devices` WHERE `hostname` = ? LIMIT 1", array($host));
$device = dbFetchRow("SELECT * from `devices` WHERE `hostname` = ? LIMIT 1", [$host]);
$value = snmp_get($device, $oid, '-Oqv');
if (! is_numeric($value)) {
@ -86,8 +84,8 @@ function getValue($host, $port, $id, $inout)
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));
$return = [];
$row = dbFetchRow("SELECT timestamp, in_counter, in_delta, out_counter, out_delta FROM bill_port_counters WHERE `port_id` = ? AND `bill_id` = ?", [$port_id, $bill_id]);
if (! is_null($row)) {
$return['timestamp'] = $row['timestamp'];
$return['in_counter'] = $row['in_counter'];
@ -98,14 +96,14 @@ function getLastPortCounter($port_id, $bill_id)
} else {
$return['state'] = 'failed';
}
return $return;
}//end getLastPortCounter()
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));
$return = [];
$row = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id = ? ORDER BY timestamp DESC LIMIT 1", [$bill_id]);
if (! is_null($row)) {
$return['delta'] = $row['delta'];
$return['delta_in'] = $row['delta_in'];
@ -115,57 +113,55 @@ function getLastMeasurement($bill_id)
} else {
$return['state'] = 'failed';
}
return ($return);
return $return;
}//end getLastMeasurement()
function get95thagg($bill_id, $datefrom, $dateto)
{
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
$mq_sql .= " AND timestamp > ? AND timestamp <= ?";
$measurements = dbFetchCell($mq_sql, array($bill_id, $datefrom, $dateto));
$measurements = dbFetchCell($mq_sql, [$bill_id, $datefrom, $dateto]);
$measurement_95th = (round(($measurements / 100 * 95)) - 1);
$q_95_sql = "SELECT (delta / period * 8) AS rate FROM bill_data WHERE bill_id = ?";
$q_95_sql .= " AND timestamp > ? AND timestamp <= ? ORDER BY rate ASC";
$a_95th = dbFetchColumn($q_95_sql, array($bill_id, $datefrom, $dateto));
$a_95th = dbFetchColumn($q_95_sql, [$bill_id, $datefrom, $dateto]);
$m_95th = $a_95th[$measurement_95th];
return (round($m_95th, 2));
return round($m_95th, 2);
}//end get95thagg()
function get95thIn($bill_id, $datefrom, $dateto)
{
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
$mq_sql .= " AND timestamp > ? AND timestamp <= ?";
$measurements = dbFetchCell($mq_sql, array($bill_id, $datefrom, $dateto));
$measurements = dbFetchCell($mq_sql, [$bill_id, $datefrom, $dateto]);
$measurement_95th = (round(($measurements / 100 * 95)) - 1);
$q_95_sql = "SELECT (in_delta / period * 8) AS rate FROM bill_data WHERE bill_id = ?";
$q_95_sql .= " AND timestamp > ? AND timestamp <= ? ORDER BY rate ASC";
$a_95th = dbFetchColumn($q_95_sql, array($bill_id, $datefrom, $dateto));
$a_95th = dbFetchColumn($q_95_sql, [$bill_id, $datefrom, $dateto]);
$m_95th = $a_95th[$measurement_95th];
return (round($m_95th, 2));
return round($m_95th, 2);
}//end get95thIn()
function get95thout($bill_id, $datefrom, $dateto)
{
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
$mq_sql .= " AND timestamp > ? AND timestamp <= ?";
$measurements = dbFetchCell($mq_sql, array($bill_id, $datefrom, $dateto));
$measurements = dbFetchCell($mq_sql, [$bill_id, $datefrom, $dateto]);
$measurement_95th = (round(($measurements / 100 * 95)) - 1);
$q_95_sql = "SELECT (out_delta / period * 8) AS rate FROM bill_data WHERE bill_id = ?";
$q_95_sql .= " AND timestamp > ? AND timestamp <= ? ORDER BY rate ASC";
$a_95th = dbFetchColumn($q_95_sql, array($bill_id, $datefrom, $dateto));
$a_95th = dbFetchColumn($q_95_sql, [$bill_id, $datefrom, $dateto]);
$m_95th = $a_95th[$measurement_95th];
return (round($m_95th, 2));
return round($m_95th, 2);
}//end get95thout()
function getRates($bill_id, $datefrom, $dateto, $dir_95th)
{
$data = [];
@ -200,33 +196,33 @@ function getRates($bill_id, $datefrom, $dateto, $dir_95th)
$data['rate_average_out'] = ($mtot_out / $ptot * 8);
// print_r($data);
return ($data);
return $data;
}//end getRates()
function getTotal($bill_id, $datefrom, $dateto)
{
$mtot = dbFetchCell("SELECT SUM(delta) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", array($bill_id, $datefrom, $dateto));
return ($mtot);
}//end getTotal()
$mtot = dbFetchCell("SELECT SUM(delta) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", [$bill_id, $datefrom, $dateto]);
return $mtot;
}//end getTotal()
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 = ? AND timestamp > ? AND timestamp <= ?", array($bill_id, $datefrom, $dateto));
return ($sum);
}//end getSum()
$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 = ? AND timestamp > ? AND timestamp <= ?", [$bill_id, $datefrom, $dateto]);
return $sum;
}//end getSum()
function getPeriod($bill_id, $datefrom, $dateto)
{
$ptot = dbFetchCell("SELECT SUM(period) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", array($bill_id, $datefrom, $dateto));
return ($ptot);
$ptot = dbFetchCell("SELECT SUM(period) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", [$bill_id, $datefrom, $dateto]);
return $ptot;
}//end getPeriod()
function getBillingHistoryBitsGraphData($bill_id, $bill_hist_id, $reducefactor)
{
$histrow = dbFetchRow('SELECT UNIX_TIMESTAMP(bill_datefrom) as `from`, UNIX_TIMESTAMP(bill_dateto) AS `to`, rate_95th, rate_average, bill_type FROM bill_history WHERE bill_id = ? AND bill_hist_id = ?', array($bill_id, $bill_hist_id));
$histrow = dbFetchRow('SELECT UNIX_TIMESTAMP(bill_datefrom) as `from`, UNIX_TIMESTAMP(bill_dateto) AS `to`, rate_95th, rate_average, bill_type FROM bill_history WHERE bill_id = ? AND bill_hist_id = ?', [$bill_id, $bill_hist_id]);
if (is_null($histrow)) {
return null;
@ -259,10 +255,10 @@ function getBillingBitsGraphData($bill_id, $from, $to, $reducefactor)
$in_delta = null;
$out_delta = null;
$period = null;
$in_data = array();
$out_data = array();
$tot_data = array();
$ticks = array();
$in_data = [];
$out_data = [];
$tot_data = [];
$ticks = [];
if (! isset($reducefactor) || ! is_numeric($reducefactor) || $reducefactor < 1) {
// Auto calculate reduce factor
@ -271,9 +267,9 @@ function getBillingBitsGraphData($bill_id, $from, $to, $reducefactor)
$reducefactor = max(1, floor($expectedpoints / $desiredpoints));
}
$bill_data = dbFetchRow('SELECT * from `bills` WHERE `bill_id`= ? LIMIT 1', array($bill_id));
$bill_data = dbFetchRow('SELECT * from `bills` WHERE `bill_id`= ? LIMIT 1', [$bill_id]);
foreach (dbFetch('SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = ? AND `timestamp` >= FROM_UNIXTIME( ? ) AND `timestamp` <= FROM_UNIXTIME( ? ) ORDER BY timestamp ASC', array($bill_id, $from, $to)) as $row) {
foreach (dbFetch('SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = ? AND `timestamp` >= FROM_UNIXTIME( ? ) AND `timestamp` <= FROM_UNIXTIME( ? ) ORDER BY timestamp ASC', [$bill_id, $from, $to]) as $row) {
$timestamp = $row['formatted_date'];
if (! $first) {
$first = $timestamp;
@ -314,7 +310,7 @@ function getBillingBitsGraphData($bill_id, $from, $to, $reducefactor)
$ticks[$i] = $timestamp;
$i++;
}
$result = array(
$result = [
'from' => $from,
'to' => $to,
'first' => $first,
@ -327,8 +323,8 @@ function getBillingBitsGraphData($bill_id, $from, $to, $reducefactor)
'rate_95th' => $bill_data['rate_95th'],
'rate_average' => $bill_data['rate_average'],
'bill_type' => $bill_data['bill_type']
);
'bill_type' => $bill_data['bill_type'],
];
if ($period) {
$result['max_in'] = $max_in;
@ -338,6 +334,7 @@ function getBillingBitsGraphData($bill_id, $from, $to, $reducefactor)
$result['last_in'] = $in_delta / $period;
$result['last_out'] = $out_delta / $period;
}
return $result;
}//end getBillingBitsGraphData
@ -345,16 +342,16 @@ function getHistoricTransferGraphData($bill_id)
{
$i = '0';
$in_data = array();
$out_data = array();
$tot_data = array();
$allow_data = array();
$ave_data = array();
$overuse_data = array();
$ticklabels = array();
$in_data = [];
$out_data = [];
$tot_data = [];
$allow_data = [];
$ave_data = [];
$overuse_data = [];
$ticklabels = [];
$allowed_val = null;
foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12', array($bill_id)) as $data) {
foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12', [$bill_id]) as $data) {
$datefrom = strftime('%Y-%m-%d', strtotime($data['bill_datefrom']));
$dateto = strftime('%Y-%m-%d', strtotime($data['bill_dateto']));
$datelabel = $datefrom . " - " . $dateto;
@ -383,7 +380,7 @@ function getHistoricTransferGraphData($bill_id)
$graph_name = 'Historical bandwidth over the last 12 billing periods';
return array(
return [
'graph_name' => $graph_name,
'in_data' => $in_data,
'out_data' => $out_data,
@ -391,14 +388,14 @@ function getHistoricTransferGraphData($bill_id)
'allow_data' => $allow_data,
'ave_data' => $ave_data,
'overuse_data' => $overuse_data,
'ticklabels' => $ticklabels
);
'ticklabels' => $ticklabels,
];
}
function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgtype)
{
if (is_numeric($bill_hist_id)) {
$histrow = dbFetchRow('SELECT UNIX_TIMESTAMP(bill_datefrom) as `from`, UNIX_TIMESTAMP(bill_dateto) AS `to`, rate_95th, rate_average FROM bill_history WHERE bill_id = ? AND bill_hist_id = ?', array($bill_id, $bill_hist_id));
$histrow = dbFetchRow('SELECT UNIX_TIMESTAMP(bill_datefrom) as `from`, UNIX_TIMESTAMP(bill_dateto) AS `to`, rate_95th, rate_average FROM bill_history WHERE bill_id = ? AND bill_hist_id = ?', [$bill_id, $bill_hist_id]);
if (is_null($histrow)) {
return null;
@ -407,22 +404,22 @@ function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgt
$to = $histrow['to'];
} else {
if (! is_numeric($from) || ! is_numeric($to)) {
die('Must supply from and to if bill_hist_id is not supplied');
exit('Must supply from and to if bill_hist_id is not supplied');
}
}
$in_data = array();
$out_data = array();
$tot_data = array();
$allow_data = array();
$ave_data = array();
$overuse_data = array();
$ticklabels = array();
$in_data = [];
$out_data = [];
$tot_data = [];
$allow_data = [];
$ave_data = [];
$overuse_data = [];
$ticklabels = [];
$data = array();
$data = [];
$average = 0;
if ($imgtype == 'day') {
foreach (dbFetch('SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC', array($bill_id, $from, $to)) as $data) {
foreach (dbFetch('SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC', [$bill_id, $from, $to]) as $data) {
array_push($ticklabels, strftime("%Y-%m-%d", $data['timestamp']));
array_push($in_data, isset($data['traf_in']) ? $data['traf_in'] : 0);
array_push($out_data, isset($data['traf_out']) ? $data['traf_out'] : 0);
@ -441,7 +438,7 @@ function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgt
array_push($tot_data, 0);
}
} elseif ($imgtype == 'hour') {
foreach (dbFetch('SELECT DISTINCT HOUR(timestamp) as hour, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY HOUR(timestamp) ASC', array($bill_id, $from, $to)) as $data) {
foreach (dbFetch('SELECT DISTINCT HOUR(timestamp) as hour, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY HOUR(timestamp) ASC', [$bill_id, $from, $to]) as $data) {
array_push($ticklabels, sprintf('%02d', $data['hour']) . ":00");
array_push($in_data, isset($data['traf_in']) ? $data['traf_in'] : 0);
array_push($out_data, isset($data['traf_out']) ? $data['traf_out'] : 0);
@ -451,7 +448,7 @@ function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgt
$ave_count = count($tot_data);
} else {
die("Unknown graph type $imgtype");
exit("Unknown graph type $imgtype");
}//end if
$average = ($average / $ave_count);
@ -462,7 +459,7 @@ function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgt
$graph_name = date('M j g:ia', $from) . ' - ' . date('M j g:ia', $to);
return array(
return [
'graph_name' => $graph_name,
'in_data' => $in_data,
'out_data' => $out_data,
@ -470,7 +467,7 @@ function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgt
'allow_data' => $allow_data,
'ave_data' => $ave_data,
'overuse_data' => $overuse_data,
'ticklabels' => $ticklabels
);
'ticklabels' => $ticklabels,
];
}
//end getBillingBandwidthGraphData

View File

@ -1,13 +1,13 @@
<?php
if (Auth::user()->hasGlobalRead()) {
$data['active_count'] = array('query' => 'SELECT COUNT(`alerts`.`id`) FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id` RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE 1 AND `alerts`.`state` NOT IN (0,2) AND `devices`.`disabled` = 0 AND `devices`.`ignore` = 0');
$data['active_count'] = ['query' => 'SELECT COUNT(`alerts`.`id`) FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id` RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE 1 AND `alerts`.`state` NOT IN (0,2) AND `devices`.`disabled` = 0 AND `devices`.`ignore` = 0'];
} else {
$device_ids = Permissions::devicesForUser()->toArray() ?: [0];
$perms_sql = "`D`.`device_id` IN " . dbGenPlaceholders(count($device_ids));
$data['active_count'] = array(
$data['active_count'] = [
'query' => 'SELECT COUNT(`alerts`.`id`) FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id` RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE $perms_sql AND `alerts`.`state` NOT IN (0,2) AND `devices`.`disabled` = 0 AND `devices`.`ignore` = 0',
'params' => $device_ids
);
'params' => $device_ids,
];
}

View File

@ -1,41 +1,41 @@
<?php
if (Auth::user()->hasGlobalRead()) {
$data['count'] = array('query' => 'SELECT COUNT(*) FROM devices');
$data['count'] = ['query' => 'SELECT COUNT(*) FROM devices'];
$data['up'] = array('query' => "SELECT COUNT(*) FROM devices WHERE `status` = '1' AND `ignore` = '0' AND `disabled` = '0'",);
$data['up'] = ['query' => "SELECT COUNT(*) FROM devices WHERE `status` = '1' AND `ignore` = '0' AND `disabled` = '0'"];
$data['down'] = array('query' => "SELECT COUNT(*) FROM devices WHERE `status` = '0' AND `ignore` = '0' AND `disabled` = '0'");
$data['down'] = ['query' => "SELECT COUNT(*) FROM devices WHERE `status` = '0' AND `ignore` = '0' AND `disabled` = '0'"];
$data['ignored'] = array('query' => "SELECT COUNT(*) FROM devices WHERE `ignore` = '1' AND `disabled` = '0'");
$data['ignored'] = ['query' => "SELECT COUNT(*) FROM devices WHERE `ignore` = '1' AND `disabled` = '0'"];
$data['disabled'] = array('query' => "SELECT COUNT(*) FROM devices WHERE `disabled` = '1'");
$data['disabled'] = ['query' => "SELECT COUNT(*) FROM devices WHERE `disabled` = '1'"];
} else {
$device_ids = Permissions::devicesForUser()->toArray() ?: [0];
$perms_sql = "`D`.`device_id` IN " . dbGenPlaceholders(count($device_ids));
$data['count'] = array(
$data['count'] = [
'query' => 'SELECT COUNT(*) FROM devices AS D WHERE $perms_sql',
'params' => $device_ids
);
'params' => $device_ids,
];
$data['up'] = array(
$data['up'] = [
'query' => "SELECT COUNT(*) FROM devices AS D WHERE $perms_sql AND D.`status` = '1' AND D.`ignore` = '0' AND D.`disabled` = '0'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['down'] = array(
$data['down'] = [
'query' => "SELECT COUNT(*) FROM devices AS D WHERE $perms_sql AND D.`status` = '0' AND D.`ignore` = '0' AND D.`disabled` = '0'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['ignored'] = array(
$data['ignored'] = [
'query' => "SELECT COUNT(*) FROM devices AS D WHERE $perms_sql AND D.`ignore` = '1' AND D.`disabled` = '0'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['disabled'] = array(
$data['disabled'] = [
'query' => "SELECT COUNT(*) FROM devices AS D WHERE $perms_sql AND D.`disabled` = '1'",
'params' => $device_ids
);
'params' => $device_ids,
];
}//end if

View File

@ -21,26 +21,25 @@
* @package LibreNMS
* @subpackage Notifications
*/
$data['count'] = array(
$data['count'] = [
'query' => 'select count(notifications.notifications_id) from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?)',
'params' => array( Auth::id() )
);
'params' => [Auth::id()],
];
$data['unread'] = array(
$data['unread'] = [
'query' => 'select notifications.* from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?) order by notifications.notifications_id desc',
'params' => array( Auth::id() )
);
'params' => [Auth::id()],
];
$data['sticky'] = array(
$data['sticky'] = [
'query' => 'select notifications.*,notifications_attribs.user_id from notifications inner join notifications_attribs on notifications.notifications_id = notifications_attribs.notifications_id where notifications_attribs.key = "sticky" && notifications_attribs.value = 1 order by notifications_attribs.attrib_id desc',
);
];
$data['sticky_count'] = array(
$data['sticky_count'] = [
'query' => 'select count(notifications.notifications_id) from notifications inner join notifications_attribs on notifications.notifications_id = notifications_attribs.notifications_id where notifications_attribs.key = "sticky" && notifications_attribs.value = 1',
);
];
$data['read'] = array(
$data['read'] = [
'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( Auth::id() )
);
'params' => [Auth::id()],
];

View File

@ -1,48 +1,48 @@
<?php
if (Auth::user()->hasGlobalRead()) {
$data['count'] = array('query' => "SELECT COUNT(*) FROM ports WHERE `deleted` = '0'");
$data['count'] = ['query' => "SELECT COUNT(*) FROM ports WHERE `deleted` = '0'"];
$data['up'] = 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.`ifOperStatus` = 'up'",);
$data['up'] = ['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.`ifOperStatus` = 'up'"];
$data['down'] = 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.`ifOperStatus` <> 'up' AND I.`ifAdminStatus` = 'up'");
$data['down'] = ['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.`ifOperStatus` <> 'up' AND I.`ifAdminStatus` = 'up'"];
$data['shutdown'] = 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.`ifAdminStatus` = 'down'");
$data['shutdown'] = ['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.`ifAdminStatus` = 'down'"];
$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['errored'] = ['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')");
$data['ignored'] = ['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 {
$device_ids = Permissions::portsForUser()->toArray() ?: [0];
$perms_sql = "`I`.`port_id` IN " . dbGenPlaceholders(count($device_ids));
$data['count'] = array(
$data['count'] = [
'query' => "SELECT COUNT(*) FROM ports AS I WHERE $perms_sql AND I.`deleted` = '0'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['up'] = array(
$data['up'] = [
'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE $perms_sql AND I.`deleted` = '0' AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` = 'up'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['down'] = array(
$data['down'] = [
'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE $perms_sql AND I.`deleted` = '0' AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` <> 'up' AND I.`ifAdminStatus` = 'up'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['shutdown'] = array(
$data['shutdown'] = [
'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE $perms_sql AND I.`deleted` = '0' AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifAdminStatus` = 'down'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['errored'] = array(
$data['errored'] = [
'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE $perms_sql AND I.`deleted` = '0' AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['ignored'] = array(
$data['ignored'] = [
'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE $perms_sql AND I.`deleted` = '0' AND I.`device_id` = D.`device_id` AND (I.`ignore` = '1' OR D.`ignore` = '1')",
'params' => $device_ids
);
'params' => $device_ids,
];
}//end if

View File

@ -1,37 +1,37 @@
<?php
if (Auth::user()->hasGlobalRead()) {
$data['count'] = array( 'query' => 'SELECT COUNT(*) FROM services');
$data['up'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '0' AND `service_disabled` = '0' AND `service_status` = '0'");
$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'");
$data['count'] = ['query' => 'SELECT COUNT(*) FROM services'];
$data['up'] = ['query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '0' AND `service_disabled` = '0' AND `service_status` = '0'"];
$data['down'] = ['query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '0' AND `service_disabled` = '0' AND `service_status` = '2'"];
$data['ignored'] = ['query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '1' AND `service_disabled` = '0'"];
$data['disabled'] = ['query' => "SELECT COUNT(*) FROM services WHERE `service_disabled` = '1'"];
} else {
$device_ids = Permissions::devicesForUser()->toArray() ?: [0];
$perms_sql = "`S`.`device_id` IN " . dbGenPlaceholders(count($device_ids));
$data['count'] = array(
$data['count'] = [
'query' => 'SELECT COUNT(*) FROM services AS S WHERE $perms_sql',
'params' => $device_ids
);
'params' => $device_ids,
];
$data['up'] = array(
$data['up'] = [
'query' => "SELECT COUNT(*) FROM services AS S WHERE $perms_sql AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['down'] = array(
$data['down'] = [
'query' => "SELECT COUNT(*) FROM services AS S WHERE $perms_sql AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '2'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['ignored'] = array(
$data['ignored'] = [
'query' => "SELECT COUNT(*) FROM services AS S WHERE $perms_sql AND S.`service_ignore` = '1' AND S.`service_disabled` = '0'",
'params' => $device_ids
);
'params' => $device_ids,
];
$data['disabled'] = array(
$data['disabled'] = [
'query' => "SELECT COUNT(*) FROM services AS S WHERE $perms_sql AND S.`service_disabled` = '1'",
'params' => $device_ids
);
'params' => $device_ids,
];
}//end if

View File

@ -1,13 +1,13 @@
<?php
if (Auth::user()->hasGlobalRead()) {
$data['count'] = array('query' => "SELECT COUNT(`toner_id`) FROM toner");
$data['count'] = ['query' => "SELECT COUNT(`toner_id`) FROM toner"];
} else {
$device_ids = Permissions::devicesForUser()->toArray() ?: [0];
$perms_sql = "`toner`.`device_id` IN " . dbGenPlaceholders(count($device_ids));
$data['count'] = array(
$data['count'] = [
'query' => "SELECT COUNT(`toner_id`) FROM toner WHERE $perms_sql",
'params' => $device_ids
);
'params' => $device_ids,
];
}

View File

@ -15,13 +15,13 @@
$enabled = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'");
if ($enabled == 1) {
if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'") == '') {
dbInsert(array('name' => 'uuid', 'value' => guidv4(openssl_random_pseudo_bytes(16))), 'callback');
dbInsert(['name' => 'uuid', 'value' => guidv4(openssl_random_pseudo_bytes(16))], 'callback');
}
$uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'");
$version = version_info();
$queries = array(
$queries = [
'alert_rules' => 'SELECT COUNT(*) AS `total`,`severity` FROM `alert_rules` WHERE `disabled`=0 GROUP BY `severity`',
'alert_templates' => 'SELECT COUNT(*) AS `total` FROM `alert_templates`',
'api_tokens' => 'SELECT COUNT(*) AS `total` FROM `api_tokens` WHERE `disabled`=0',
@ -63,17 +63,16 @@ if ($enabled == 1) {
'vmware' => 'SELECT COUNT(*) AS `total` FROM `vminfo`',
'vrfs' => 'SELECT COUNT(*) AS `total` FROM `vrfs`',
'mysql_version' => 'SELECT 1 AS `total`, @@version AS `version`',
);
];
foreach ($queries as $name => $query) {
$data = dbFetchRows($query);
$response[$name] = $data;
}
$response['php_version'][] = array('total' => 1, 'version' => $version['php_ver']);
$response['php_version'][] = ['total' => 1, 'version' => $version['php_ver']];
$response['python_version'][] = ['total' => 1, 'version' => $version['python_ver']];
$response['rrdtool_version'][] = array('total' => 1, 'version' => $version['rrdtool_ver']);
$response['netsnmp_version'][] = array('total' => 1, 'version' => $version['netsnmp_ver']);
$response['rrdtool_version'][] = ['total' => 1, 'version' => $version['rrdtool_ver']];
$response['netsnmp_version'][] = ['total' => 1, 'version' => $version['netsnmp_ver']];
// collect sysDescr and sysObjectID for submission
$device_info = dbFetchRows('SELECT COUNT(*) AS `count`,`os`, `sysDescr`, `sysObjectID` FROM `devices`
@ -87,8 +86,8 @@ if ($enabled == 1) {
}, $entry['sysDescr']);
// wipe serial numbers, preserve the format
$sn_patterns = array('/[A-Z]/', '/[a-z]/', '/[0-9]/');
$sn_replacements = array('A', 'a', '0');
$sn_patterns = ['/[A-Z]/', '/[a-z]/', '/[0-9]/'];
$sn_replacements = ['A', 'a', '0'];
$entry['sysDescr'] = preg_replace_callback(
'/((s\/?n|serial num(ber)?)[:=]? ?)([a-z0-9.\-]{4,16})/i',
function ($matches) use ($sn_patterns, $sn_replacements) {
@ -100,13 +99,13 @@ if ($enabled == 1) {
return $entry;
}, $device_info);
$output = array(
$output = [
'uuid' => $uuid,
'data' => $response,
'info' => $device_info,
);
];
$data = json_encode($output);
$submit = array('data' => $data);
$submit = ['data' => $data];
$fields = '';
foreach ($submit as $key => $value) {
@ -133,6 +132,6 @@ if ($enabled == 1) {
curl_setopt($clear, CURLOPT_POSTFIELDS, $fields);
curl_setopt($clear, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($clear);
dbDelete('callback', '`name`="uuid"', array());
dbUpdate(array('value' => '0'), 'callback', '`name` = "enabled"', array());
dbDelete('callback', '`name`="uuid"', []);
dbUpdate(['value' => '0'], 'callback', '`name` = "enabled"', []);
}

View File

@ -25,7 +25,7 @@ use LibreNMS\Util\OS;
function generate_priority_label($priority)
{
$map = array(
$map = [
"emerg" => "label-danger",
"alert" => "label-danger",
"crit" => "label-danger",
@ -35,15 +35,16 @@ function generate_priority_label($priority)
"info" => "label-info",
"debug" => "label-default",
"" => "label-info",
);
];
$barColor = isset($map[$priority]) ? $map[$priority] : 'label-info';
return '<span class="alert-status ' . $barColor . '">&nbsp;</span>';
}
function generate_priority_status($priority)
{
$map = array(
$map = [
"emerg" => 2,
"alert" => 2,
"crit" => 2,
@ -53,14 +54,14 @@ function generate_priority_status($priority)
"info" => 0,
"debug" => 3,
"" => 0,
);
];
return isset($map[$priority]) ? $map[$priority] : 0;
}
function graylog_severity_label($severity)
{
$map = array(
$map = [
"0" => "label-danger",
"1" => "label-danger",
"2" => "label-danger",
@ -70,8 +71,9 @@ function graylog_severity_label($severity)
"6" => "label-info",
"7" => "label-default",
"" => "label-info",
);
];
$barColor = isset($map[$severity]) ? $map[$severity] : 'label-info';
return '<span class="alert-status ' . $barColor . '" style="margin-right:8px;float:left;"></span>';
}
@ -146,7 +148,8 @@ function shorthost($hostname, $len = 12)
$shorthost = $shorthost . '.' . $parts[$i];
$i++;
}
return ($shorthost);
return $shorthost;
}
function isCli()
@ -163,7 +166,7 @@ function print_error($text)
if (isCli()) {
c_echo("%r" . $text . "%n\n");
} else {
echo('<div class="alert alert-danger"><i class="fa fa-fw fa-exclamation-circle" aria-hidden="true"></i> '.$text.'</div>');
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-exclamation-circle" aria-hidden="true"></i> ' . $text . '</div>';
}
}
@ -172,7 +175,7 @@ function print_message($text)
if (isCli()) {
c_echo("%g" . $text . "%n\n");
} else {
echo('<div class="alert alert-success"><i class="fa fa-fw fa-check-circle" aria-hidden="true"></i> '.$text.'</div>');
echo '<div class="alert alert-success"><i class="fa fa-fw fa-check-circle" aria-hidden="true"></i> ' . $text . '</div>';
}
}
@ -183,11 +186,11 @@ function get_sensor_rrd($device, $sensor)
function get_sensor_rrd_name($device, $sensor)
{
# For IPMI, sensors tend to change order, and there is no index, so we prefer to use the description as key here.
// For IPMI, sensors tend to change order, and there is no index, so we prefer to use the description as key here.
if (Config::getOsSetting($device['os'], 'sensor_descr') || $sensor['poller_type'] == "ipmi") {
return array('sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_descr']);
return ['sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_descr']];
} else {
return array('sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_index']);
return ['sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_index']];
}
}
@ -217,7 +220,7 @@ function get_port_by_index_cache($device_id, $ifIndex)
function get_port_by_ifIndex($device_id, $ifIndex)
{
return dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device_id, $ifIndex));
return dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", [$device_id, $ifIndex]);
}
function table_from_entity_type($type)
@ -239,16 +242,17 @@ function get_entity_by_id_cache($type, $id)
if (is_array($entity_cache[$type][$id])) {
$entity = $entity_cache[$type][$id];
} else {
$entity = dbFetchRow("SELECT * FROM `".$table."` WHERE `".$type."_id` = ?", array($id));
$entity = dbFetchRow("SELECT * FROM `" . $table . "` WHERE `" . $type . "_id` = ?", [$id]);
$entity_cache[$type][$id] = $entity;
}
return $entity;
}
function get_port_by_id($port_id)
{
if (is_numeric($port_id)) {
$port = dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($port_id));
$port = dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", [$port_id]);
if (is_array($port)) {
return $port;
} else {
@ -260,7 +264,7 @@ function get_port_by_id($port_id)
function get_application_by_id($application_id)
{
if (is_numeric($application_id)) {
$application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", array($application_id));
$application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", [$application_id]);
if (is_array($application)) {
return $application;
} else {
@ -272,7 +276,7 @@ function get_application_by_id($application_id)
function get_sensor_by_id($sensor_id)
{
if (is_numeric($sensor_id)) {
$sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", array($sensor_id));
$sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", [$sensor_id]);
if (is_array($sensor)) {
return $sensor;
} else {
@ -284,7 +288,7 @@ function get_sensor_by_id($sensor_id)
function get_device_id_by_port_id($port_id)
{
if (is_numeric($port_id)) {
$device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `port_id` = ?", array($port_id));
$device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `port_id` = ?", [$port_id]);
if (is_numeric($device_id)) {
return $device_id;
} else {
@ -296,7 +300,7 @@ function get_device_id_by_port_id($port_id)
function get_device_id_by_app_id($app_id)
{
if (is_numeric($app_id)) {
$device_id = dbFetchCell("SELECT `device_id` FROM `applications` WHERE `app_id` = ?", array($app_id));
$device_id = dbFetchCell("SELECT `device_id` FROM `applications` WHERE `app_id` = ?", [$app_id]);
if (is_numeric($device_id)) {
return $device_id;
} else {
@ -316,16 +320,13 @@ function device_by_name($name)
return device_by_id_cache(getidbyname($name));
}
function accesspoint_by_id($ap_id, $refresh = '0')
{
$ap = dbFetchRow("SELECT * FROM `access_points` WHERE `accesspoint_id` = ?", array($ap_id));
$ap = dbFetchRow("SELECT * FROM `access_points` WHERE `accesspoint_id` = ?", [$ap_id]);
return $ap;
}
function device_by_id_cache($device_id, $refresh = false)
{
$model = $refresh ? DeviceCache::refresh((int) $device_id) : DeviceCache::get((int) $device_id);
@ -360,12 +361,13 @@ function mres($string)
return $string; // FIXME bleh
// short function wrapper because the real one is stupidly long and ugly. aesthetics.
global $database_link;
return mysqli_real_escape_string($database_link, $string);
}
function getifhost($id)
{
return dbFetchCell("SELECT `device_id` from `ports` WHERE `port_id` = ?", array($id));
return dbFetchCell("SELECT `device_id` from `ports` WHERE `port_id` = ?", [$id]);
}
function gethostbyid($device_id)
@ -375,10 +377,10 @@ function gethostbyid($device_id)
function strgen($length = 16)
{
$entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e',
$entropy = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e',
'E', 'f', 'F', 'g', 'G', 'h', 'H', 'i', 'I', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n',
'N', 'o', 'O', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S', 't', 'T', 'u', 'U', 'v', 'V', 'w',
'W','x','X','y','Y','z','Z');
'W', 'x', 'X', 'y', 'Y', 'z', 'Z', ];
$string = "";
for ($i = 0; $i < $length; $i++) {
@ -391,22 +393,22 @@ function strgen($length = 16)
function getpeerhost($id)
{
return dbFetchCell("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = ?", array($id));
return dbFetchCell("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = ?", [$id]);
}
function getifindexbyid($id)
{
return dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `port_id` = ?", array($id));
return dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `port_id` = ?", [$id]);
}
function getifbyid($id)
{
return dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($id));
return dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", [$id]);
}
function getifdescrbyid($id)
{
return dbFetchCell("SELECT `ifDescr` FROM `ports` WHERE `port_id` = ?", array($id));
return dbFetchCell("SELECT `ifDescr` FROM `ports` WHERE `port_id` = ?", [$id]);
}
function getidbyname($hostname)
@ -446,11 +448,12 @@ function get_dev_attribs($device_id)
function get_dev_entity_state($device)
{
$state = array();
foreach (dbFetchRows("SELECT * FROM entPhysical_state WHERE `device_id` = ?", array($device)) as $entity) {
$state = [];
foreach (dbFetchRows("SELECT * FROM entPhysical_state WHERE `device_id` = ?", [$device]) as $entity) {
$state['group'][$entity['group']][$entity['entPhysicalIndex']][$entity['subindex']][$entity['key']] = $entity['value'];
$state['index'][$entity['entPhysicalIndex']][$entity['subindex']][$entity['group']][$entity['key']] = $entity['value'];
}
return $state;
}
@ -467,12 +470,14 @@ function del_dev_attrib($device, $attrib_type)
function formatRates($value, $round = '2', $sf = '3')
{
$value = format_si($value, $round, $sf) . "bps";
return $value;
}
function formatStorage($value, $round = '2', $sf = '3')
{
$value = format_bi($value, $round) . "B";
return $value;
}
@ -485,14 +490,14 @@ function format_si($value, $round = '2', $sf = '3')
}
if ($value >= "0.1") {
$sizes = array('', 'k', 'M', 'G', 'T', 'P', 'E');
$sizes = ['', 'k', 'M', 'G', 'T', 'P', 'E'];
$ext = $sizes[0];
for ($i = 1; (($i < count($sizes)) && ($value >= 1000)); $i++) {
$value = $value / 1000;
$ext = $sizes[$i];
}
} else {
$sizes = array('', 'm', 'u', 'n', 'p');
$sizes = ['', 'm', 'u', 'n', 'p'];
$ext = $sizes[0];
for ($i = 1; (($i < count($sizes)) && ($value != 0) && ($value <= 0.1)); $i++) {
$value = $value * 1000;
@ -513,7 +518,7 @@ function format_bi($value, $round = '2', $sf = '3')
$neg = 1;
$value = $value * -1;
}
$sizes = array('', 'k', 'M', 'G', 'T', 'P', 'E');
$sizes = ['', 'k', 'M', 'G', 'T', 'P', 'E'];
$ext = $sizes[0];
for ($i = 1; (($i < count($sizes)) && ($value >= 1024)); $i++) {
$value = $value / 1024;
@ -523,6 +528,7 @@ function format_bi($value, $round = '2', $sf = '3')
if ($neg) {
$value = $value * -1;
}
return (number_format(round($value, $round), $sf, '.', '') + 0) . " " . $ext;
}
@ -580,22 +586,22 @@ function c_echo($string, $enabled = true)
echo $console_color->convert($string);
} else {
// limited functionality for validate.php
$search = array(
$search = [
'/%n/',
'/%g/',
'/%R/',
'/%Y/',
'/%B/',
'/%((%)|.)/' // anything left over replace with empty string
);
$replace = array(
'/%((%)|.)/', // anything left over replace with empty string
];
$replace = [
"\e[0m",
"\e[32m",
"\e[1;31m",
"\e[1;33m",
"\e[1;34m",
""
);
"",
];
echo preg_replace($search, $replace, $string);
}
} else {
@ -610,13 +616,15 @@ function is_client_authorized($clientip)
{
if (Config::get('allow_unauth_graphs', false)) {
d_echo("Unauthorized graphs allowed\n");
return true;
}
foreach (Config::get('allow_unauth_graphs_cidr', array()) as $range) {
foreach (Config::get('allow_unauth_graphs_cidr', []) as $range) {
try {
if (IP::parse($clientip)->inNetwork($range)) {
d_echo("Unauthorized graphs allowed from $range\n");
return true;
}
} catch (InvalidIpException $e) {
@ -627,14 +635,13 @@ function is_client_authorized($clientip)
return false;
} // is_client_authorized
/*
* @return an array of all graph subtypes for the given type
*/
function get_graph_subtypes($type, $device = null)
{
$type = basename($type);
$types = array();
$types = [];
// find the subtypes defined in files
if ($handle = opendir(Config::get('install_dir') . "/includes/html/graphs/$type/")) {
@ -647,23 +654,24 @@ function get_graph_subtypes($type, $device = null)
}
sort($types);
return $types;
} // get_graph_subtypes
function get_smokeping_files($device)
{
$smokeping = new \LibreNMS\Util\Smokeping(DeviceCache::get((int) $device['device_id']));
return $smokeping->findFiles();
}
function generate_smokeping_file($device, $file = '')
{
$smokeping = new \LibreNMS\Util\Smokeping(DeviceCache::get((int) $device['device_id']));
return $smokeping->generateFileName($file);
}
/*
* @return rounded value to 10th/100th/1000th depending on input (valid: 10, 100, 1000)
*/
@ -676,20 +684,20 @@ function round_Nth($val, $round_to)
} else {
$ret = $val - $diff;
}
return $ret;
}
} // end round_Nth
function is_customoid_graph($type, $subtype)
{
if (! empty($subtype) && $type == 'customoid') {
return true;
}
return false;
} // is_customoid_graph
//
// maintain a simple cache of objects
//
@ -700,7 +708,6 @@ function object_add_cache($section, $obj)
$object_cache[$section][$obj] = true;
} // object_add_cache
function object_is_cached($section, $obj)
{
global $object_cache;
@ -711,7 +718,6 @@ function object_is_cached($section, $obj)
}
} // object_is_cached
/**
* Checks if config allows us to ping this device
* $attribs contains an array of all of this devices
@ -728,7 +734,6 @@ function can_ping_device($attribs)
}
} // end can_ping_device
/*
* @return true if every string in $arr begins with $str
*/
@ -740,12 +745,14 @@ function begins_with($str, $arr)
return false;
}
}
return true;
} // begins_with
function search_phrase_column($c)
{
global $searchPhrase;
return "$c LIKE '%$searchPhrase%'";
} // search_phrase_column
@ -765,7 +772,7 @@ function ceph_rrd($gtype)
$var = $vars['pool'];
}
return rrd_name($device['hostname'], array('app', 'ceph', $vars['id'], $gtype, $var));
return rrd_name($device['hostname'], ['app', 'ceph', $vars['id'], $gtype, $var]);
} // ceph_rrd
/**
@ -837,6 +844,7 @@ function inet6_ntop($ip)
if ($l == 4 or $l == 16) {
return inet_ntop(pack('A' . $l, $ip));
}
return '';
}
@ -915,12 +923,12 @@ function get_port_assoc_mode_name($port_assoc_mode_id)
*/
function get_ports_mapped($device_id, $with_statistics = false)
{
$ports = array();
$maps = array(
'ifIndex' => array(),
'ifName' => array(),
'ifDescr' => array(),
);
$ports = [];
$maps = [
'ifIndex' => [],
'ifName' => [],
'ifDescr' => [],
];
if ($with_statistics) {
/* ... including any related ports_statistics if requested */
@ -932,7 +940,7 @@ function get_ports_mapped($device_id, $with_statistics = false)
// Query known ports in order of discovery to make sure the latest
// discoverd/polled port is in the mapping tables.
foreach (dbFetchRows($query, array ($device_id)) as $port) {
foreach (dbFetchRows($query, [$device_id]) as $port) {
// Store port information by ports port_id from DB
$ports[$port['port_id']] = $port;
@ -942,10 +950,10 @@ function get_ports_mapped($device_id, $with_statistics = false)
$maps['ifDescr'][$port['ifDescr']] = $port['port_id'];
}
return array(
return [
'ports' => $ports,
'maps' => $maps,
);
];
}
/**
@ -969,7 +977,7 @@ function get_port_id($ports_mapped, $port, $port_association_mode)
*/
$maps = $ports_mapped['maps'];
if (in_array($port_association_mode, array ('ifIndex', 'ifName', 'ifDescr', 'ifAlias'))) {
if (in_array($port_association_mode, ['ifIndex', 'ifName', 'ifDescr', 'ifAlias'])) {
$port_id = $maps[$port_association_mode][$port[$port_association_mode]];
}
@ -985,11 +993,11 @@ function get_port_id($ports_mapped, $port, $port_association_mode)
* @param array $last Glues on the fringe
* @return array|false
*/
function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array())
function ResolveGlues($tables, $target, $x = 0, $hist = [], $last = [])
{
if (sizeof($tables) == 1 && $x != 0) {
if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', array($tables[0],$target)) == 1) {
return array_merge($last, array($tables[0].'.'.$target));
if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', [$tables[0], $target]) == 1) {
return array_merge($last, [$tables[0] . '.' . $target]);
} else {
return false;
}
@ -1002,27 +1010,27 @@ function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()
foreach ($tables as $table) {
if ($table == 'state_translations' && ($target == 'device_id' || $target == 'sensor_id')) {
// workaround for state_translations
return array_merge($last, array(
return array_merge($last, [
'state_translations.state_index_id',
'sensors_to_state_indexes.sensor_id',
"sensors.$target",
));
]);
} elseif ($table == 'application_metrics' && $target == 'device_id') {
return array_merge($last, array(
return array_merge($last, [
'application_metrics.app_id',
"applications.$target",
));
]);
} elseif ($table == 'locations' && $target == 'device_id') {
return array_merge($last, [
'locations.id',
'devices.device_id.location_id'
'devices.device_id.location_id',
]);
}
$glues = dbFetchRows('SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME LIKE "%\_id"', array($table));
$glues = dbFetchRows('SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME LIKE "%\_id"', [$table]);
if (sizeof($glues) == 1 && $glues[0]['COLUMN_NAME'] != $target) {
//Search for new candidates to expand
$ntables = array();
$ntables = [];
[$tmp] = explode('_', $glues[0]['COLUMN_NAME'], 2);
$ntables[] = $tmp;
$ntables[] = $tmp . 's';
@ -1030,20 +1038,20 @@ function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()
foreach ($tmp as $expand) {
$ntables[] = $expand['TABLE_NAME'];
}
$tmp = ResolveGlues($ntables, $target, $x++, array_merge($tables, $ntables), array_merge($last, array($table.'.'.$glues[0]['COLUMN_NAME'])));
$tmp = ResolveGlues($ntables, $target, $x++, array_merge($tables, $ntables), array_merge($last, [$table . '.' . $glues[0]['COLUMN_NAME']]));
if (is_array($tmp)) {
return $tmp;
}
} else {
foreach ($glues as $glue) {
if ($glue['COLUMN_NAME'] == $target) {
return array_merge($last, array($table.'.'.$target));
return array_merge($last, [$table . '.' . $target]);
} else {
[$tmp] = explode('_', $glue['COLUMN_NAME']);
$tmp .= 's';
if (! in_array($tmp, $tables) && ! in_array($tmp, $hist)) {
//Expand table
$tmp = ResolveGlues(array($tmp), $target, $x++, array_merge($tables, array($tmp)), array_merge($last, array($table.'.'.$glue['COLUMN_NAME'])));
$tmp = ResolveGlues([$tmp], $target, $x++, array_merge($tables, [$tmp]), array_merge($last, [$table . '.' . $glue['COLUMN_NAME']]));
if (is_array($tmp)) {
return $tmp;
}
@ -1071,6 +1079,7 @@ function str_i_contains($haystack, $needles)
return true;
}
}
return false;
}
@ -1081,10 +1090,9 @@ function str_i_contains($haystack, $needles)
* @param string $alert_rules_name
* @return string
*/
function get_sql_filter_min_severity($min_severity, $alert_rules_name)
{
$alert_severities = array(
$alert_severities = [
// alert_rules.status is enum('ok','warning','critical')
'ok' => 1,
'warning' => 2,
@ -1092,7 +1100,7 @@ function get_sql_filter_min_severity($min_severity, $alert_rules_name)
'ok only' => 4,
'warning only' => 5,
'critical only' => 6,
);
];
if (is_numeric($min_severity)) {
$min_severity_id = $min_severity;
} elseif (! empty($min_severity)) {
@ -1101,6 +1109,7 @@ function get_sql_filter_min_severity($min_severity, $alert_rules_name)
if (isset($min_severity_id)) {
return " AND `$alert_rules_name`.`severity` " . ($min_severity_id > 3 ? "" : ">") . "= " . ($min_severity_id > 3 ? $min_severity_id - 3 : $min_severity_id);
}
return "";
}
@ -1138,6 +1147,7 @@ function load_os(&$device)
{
if (! isset($device['os'])) {
d_echo("No OS to load\n");
return;
}
@ -1172,6 +1182,7 @@ function fahrenheit_to_celsius($value, $scale = 'fahrenheit')
if ($scale === 'fahrenheit') {
$value = ($value - 32) / 1.8;
}
return sprintf('%.02f', $value);
}
@ -1183,18 +1194,17 @@ function fahrenheit_to_celsius($value, $scale = 'fahrenheit')
* @param string $scale fahrenheit or celsius
* @return string (containing a float)
*/
function celsius_to_fahrenheit($value, $scale = 'celsius')
{
if ($scale === 'celsius') {
$value = ($value * 1.8) + 32;
}
return sprintf('%.02f', $value);
}
/**
* Converts string to float
*
*/
function string_to_float($value)
{
@ -1204,7 +1214,6 @@ function string_to_float($value)
/**
* Converts uW to dBm
* $value must be positive
*
*/
function uw_to_dbm($value)
{
@ -1214,7 +1223,6 @@ function uw_to_dbm($value)
/**
* Converts mW to dBm
* $value must be positive
*
*/
function mw_to_dbm($value)
{
@ -1238,6 +1246,7 @@ function set_null($value, $default = null, $min = null)
} elseif (isset($min) && $value < $min) {
return $default;
}
return $value;
}
/*
@ -1253,6 +1262,7 @@ function set_numeric($value, $default = 0)
) {
$value = $default;
}
return $value;
}
@ -1279,8 +1289,10 @@ function str_to_class($name, $namespace = null)
$class = str_replace(' ', '', ucwords(strtolower($pre_format)));
$class = preg_replace_callback('/^(\d)(.)/', function ($matches) {
$numbers = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'];
return $numbers[$matches[1]] . strtoupper($matches[2]);
}, $class);
return $namespace . $class;
}

View File

@ -19,8 +19,8 @@
use Illuminate\Database\QueryException;
use LibreNMS\Config;
use LibreNMS\Exceptions\DatabaseConnectException;
use LibreNMS\DB\Eloquent;
use LibreNMS\Exceptions\DatabaseConnectException;
use LibreNMS\Util\Laravel;
function dbIsConnected()
@ -66,7 +66,7 @@ function dbConnect($db_host = null, $db_user = '', $db_pass = '', $db_name = '',
"collation" => "utf8_unicode_ci",
"prefix" => "",
"strict" => true,
"engine" => null
"engine" => null,
]);
\Config::set('database.default', 'setup');
}
@ -96,11 +96,11 @@ function dbQuery($sql, $parameters = [])
return Eloquent::DB()->statement($sql, (array) $parameters);
} catch (PDOException $pdoe) {
dbHandleException(new QueryException($sql, $parameters, $pdoe));
return false;
}
}
/**
* @param array $data
* @param string $table
@ -126,7 +126,6 @@ function dbInsert($data, $table)
}
}//end dbInsert()
/**
* Passed an array and a table name, it attempts to insert the data into the table.
* $data is an array (rows) of key value pairs. keys are fields. Rows need to have same fields.
@ -160,6 +159,7 @@ function dbBulkInsert($data, $table)
$result = Eloquent::DB()->table($table)->insert((array) $data_chunk);
recordDbStatistic('insert', $time_start);
return $result;
} catch (PDOException $pdoe) {
// FIXME query?
@ -170,7 +170,6 @@ function dbBulkInsert($data, $table)
return false;
}//end dbBulkInsert()
/**
* Passed an array, table name, WHERE clause, and placeholder parameters, it attempts to update a record.
* Returns the number of affected rows
@ -213,6 +212,7 @@ function dbUpdate($data, $table, $where = null, $parameters = [])
$result = Eloquent::DB()->update($sql, (array) $data);
recordDbStatistic('update', $time_start);
return $result;
} catch (PDOException $pdoe) {
dbHandleException(new QueryException($sql, $data, $pdoe));
@ -221,8 +221,7 @@ function dbUpdate($data, $table, $where = null, $parameters = [])
return false;
}//end dbUpdate()
function dbDelete($table, $where = null, $parameters = array())
function dbDelete($table, $where = null, $parameters = [])
{
$time_start = microtime(true);
@ -238,10 +237,10 @@ function dbDelete($table, $where = null, $parameters = array())
}
recordDbStatistic('delete', $time_start);
return $result;
}//end dbDelete()
/**
* Delete orphaned entries from a table that no longer have a parent in parent_table
* Format of parents array is as follows table.table_key_column<.target_key_column>
@ -261,15 +260,15 @@ function dbDeleteOrphans($target_table, $parents)
$target_table = mres($target_table);
$sql = "DELETE T FROM `$target_table` T";
$where = array();
$where = [];
foreach ((array) $parents as $parent) {
$parent_parts = explode('.', mres($parent));
if (count($parent_parts) == 2) {
list($parent_table, $parent_column) = $parent_parts;
[$parent_table, $parent_column] = $parent_parts;
$target_column = $parent_column;
} elseif (count($parent_parts) == 3) {
list($parent_table, $parent_column, $target_column) = $parent_parts;
[$parent_table, $parent_column, $target_column] = $parent_parts;
} else {
// invalid input
return false;
@ -288,6 +287,7 @@ function dbDeleteOrphans($target_table, $parents)
}
recordDbStatistic('delete', $time_start);
return $result;
}
@ -296,7 +296,6 @@ function dbDeleteOrphans($target_table, $parents)
* Most other retrieval functions build off this
* */
function dbFetchRows($sql, $parameters = [])
{
global $PDO_FETCH_ASSOC;
@ -307,6 +306,7 @@ function dbFetchRows($sql, $parameters = [])
$rows = Eloquent::DB()->select($sql, (array) $parameters);
recordDbStatistic('fetchrows', $time_start);
return $rows;
} catch (PDOException $pdoe) {
dbHandleException(new QueryException($sql, $parameters, $pdoe));
@ -317,13 +317,11 @@ function dbFetchRows($sql, $parameters = [])
return [];
}//end dbFetchRows()
/*
* This is intended to be the method used for large result sets.
* It is intended to return an iterator, and act upon buffered data.
* */
function dbFetch($sql, $parameters = [])
{
return dbFetchRows($sql, $parameters);
@ -339,13 +337,11 @@ function dbFetch($sql, $parameters = [])
*/
}//end dbFetch()
/*
* Like fetch(), accepts any number of arguments
* The first argument is an sprintf-ready query stringTypes
* */
function dbFetchRow($sql = null, $parameters = [])
{
global $PDO_FETCH_ASSOC;
@ -356,6 +352,7 @@ function dbFetchRow($sql = null, $parameters = [])
$row = Eloquent::DB()->selectOne($sql, (array) $parameters);
recordDbStatistic('fetchrow', $time_start);
return $row;
} catch (PDOException $pdoe) {
dbHandleException(new QueryException($sql, $parameters, $pdoe));
@ -366,12 +363,10 @@ function dbFetchRow($sql = null, $parameters = [])
return [];
}//end dbFetchRow()
/*
* Fetches the first call from the first row returned by the query
* */
function dbFetchCell($sql, $parameters = [])
{
global $PDO_FETCH_ASSOC;
@ -394,13 +389,11 @@ function dbFetchCell($sql, $parameters = [])
return null;
}//end dbFetchCell()
/*
* This method is quite different from fetchCell(), actually
* It fetches one cell from each row and places all the values in 1 array
* */
function dbFetchColumn($sql, $parameters = [])
{
global $PDO_FETCH_ASSOC;
@ -416,6 +409,7 @@ function dbFetchColumn($sql, $parameters = [])
$PDO_FETCH_ASSOC = false;
recordDbStatistic('fetchcolumn', $time_start);
return $cells;
} catch (PDOException $pdoe) {
dbHandleException(new QueryException($sql, $parameters, $pdoe));
@ -426,17 +420,15 @@ function dbFetchColumn($sql, $parameters = [])
return [];
}//end dbFetchColumn()
/*
* Should be passed a query that fetches two fields
* The first will become the array key
* The second the key's value
*/
function dbFetchKeyValue($sql, $parameters = array())
function dbFetchKeyValue($sql, $parameters = [])
{
$data = array();
$data = [];
foreach (dbFetch($sql, $parameters) as $row) {
$key = array_shift($row);
if (sizeof($row) == 1) {
@ -507,7 +499,7 @@ function dbHandleException(QueryException $exception)
*/
function dbPlaceHolders(&$values)
{
$data = array();
$data = [];
foreach ($values as $key => $value) {
if (is_array($value)) {
// array wrapped values are raw sql
@ -523,19 +515,16 @@ function dbPlaceHolders(&$values)
return $data;
}//end dbPlaceHolders()
function dbBeginTransaction()
{
Eloquent::DB()->beginTransaction();
}//end dbBeginTransaction()
function dbCommitTransaction()
{
Eloquent::DB()->commit();
}//end dbCommitTransaction()
function dbRollbackTransaction()
{
Eloquent::DB()->rollBack();
@ -565,8 +554,8 @@ function recordDbStatistic($stat, $start_time)
global $db_stats, $db_stats_last;
if (! isset($db_stats)) {
$db_stats = array(
'ops' => array(
$db_stats = [
'ops' => [
'insert' => 0,
'update' => 0,
'delete' => 0,
@ -574,8 +563,8 @@ function recordDbStatistic($stat, $start_time)
'fetchcolumn' => 0,
'fetchrow' => 0,
'fetchrows' => 0,
),
'time' => array(
],
'time' => [
'insert' => 0.0,
'update' => 0.0,
'delete' => 0.0,
@ -583,8 +572,8 @@ function recordDbStatistic($stat, $start_time)
'fetchcolumn' => 0.0,
'fetchrow' => 0.0,
'fetchrows' => 0.0,
),
);
],
];
$db_stats_last = $db_stats;
}
@ -645,10 +634,10 @@ function dbSyncRelationship($table, $target_column = null, $target = null, $list
* @param array $relationships array of relationship pairs with columns as keys and ids as values
* @return array [$inserted, $deleted]
*/
function dbSyncRelationships($table, $relationships = array())
function dbSyncRelationships($table, $relationships = [])
{
$changed = [[0, 0]];
list($target_column, $list_column) = array_keys(reset($relationships));
[$target_column, $list_column] = array_keys(reset($relationships));
$grouped = [];
foreach ($relationships as $relationship) {

View File

@ -28,10 +28,10 @@ use LibreNMS\Config;
echo "\nApplications: ";
// fetch applications from the client
$results = snmpwalk_cache_oid($device, 'nsExtendStatus', array(), 'NET-SNMP-EXTEND-MIB');
$results = snmpwalk_cache_oid($device, 'nsExtendStatus', [], 'NET-SNMP-EXTEND-MIB');
// Load our list of available applications
$applications = array();
$applications = [];
if ($results) {
foreach (glob(Config::get('install_dir') . '/includes/polling/applications/*.inc.php') as $file) {
$name = basename($file, '.inc.php');
@ -52,20 +52,20 @@ d_echo(PHP_EOL . 'Available: ' . implode(', ', array_keys($applications)) . PHP_
d_echo('Checking for: ' . implode(', ', array_keys($results)) . PHP_EOL);
// Generate a list of enabled apps and a list of all discovered apps from the db
list($enabled_apps, $discovered_apps) = array_reduce(dbFetchRows(
[$enabled_apps, $discovered_apps] = array_reduce(dbFetchRows(
'SELECT `app_type`,`discovered` FROM `applications` WHERE `device_id`=? ORDER BY `app_type`',
array($device['device_id'])
[$device['device_id']]
), function ($result, $app) {
$result[0][] = $app['app_type'];
if ($app['discovered']) {
$result[1][] = $app['app_type'];
}
return $result;
}, array(array(), array()));
return $result;
}, [[], []]);
// Enable applications
$current_apps = array();
$current_apps = [];
foreach ($results as $extend => $result) {
if (isset($applications[$extend])) {
$app = $applications[$extend];
@ -74,13 +74,13 @@ foreach ($results as $extend => $result) {
if (in_array($app, $enabled_apps)) {
echo '.';
} else {
dbInsert(array(
dbInsert([
'device_id' => $device['device_id'],
'app_type' => $app,
'discovered' => 1,
'app_status' => '',
'app_instance' => ''
), 'applications');
'app_instance' => '',
], 'applications');
echo '+';
log_event("Application enabled by discovery: $app", $device, 'application', 1);
@ -106,7 +106,7 @@ if ($num > 0) {
}
// clean application_metrics
dbDeleteOrphans('application_metrics', array('applications.app_id'));
dbDeleteOrphans('application_metrics', ['applications.app_id']);
echo PHP_EOL;

View File

@ -28,7 +28,7 @@ use LibreNMS\Config;
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
} else {
$vrfs_lite_cisco = array(array('context_name'=>''));
$vrfs_lite_cisco = [['context_name'=>'']];
}
foreach ($vrfs_lite_cisco as $vrf) {
@ -43,14 +43,14 @@ foreach ($vrfs_lite_cisco as $vrf) {
}
$sql = "SELECT * from `ipv4_mac` WHERE `device_id`=? AND `context_name`=?";
$existing_data = dbFetchRows($sql, array($device['device_id'], $context));
$existing_data = dbFetchRows($sql, [$device['device_id'], $context]);
$ipv4_addresses = array_map(function ($data) {
return $data['ipv4_address'];
}, $existing_data);
$arp_table = array();
$insert_data = array();
$arp_table = [];
$insert_data = [];
foreach ($arp_data as $ifIndex => $data) {
$interface = get_port_by_index_cache($device['device_id'], $ifIndex);
$port_id = $interface['port_id'];
@ -75,18 +75,18 @@ foreach ($vrfs_lite_cisco as $vrf) {
if ($mac != $old_mac && $mac != '') {
d_echo("Changed mac address for $ip from $old_mac to $mac\n");
log_event("MAC change: $ip : " . mac_clean_to_readable($old_mac) . ' -> ' . mac_clean_to_readable($mac), $device, 'interface', 4, $port_id);
dbUpdate(array('mac_address' => $mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND context_name=?', array($port_id, $ip, $context));
dbUpdate(['mac_address' => $mac], 'ipv4_mac', 'port_id=? AND ipv4_address=? AND context_name=?', [$port_id, $ip, $context]);
}
d_echo("$raw_mac => $ip\n", '.');
} elseif (isset($interface['port_id'])) {
d_echo("$raw_mac => $ip\n", '+');
$insert_data[] = array(
$insert_data[] = [
'port_id' => $port_id,
'device_id' => $device['device_id'],
'mac_address' => $mac,
'ipv4_address' => $ip,
'context_name' => (string) $context,
);
];
}
}
echo PHP_EOL;
@ -110,13 +110,13 @@ foreach ($vrfs_lite_cisco as $vrf) {
$entry_if = $entry['port_id'];
$entry_ip = $entry['ipv4_address'];
if ($arp_table[$entry_if][$entry_ip] != $entry_mac) {
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address`=? AND `ipv4_address`=? AND `context_name`=?', array($entry_if, $entry_mac, $entry_ip, $context));
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address`=? AND `ipv4_address`=? AND `context_name`=?', [$entry_if, $entry_mac, $entry_ip, $context]);
d_echo(null, '-');
}
}
// remove entries that no longer have an owner
dbDeleteOrphans('ipv4_mac', array('ports.port_id', 'devices.device_id'));
dbDeleteOrphans('ipv4_mac', ['ports.port_id', 'devices.device_id']);
echo PHP_EOL;
unset(

View File

@ -22,7 +22,6 @@
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
$binding = snmpwalk_group($device, 'agentDynamicDsBindingTable', 'EdgeSwitch-SWITCHING-MIB', 1);
foreach ($binding as $mac => $data) {

View File

@ -15,7 +15,7 @@ if (Config::get('enable_bgp')) {
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
} else {
$vrfs_lite_cisco = array(array('context_name'=>''));
$vrfs_lite_cisco = [['context_name'=>'']];
}
$bgpLocalAs = snmp_getnext($device, 'bgpLocalAs', '-OQUsv', 'BGP4-MIB');
@ -25,7 +25,7 @@ if (Config::get('enable_bgp')) {
if (is_numeric($bgpLocalAs)) {
echo "AS$bgpLocalAs ";
if ($bgpLocalAs != $device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id']));
dbUpdate(['bgpLocalAs' => $bgpLocalAs], 'devices', 'device_id=?', [$device['device_id']]);
echo 'Updated AS ';
}
@ -48,7 +48,7 @@ if (Config::get('enable_bgp')) {
} else {
echo 'No BGP on host';
if ($device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => array('NULL')), 'devices', 'device_id=?', array($device['device_id']));
dbUpdate(['bgpLocalAs' => ['NULL']], 'devices', 'device_id=?', [$device['device_id']]);
echo ' (Removed ASN) ';
}
}
@ -57,8 +57,8 @@ if (Config::get('enable_bgp')) {
// Process discovered peers
if (! empty($peerlist)) {
$af_data = array();
$af_list = array();
$af_data = [];
$af_list = [];
foreach ($peerlist as $peer) {
$peer['astext'] = get_astext($peer['as']);
@ -68,10 +68,10 @@ if (Config::get('enable_bgp')) {
if (empty($af_data)) {
if ($device['os_group'] == 'cisco') {
if ($peer2 === true) {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', array(), 'CISCO-BGP4-MIB');
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', [], 'CISCO-BGP4-MIB');
}
if (empty($af_data)) {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', array(), 'CISCO-BGP4-MIB');
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', [], 'CISCO-BGP4-MIB');
$peer2 = false;
}
} elseif ($device['os_group'] === 'arista') {
@ -117,13 +117,13 @@ if (Config::get('enable_bgp')) {
if (! isset($j_afisafi)) {
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', 'junos');
foreach (array_keys($j_prefixes) as $key) {
list($index,$afisafi) = explode('.', $key, 2);
[$index,$afisafi] = explode('.', $key, 2);
$j_afisafi[$index][] = $afisafi;
}
}
foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) {
list ($afi,$safi) = explode('.', $afisafi);
[$afi,$safi] = explode('.', $afisafi);
$afi = $afis[$afi];
$safi = $safis[$safi];
$af_list[$peer['ip']][$afi][$safi] = 1;

View File

@ -112,7 +112,7 @@ if (Config::get('enable_bgp')) {
echo '.';
$vrp_bgp_peer_count++;
}
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $value['hwBgpPeerRemoteAddr'], $value['afi'], $value['safi'])) < 1) {
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', [$device['device_id'], $value['hwBgpPeerRemoteAddr'], $value['afi'], $value['safi']]) < 1) {
$device['context_name'] = $vrfName;
add_cbgp_peer($device, ['ip' => $value['hwBgpPeerRemoteAddr']], $value['afi'], $value['safi']);
unset($device['context_name']);

View File

@ -15,14 +15,13 @@ if ($device['os_group'] == 'cisco') {
$module = 'Cisco-CBQOS';
$component = new LibreNMS\Component();
$components = $component->getComponents($device['device_id'], array('type'=>$module));
$components = $component->getComponents($device['device_id'], ['type'=>$module]);
// We only care about our device id.
$components = $components[$device['device_id']];
// Begin our master array, all other values will be processed into this array.
$tblCBQOS = array();
$tblCBQOS = [];
// Let's gather some data..
$tblcbQosServicePolicy = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.1');
@ -44,7 +43,7 @@ if ($device['os_group'] == 'cisco') {
foreach ($tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.2'] as $spid => $array) {
foreach ($array as $spobj => $index) {
$result = array();
$result = [];
// Produce a unique reproducible index for this entry.
$result['UID'] = hash('crc32', $spid . "-" . $spobj);

View File

@ -1,13 +1,13 @@
<?php
$cefs = array();
$cefs = [];
$cefs = snmpwalk_cache_threepart_oid($device, 'CISCO-CEF-MIB::cefSwitchingPath', $cefs);
d_echo($cefs);
if (is_array($cefs)) {
if (! is_array($entity_array)) {
echo 'Caching OIDs: ';
$entity_array = array();
$entity_array = [];
echo ' entPhysicalDescr';
$entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalDescr', $entity_array, 'ENTITY-MIB');
echo ' entPhysicalName';
@ -25,8 +25,8 @@ if (is_array($cefs)) {
echo ' | |-' . $path . ': ' . $path_name['cefSwitchingPath'] . "\n";
$cef_exists[$device['device_id']][$entity][$afi][$path] = 1;
if (dbFetchCell('SELECT COUNT(*) from `cef_switching` WHERE device_id = ? AND entPhysicalIndex = ? AND afi=? AND cef_index=?', array($device['device_id'], $entity, $afi, $path)) != '1') {
dbInsert(array('device_id' => $device['device_id'], 'entPhysicalIndex' => $entity, 'afi' => $afi, 'cef_path' => $path), 'cef_switching');
if (dbFetchCell('SELECT COUNT(*) from `cef_switching` WHERE device_id = ? AND entPhysicalIndex = ? AND afi=? AND cef_index=?', [$device['device_id'], $entity, $afi, $path]) != '1') {
dbInsert(['device_id' => $device['device_id'], 'entPhysicalIndex' => $entity, 'afi' => $afi, 'cef_path' => $path], 'cef_switching');
echo '+';
}
}

View File

@ -4,11 +4,11 @@ if ($device['os_group'] == 'cisco') {
$datas = snmp_walk($device, 'cipMacSwitchedBytes', '-Oqn', 'CISCO-IP-STAT-MIB');
foreach (explode("\n", $datas) as $data) {
list($oid) = explode(' ', $data);
[$oid] = explode(' ', $data);
$oid = str_replace('.1.3.6.1.4.1.9.9.84.1.2.1.1.4.', '', $oid);
list($if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode('.', $oid);
[$if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f] = explode('.', $oid);
unset($interface);
$interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if));
$interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', [$device['device_id'], $if]);
$ah_a = zeropad(dechex($a_a));
$ah_b = zeropad(dechex($a_b));
$ah_c = zeropad(dechex($a_c));
@ -18,10 +18,10 @@ if ($device['os_group'] == 'cisco') {
$mac = "$ah_a$ah_b$ah_c$ah_d$ah_e$ah_f";
if ($interface) {
if (dbFetchCell('SELECT COUNT(*) from mac_accounting WHERE port_id = ? AND mac = ?', array($interface['port_id'], $mac))) {
if (dbFetchCell('SELECT COUNT(*) from mac_accounting WHERE port_id = ? AND mac = ?', [$interface['port_id'], $mac])) {
echo '.';
} else {
dbInsert(array('port_id' => $interface['port_id'], 'mac' => $mac), 'mac_accounting');
dbInsert(['port_id' => $interface['port_id'], 'mac' => $mac], 'mac_accounting');
echo '+';
}
}

View File

@ -13,7 +13,7 @@
if ($device['os_group'] == 'cisco') {
// Define some error messages
$error_vpn = array();
$error_vpn = [];
$error_vpn[0] = "Other";
$error_vpn[1] = "Configuration changed";
$error_vpn[2] = "Control Group information is unavailable";
@ -35,7 +35,7 @@ if ($device['os_group'] == 'cisco') {
$error_vpn[18] = "Changing device ID";
$error_vpn[19] = "Cleanup in progress";
$error_aed = array();
$error_aed = [];
$error_aed[0] = "Other";
$error_aed[1] = "Overlay is Down";
$error_aed[2] = "Site ID is not configured";
@ -48,7 +48,7 @@ if ($device['os_group'] == 'cisco') {
$error_aed[9] = "Overlay state down event in progress";
$error_aed[10] = "ISIS control group sync pending";
$error_overlay = array();
$error_overlay = [];
$error_overlay[1] = "active";
$error_overlay[2] = "notInService";
$error_overlay[3] = "notReady";
@ -59,14 +59,14 @@ if ($device['os_group'] == 'cisco') {
$module = 'Cisco-OTV';
$component = new LibreNMS\Component();
$components = $component->getComponents($device['device_id'], array('type'=>$module));
$components = $component->getComponents($device['device_id'], ['type'=>$module]);
// We only care about our device id.
$components = $components[$device['device_id']];
// Begin our master array, all other values will be processed into this array.
$tblOTV = array();
$tblEndpoints = array();
$tblOTV = [];
$tblEndpoints = [];
// Let's gather some data..
$tblOverlayEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.2.1.1');
@ -85,7 +85,7 @@ if ($device['os_group'] == 'cisco') {
// Add each overlay to the array.
foreach ((array) $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.2'] as $index => $name) {
$result = array();
$result = [];
$message = false;
$result['index'] = $index;
$result['label'] = $name;
@ -135,7 +135,7 @@ if ($device['os_group'] == 'cisco') {
if ($tblAdjacentDevName) {
foreach ((array) $tblAdjacentDevName as $key => $value) {
preg_match('/^1.3.6.1.4.1.9.9.810.1.3.1.1.4.(\d+).1.4.(\d+.\d+.\d+.\d+)$/', $key, $matches);
$result = array();
$result = [];
$result['index'] = $matches[1];
$result['endpoint'] = $matches[2];
$tblEndpoints[$value] = true;

View File

@ -5,12 +5,12 @@ use LibreNMS\Config;
if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
$pws_db = [];
// Pre-cache the existing state of pseudowires for this device from the database
$pws_db_raw = dbFetchRows('SELECT * FROM `pseudowires` WHERE `device_id` = ?', array($device['device_id']));
$pws_db_raw = dbFetchRows('SELECT * FROM `pseudowires` WHERE `device_id` = ?', [$device['device_id']]);
foreach ($pws_db_raw as $pw_db) {
$pws_db[$pw_db['cpwVcID']] = $pw_db['pseudowire_id'];
}
$pws = snmpwalk_cache_oid($device, 'cpwVcID', array(), 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcID', [], 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcName', $pws, 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcType', $pws, 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcPsnType', $pws, 'CISCO-IETF-PW-MPLS-MIB');
@ -27,15 +27,15 @@ if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
$pw['cpwVcName'] = preg_replace('/(?<=\d)_(?=\d)/', '/', $pw['cpwVcName']);
// END
list($cpw_remote_id) = explode(':', $pw['cpwVcMplsPeerLdpID']);
$cpw_remote_device = dbFetchCell('SELECT device_id from ipv4_addresses AS A, ports AS I WHERE A.ipv4_address=? AND A.port_id=I.port_id', array($cpw_remote_id));
$if_id = dbFetchCell('SELECT port_id from ports WHERE `ifDescr`=? AND `device_id`=?', array($pw['cpwVcName'], $device['device_id']));
[$cpw_remote_id] = explode(':', $pw['cpwVcMplsPeerLdpID']);
$cpw_remote_device = dbFetchCell('SELECT device_id from ipv4_addresses AS A, ports AS I WHERE A.ipv4_address=? AND A.port_id=I.port_id', [$cpw_remote_id]);
$if_id = dbFetchCell('SELECT port_id from ports WHERE `ifDescr`=? AND `device_id`=?', [$pw['cpwVcName'], $device['device_id']]);
if (! empty($pws_db[$pw['cpwVcID']])) {
$pseudowire_id = $pws_db[$pw['cpwVcID']];
echo '.';
} else {
$pseudowire_id = dbInsert(
array(
[
'device_id' => $device['device_id'],
'port_id' => $if_id,
'peer_device_id' => $cpw_remote_device,
@ -45,7 +45,7 @@ if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
'pw_type' => $pw['cpwVcType'],
'pw_descr' => $pw['cpwVcDescr'],
'pw_psntype' => $pw['cpwVcPsnType'],
),
],
'pseudowires'
);
echo '+';
@ -57,7 +57,7 @@ if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
// Cycle the list of pseudowires we cached earlier and make sure we saw them again.
foreach ($pws_db as $pw_id => $pseudowire_id) {
if (empty($device['pws'][$pw_id])) {
dbDelete('pseudowires', '`pseudowire_id` = ?', array($pseudowire_id));
dbDelete('pseudowires', '`pseudowire_id` = ?', [$pseudowire_id]);
}
}

View File

@ -14,38 +14,37 @@
* @copyright 2019 LibreNMS
* @author Pavle Obradovic <pobradovic08@gmail.com>
*/
if ($device['os_group'] == 'cisco') {
$module = 'cisco-qfp';
/*
* CISCO-ENTITY-QFP-MIB::ceqfpSystemState values
*/
$system_states = array(
$system_states = [
1 => 'unknown',
2 => 'reset',
3 => 'init',
4 => 'active',
5 => 'activeSolo',
6 => 'standby',
7 => 'hotStandby'
);
7 => 'hotStandby',
];
/*
* CISCO-ENTITY-QFP-MIB::ceqfpSystemTrafficDirection values
*/
$system_traffic_direction = array (
$system_traffic_direction = [
1 => 'none',
2 => 'ingress',
3 => 'egress',
4 => 'both'
);
4 => 'both',
];
/*
* Get module's components for a device
*/
$component = new LibreNMS\Component();
$components = $component->getComponents($device['device_id'], array('type'=>$module));
$components = $component->getComponents($device['device_id'], ['type'=>$module]);
$components = $components[$device['device_id']];
/*
@ -67,15 +66,15 @@ if ($device['os_group'] == 'cisco') {
/*
* Component data array for `component_prefs`
*/
$component_data = array(
$component_data = [
'label' => 'qfp_' . $qfp_index,
'entPhysicalIndex' => $qfp_index,
'name' => $qfp_name,
'traffic_direction' => $system_traffic_direction[$data['ceqfpSystemTrafficDirection']],
'system_state' => $system_states[$data['ceqfpSystemState']],
'system_loads' => $data['ceqfpNumberSystemLoads'],
'system_last_load' => $data['ceqfpSystemLastLoadTime']
);
'system_last_load' => $data['ceqfpSystemLastLoadTime'],
];
/*
* Find existing component ID if QFP is already known

View File

@ -6,7 +6,7 @@ use LibreNMS\Util\IP;
if (Config::get('enable_sla') && $device['os_group'] == 'cisco') {
$slas = snmp_walk($device, 'ciscoRttMonMIB.ciscoRttMonObjects.rttMonCtrl', '-Osq', '+CISCO-RTTMON-MIB');
$sla_table = array();
$sla_table = [];
foreach (explode("\n", $slas) as $sla) {
$key_val = explode(' ', $sla, 2);
if (count($key_val) != 2) {
@ -29,16 +29,16 @@ if (Config::get('enable_sla') && $device['os_group'] == 'cisco') {
// var_dump($sla_table);
// Get existing SLAs
$existing_slas = dbFetchColumn('SELECT `sla_id` FROM `slas` WHERE `device_id` = :device_id AND `deleted` = 0', array('device_id' => $device['device_id']));
$existing_slas = dbFetchColumn('SELECT `sla_id` FROM `slas` WHERE `device_id` = :device_id AND `deleted` = 0', ['device_id' => $device['device_id']]);
foreach ($sla_table as $sla_nr => $sla_config) {
$query_data = array(
$query_data = [
'device_id' => $device['device_id'],
'sla_nr' => $sla_nr,
);
];
$sla_id = dbFetchCell('SELECT `sla_id` FROM `slas` WHERE `device_id` = :device_id AND `sla_nr` = :sla_nr', $query_data);
$data = array(
$data = [
'device_id' => $device['device_id'],
'sla_nr' => $sla_nr,
'owner' => $sla_config['rttMonCtrlAdminOwner'],
@ -47,7 +47,7 @@ if (Config::get('enable_sla') && $device['os_group'] == 'cisco') {
'status' => ($sla_config['rttMonCtrlAdminStatus'] == 'active') ? 1 : 0,
'opstatus' => ($sla_config['rttMonLatestRttOperSense'] == 'ok') ? 0 : 2,
'deleted' => 0,
);
];
// Some fallbacks for when the tag is empty
if (! $data['tag']) {
@ -80,7 +80,7 @@ if (Config::get('enable_sla') && $device['os_group'] == 'cisco') {
echo '+';
} else {
// Remove from the list
$existing_slas = array_diff($existing_slas, array($sla_id));
$existing_slas = array_diff($existing_slas, [$sla_id]);
dbUpdate($data, 'slas', 'sla_id = ?', [$sla_id]);
echo '.';

View File

@ -14,14 +14,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
global $debug;
// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco
use LibreNMS\Config;
if (Config::get('enable_vrf_lite_cisco')) {
$ids = array();
$ids = [];
// For the moment only will be cisco and the version 3
if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') {
@ -64,16 +63,16 @@ if (Config::get('enable_vrf_lite_cisco')) {
foreach ((array) $tableVrf as $context => $vrf) {
if ($debug) {
echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n");
echo "\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n";
}
$tmpVrf = dbFetchRow("SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=?", array(
$tmpVrf = dbFetchRow("SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=?", [
$device ['device_id'],
$context
));
$context,
]);
if (! empty($tmpVrf)) {
$ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id'];
$vrfUpdate=array();
$vrfUpdate = [];
foreach ($vrfUpdate as $key => $value) {
if ($vrf[$key] != $value) {
@ -81,17 +80,17 @@ if (Config::get('enable_vrf_lite_cisco')) {
}
}
if (! empty($vrfUpdate)) {
dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array(
$tmp['vrf_lite_cisco_id']
));
dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', [
$tmp['vrf_lite_cisco_id'],
]);
}
} else {
$id = dbInsert(array(
$id = dbInsert([
'device_id' => $device ['device_id'],
'context_name' => $context,
'intance_name' => $vrf['intance_name'],
'vrf_name' => $vrf['vrf_name']
), 'vrf_lite_cisco');
'vrf_name' => $vrf['vrf_name'],
], 'vrf_lite_cisco');
$ids[$id] = $id;
}
}
@ -99,8 +98,8 @@ if (Config::get('enable_vrf_lite_cisco')) {
}
//get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work
$tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array(
$device ['device_id']));
$tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", [
$device ['device_id'], ]);
$device['vrf_lite_cisco'] = $tmpVrfC;
//Delete all vrf that chaged
@ -109,7 +108,7 @@ if (Config::get('enable_vrf_lite_cisco')) {
}
if (! empty($ids)) {
foreach ($ids as $id) {
dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array($id));
dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', [$id]);
}
}
unset($ids);

View File

@ -1,4 +1,5 @@
<?php
//
// LibreNMS module to do device discovery by ARP table contents.
//
@ -34,10 +35,10 @@ $sql = '
';
// FIXME: Observium now uses ip_mac.ip_address in place of ipv4_mac.ipv4_address - why?
$names = array();
$ips = array();
$names = [];
$ips = [];
foreach (dbFetchRows($sql, array($deviceid)) as $entry) {
foreach (dbFetchRows($sql, [$deviceid]) as $entry) {
$ip = $entry['ipv4_address'];
$mac = $entry['mac_address'];
$if = $entry['port_id'];

View File

@ -89,13 +89,12 @@ if (($device['os'] == 'routeros')) {
$lldp_ports = snmpwalk_group($device, 'mtxrInterfaceStatsName', 'MIKROTIK-MIB');
$lldp_ports_num = snmpwalk_group($device, 'mtxrNeighborInterfaceID', 'MIKROTIK-MIB');
foreach ($lldp_array as $key => $lldp) {
$local_port_ifName = $lldp_ports[hexdec($lldp_ports_num[$key]['mtxrNeighborInterfaceID'])]['mtxrInterfaceStatsName'];
$local_port_id = find_port_id($local_port_ifName, null, $device['device_id']);
$interface = get_port_by_id($local_port_id);
if ($lldp['lldpRemPortIdSubtype'] == 3) { // 3 = macaddress
$remote_port_mac = str_replace(array(' ', ':', '-'), '', strtolower($lldp['lldpRemPortId']));
$remote_port_mac = str_replace([' ', ':', '-'], '', strtolower($lldp['lldpRemPortId']));
}
$remote_device_id = find_device_id($lldp['lldpRemSysName'], $lldp['lldpRemManAddr'], $remote_port_mac);
@ -239,7 +238,7 @@ if (($device['os'] == 'routeros')) {
// normalize MAC address if present
$remote_port_mac = '';
if ($lldp['lldpRemPortIdSubtype'] == 3) { // 3 = macaddress
$remote_port_mac = str_replace(array(' ', ':', '-'), '', strtolower($lldp['lldpRemPortId']));
$remote_port_mac = str_replace([' ', ':', '-'], '', strtolower($lldp['lldpRemPortId']));
}
$remote_device_id = find_device_id($lldp['lldpRemSysName'], $lldp['lldpRemManAddr'], $remote_port_mac);
@ -320,7 +319,7 @@ if (($device['os'] == 'routeros')) {
if (Config::get('autodiscovery.ospf') === true) {
echo ' OSPF Discovery: ';
$sql = 'SELECT DISTINCT(`ospfNbrIpAddr`),`device_id` FROM `ospf_nbrs` WHERE `device_id`=?';
foreach (dbFetchRows($sql, array($device['device_id'])) as $nbr) {
foreach (dbFetchRows($sql, [$device['device_id']]) as $nbr) {
try {
$ip = IP::parse($nbr['ospfNbrIpAddr']);
@ -346,7 +345,7 @@ if (Config::get('autodiscovery.ospf') === true) {
d_echo($link_exists);
$sql = "SELECT * FROM `links` AS L, `ports` AS I WHERE L.local_port_id = I.port_id AND I.device_id = ?";
foreach (dbFetchRows($sql, array($device['device_id'])) as $test) {
foreach (dbFetchRows($sql, [$device['device_id']]) as $test) {
$local_port_id = $test['local_port_id'];
$remote_hostname = $test['remote_hostname'];
$remote_port = $test['remote_port'];
@ -354,13 +353,13 @@ foreach (dbFetchRows($sql, array($device['device_id'])) as $test) {
if (! $link_exists[$local_port_id][$remote_hostname][$remote_port]) {
echo '-';
$rows = dbDelete('links', '`id` = ?', array($test['id']));
$rows = dbDelete('links', '`id` = ?', [$test['id']]);
d_echo("$rows deleted ");
}
}
// remove orphaned links
$deleted = (int)dbDeleteOrphans('links', array('devices.device_id.local_device_id'));
$deleted = (int) dbDeleteOrphans('links', ['devices.device_id.local_device_id']);
echo str_repeat('-', $deleted);
d_echo(" $deleted orphaned links deleted\n");

View File

@ -12,11 +12,11 @@ if (Config::get('enable_inventory')) {
// Delete any entries that have not been accounted for.
$sql = 'SELECT * FROM `entPhysical` WHERE `device_id` = ?';
foreach (dbFetchRows($sql, array($device['device_id'])) as $test) {
foreach (dbFetchRows($sql, [$device['device_id']]) as $test) {
$id = $test['entPhysicalIndex'];
if (! $valid[$id]) {
echo '-';
dbDelete('entPhysical', 'entPhysical_id = ?', array ($test['entPhysical_id']));
dbDelete('entPhysical', 'entPhysical_id = ?', [$test['entPhysical_id']]);
}
}
unset(

View File

@ -13,13 +13,13 @@
$comp_module = 'Cisco-CIMC';
$component = new LibreNMS\Component();
$components = $component->getComponents($device['device_id'], array('type'=>$comp_module));
$components = $component->getComponents($device['device_id'], ['type'=>$comp_module]);
// We only care about our device id.
$components = $components[$device['device_id']];
// Begin our master array, all other values will be processed into this array.
$tblCIMC = array();
$tblCIMC = [];
// Let's gather some data..
$tblUCSObjects = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.719.1', 2);
@ -32,14 +32,14 @@ if (is_null($tblUCSObjects)) {
// We have to error here or we will end up deleting all our components.
} else {
// No Error, lets process things.
echo("CIMC Hardware Found: ");
echo "CIMC Hardware Found: ";
// Make sure we have an array before we try to iterate over it
if (is_array($tblUCSObjects)) {
// Gather entPhysical data
$entmax = 0;
$entphysical = array();
$dbentphysical = $entries = dbFetchRows('SELECT * FROM entPhysical WHERE device_id=?', array($device['device_id']));
$entphysical = [];
$dbentphysical = $entries = dbFetchRows('SELECT * FROM entPhysical WHERE device_id=?', [$device['device_id']]);
foreach ($dbentphysical as $array) {
$entphysical[$array['entPhysicalVendorType']] = $array;
if ($array['entPhysicalIndex'] > $entmax) {
@ -48,7 +48,7 @@ if (is_null($tblUCSObjects)) {
}
// Let's extract any active faults, we will use them later.
$faults = array();
$faults = [];
foreach ($tblUCSObjects['1.3.6.1.4.1.9.9.719.1.1.1.1'][5] as $fid => $fobj) {
$fobj = preg_replace('/^\/?sys\//', '', $fobj);
$faults[$fobj] = $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.1.1.1'][3][$fid] . " - " . $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.1.1.1'][11][$fid];
@ -71,18 +71,18 @@ if (is_null($tblUCSObjects)) {
}
// Lets Set some defaults.
$entPhysicalData = array(
$entPhysicalData = [
'entPhysicalHardwareRev' => '',
'entPhysicalFirmwareRev' => '',
'entPhysicalSoftwareRev' => '',
'entPhysicalIsFRU' => 'FALSE',
);
];
switch ($tbl) {
// Chassis - rack-unit-1
case "1.3.6.1.4.1.9.9.719.1.9.35.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
$result['hwtype'] = 'chassis';
$result['id'] = $array[27][$key];
$result['label'] = $array[2][$key];
@ -116,7 +116,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'Chassis';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = $array[47][$key];
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -128,7 +128,7 @@ if (is_null($tblUCSObjects)) {
// System Board - rack-unit-1/board
case "1.3.6.1.4.1.9.9.719.1.9.6.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
$result['hwtype'] = 'board';
$result['id'] = $array[5][$key];
$result['label'] = $array[2][$key];
@ -152,7 +152,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'System Board';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = $array[14][$key];
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -164,7 +164,7 @@ if (is_null($tblUCSObjects)) {
// Memory Modules - rack-unit-1/board/memarray-1/mem-0
case "1.3.6.1.4.1.9.9.719.1.30.11.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
// If there is no memory module present, continue.
if ($array[17][$key] != 10) {
continue;
@ -194,7 +194,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'Memory';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = $array[19][$key];
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -206,7 +206,7 @@ if (is_null($tblUCSObjects)) {
// CPU's - rack-unit-1/board/cpu-1
case "1.3.6.1.4.1.9.9.719.1.41.9.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
// If there is no cpu present, continue.
if ($array[13][$key] != 10) {
continue;
@ -236,7 +236,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'Processor';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = $array[15][$key];
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -248,7 +248,7 @@ if (is_null($tblUCSObjects)) {
// SAS Storage Module - rack-unit-1/board/storage-SAS-2
case "1.3.6.1.4.1.9.9.719.1.45.1.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
$result['hwtype'] = 'sas-controller';
$result['id'] = substr($array[3][$key], 12);
$result['label'] = $array[2][$key];
@ -273,7 +273,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'Storage Module';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = $array[14][$key];
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -285,7 +285,7 @@ if (is_null($tblUCSObjects)) {
// SAS Disks - rack-unit-1/board/storage-SAS-2/disk-1
case "1.3.6.1.4.1.9.9.719.1.45.4.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
$result['hwtype'] = 'sas-disk';
$result['id'] = substr($array[3][$key], 5);
$result['label'] = $array[2][$key];
@ -321,7 +321,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'Disk';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = $array[12][$key];
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -333,7 +333,7 @@ if (is_null($tblUCSObjects)) {
// LUN's - rack-unit-1/board/storage-SAS-2/lun-0
case "1.3.6.1.4.1.9.9.719.1.45.8.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
$result['hwtype'] = 'lun';
$result['id'] = substr($array[3][$key], 4);
$result['label'] = $array[2][$key];
@ -369,7 +369,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'LUN';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = '';
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -381,7 +381,7 @@ if (is_null($tblUCSObjects)) {
// RAID Battery - rack-unit-1/board/storage-SAS-2/raid-battery
case "1.3.6.1.4.1.9.9.719.1.45.11.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
$result['hwtype'] = 'raid-battery';
$result['id'] = $array[3][$key];
$result['label'] = $array[2][$key];
@ -406,7 +406,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'RAID Battery';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = '';
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -418,7 +418,7 @@ if (is_null($tblUCSObjects)) {
// Fan's - rack-unit-1/fan-module-1-1/fan-1
case "1.3.6.1.4.1.9.9.719.1.15.12.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
$result['hwtype'] = 'fan';
$result['id'] = $array[8][$key] . "-" . substr($array[3][$key], 4);
$result['label'] = $array[2][$key];
@ -443,7 +443,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'FAN';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = '';
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -455,7 +455,7 @@ if (is_null($tblUCSObjects)) {
// PSU's - rack-unit-1/psu-1
case "1.3.6.1.4.1.9.9.719.1.15.56.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
$result['hwtype'] = 'psu';
$result['id'] = substr($array[3][$key], 4);
$result['label'] = $array[2][$key];
@ -480,7 +480,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'PSU';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = $array[13][$key];
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -492,7 +492,7 @@ if (is_null($tblUCSObjects)) {
// Adaptors - rack-unit-1/adaptor-1
case "1.3.6.1.4.1.9.9.719.1.3.85.1":
foreach ($array[3] as $key => $item) {
$result = array();
$result = [];
$result['hwtype'] = 'adaptor';
$result['id'] = substr($array[3][$key], 8);
$result['label'] = $array[2][$key];
@ -517,7 +517,7 @@ if (is_null($tblUCSObjects)) {
$entPhysicalData['entPhysicalName'] = 'Adaptor';
$entPhysicalData['entPhysicalDescr'] = $result['string'];
$entPhysicalData['entPhysicalSerialNum'] = $array[21][$key];
list($result['entPhysical'],$entPhysicalData['entPhysicalIndex']) = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
[$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
$valid[$entPhysicalData['entPhysicalIndex']] = 1;
// Add the result to the array.
@ -586,7 +586,7 @@ if (is_null($tblUCSObjects)) {
if ($found === false) {
// The component has not been found. we should delete it and it's entPhysical entry
echo "-";
dbDelete('entPhysical', '`entPhysical_id` = ?', array($array['entPhysical']));
dbDelete('entPhysical', '`entPhysical_id` = ?', [$array['entPhysical']]);
$component->deleteComponent($key);
}
}

View File

@ -5,11 +5,11 @@ use Illuminate\Support\Str;
echo "\nCaching OIDs:";
if ($device['os'] == 'junos') {
$entity_array = array();
$entity_array = [];
echo ' jnxBoxAnatomy';
$entity_array = snmpwalk_cache_oid($device, 'jnxBoxAnatomy', $entity_array, 'JUNIPER-MIB');
} elseif ($device['os'] == 'aruba-instant') {
$entity_array = array();
$entity_array = [];
echo 'aruba-instant';
$ai_mib = 'AI-AP-MIB';
@ -39,11 +39,11 @@ if ($device['os'] == 'junos') {
$entity_array = snmpwalk_group($device, 'aiAccessPointEntry', $ai_mib);
$instant_index = 2;
} elseif ($device['os'] == 'timos') {
$entity_array = array();
$entity_array = [];
echo 'tmnxHwObjs';
$entity_array = snmpwalk_cache_multi_oid($device, 'tmnxHwObjs', $entity_array, 'TIMETRA-CHASSIS-MIB', 'nokia');
} else {
$entity_array = array();
$entity_array = [];
echo ' entPhysicalEntry';
$entity_array = snmpwalk_cache_oid($device, 'entPhysicalEntry', $entity_array, 'ENTITY-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB');
@ -229,7 +229,7 @@ foreach ($entity_array as $entPhysicalIndex => $entry) {
}
// List of real names for cisco entities
$entPhysicalVendorTypes = array(
$entPhysicalVendorTypes = [
'cevC7xxxIo1feTxIsl' => 'C7200-IO-FE-MII',
'cevChassis7140Dualfe' => 'C7140-2FE',
'cevChassis7204' => 'C7204',
@ -248,7 +248,7 @@ foreach ($entity_array as $entPhysicalIndex => $entry) {
'cevPaA8tX21' => 'PA-8T-X21',
'cevMGBIC1000BaseLX' => '1000BaseLX GBIC',
'cevPort10GigBaseLR' => '10GigBaseLR',
);
];
if ($entPhysicalVendorTypes[$entPhysicalVendorType] && ! $entPhysicalModelName) {
$entPhysicalModelName = $entPhysicalVendorTypes[$entPhysicalVendorType];

View File

@ -86,7 +86,7 @@ $nbsCmmcPortSensor_array = [
];
foreach ($chassis_array as $nbsCmmcChassis => $chassis_contents) {
list($chassisHardwareRev, $chassisFirmwareRev) = explode(', ', $chassis_contents['nbsCmmcChassisHardwareRevision']);
[$chassisHardwareRev, $chassisFirmwareRev] = explode(', ', $chassis_contents['nbsCmmcChassisHardwareRevision']);
// Discover the chassis
$entity_array[] = [
'entPhysicalIndex' => $chassis_contents['nbsCmmcChassisIfIndex'] . "00",
@ -188,8 +188,6 @@ foreach ($chassis_array as $nbsCmmcChassis => $chassis_contents) {
}
}
foreach ($slot_array as $nbsCmmcSlot => $slot_contents) {
// Obtain the nbsCmmcChassisIfIndex of the chassis which houses this slot
$nbsCmmcChassisIfIndex = $chassis_array[$slot_contents['nbsCmmcSlotChassisIndex']]['nbsCmmcChassisIfIndex'];
@ -207,7 +205,7 @@ foreach ($slot_array as $nbsCmmcSlot => $slot_contents) {
'entPhysicalIsFRU' => 'false',
];
if (isset($slot_contents['nbsCmmcSlotIfIndex']) && $slot_contents['nbsCmmcSlotIfIndex'] != '-1') {
list($cardHardwareRev, $cardFirmwareRev, $cardOtherRev) = explode(', ', $slot_contents['nbsCmmcSlotHardwareRevision']);
[$cardHardwareRev, $cardFirmwareRev, $cardOtherRev] = explode(', ', $slot_contents['nbsCmmcSlotHardwareRevision']);
// Discover the card
$entity_array[] = [
'entPhysicalIndex' => $slot_contents['nbsCmmcSlotIfIndex'] . "01",
@ -270,7 +268,7 @@ foreach ($port_array as $nbsCmmcPort => $port_contents) {
// If one runs a command like "show 1.1.1 | grep Part" on a port with a genuine pluggable transceiver,
// CLI output like "Part #/Rev: SFP-10GDWZR-22/0001" indicates / is considered to be the string delimiter.
// However, non-genuine pluggable transceivers may not adhere to this format.
list($nbsCmmcPortModelName, $nbsCmmcPortHardwareRev) = explode('/', $port_contents['nbsCmmcPortPartRev']);
[$nbsCmmcPortModelName, $nbsCmmcPortHardwareRev] = explode('/', $port_contents['nbsCmmcPortPartRev']);
} else {
$nbsCmmcPortType = 'Built-in';

View File

@ -111,13 +111,13 @@ foreach ($sdbMgmtCtrlDevUnitAddressArray as $sdbMgmtCtrlDevUnitAddress => $sdbDe
$sensorIndex = $sdbMgmtCtrlDevUnitAddress * 1000000 + 300000 + $sdbDevSnsIndex * 1000; // +300k for the third top-level index namespace. Add 1000 * sdbDevSnsIndex which goes up to 16. Leave 3 variable digits at the end.
$entPhysicalName = "External Sensor #" . $sdbDevSnsIndex;
switch ($sdbDevSnsTypeArray[$sdbDevIdIndex][$sdbDevSnsIndex]) {
case ('T'):
case 'T':
$entPhysicalDescr = "Temperature sensor (°C)";
break;
case ('H'):
case 'H':
$entPhysicalDescr = "Humidity sensor (%)";
break;
case ('I'):
case 'I':
$entPhysicalDescr = "Dry switch contact (binary)";
break;
}

View File

@ -22,10 +22,9 @@
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
$entPhysical = dbFetchRows(
'SELECT entPhysical_id, entPhysicalIndex FROM entPhysical WHERE device_id=?',
array($device['device_id'])
[$device['device_id']]
);
if (! empty($entPhysical)) {
@ -33,7 +32,7 @@ if (!empty($entPhysical)) {
$entPhysical = array_column($entPhysical, 'entPhysical_id', 'entPhysicalIndex');
$state_data = snmpwalk_group($device, 'entStateTable', 'ENTITY-STATE-MIB');
$db_states = dbFetchRows('SELECT * FROM entityState WHERE device_id=?', array($device['device_id']));
$db_states = dbFetchRows('SELECT * FROM entityState WHERE device_id=?', [$device['device_id']]);
$db_states = array_by_column($db_states, 'entPhysical_id');
foreach ($state_data as $index => $state) {
@ -44,7 +43,7 @@ if (!empty($entPhysical)) {
if (empty($state['entStateLastChanged'])) {
$state['entStateLastChanged'] = null;
} else {
list($date, $time, $tz) = explode(',', $state['entStateLastChanged']);
[$date, $time, $tz] = explode(',', $state['entStateLastChanged']);
try {
$lastChanged = new DateTime("$date $time", new DateTimeZone($tz));
$state['entStateLastChanged'] = $lastChanged
@ -61,10 +60,10 @@ if (!empty($entPhysical)) {
if (! empty($update)) {
if (array_key_exists('entStateLastChanged', $update) && is_null($update['entStateLastChanged'])) {
$update['entStateLastChanged'] = array('NULL');
$update['entStateLastChanged'] = ['NULL'];
}
dbUpdate($update, 'entityState', 'entity_state_id=?', array($db_state['entity_state_id']));
dbUpdate($update, 'entityState', 'entity_state_id=?', [$db_state['entity_state_id']]);
d_echo("Updating entity state: ", 'U');
d_echo($update);
} else {

View File

@ -3,15 +3,15 @@
// Build a dictionary of vlans in database
use LibreNMS\Config;
$vlans_dict = array();
foreach (dbFetchRows("SELECT `vlan_id`, `vlan_vlan` from `vlans` WHERE `device_id` = ?", array($device['device_id'])) as $vlan_entry) {
$vlans_dict = [];
foreach (dbFetchRows("SELECT `vlan_id`, `vlan_vlan` from `vlans` WHERE `device_id` = ?", [$device['device_id']]) as $vlan_entry) {
$vlans_dict[$vlan_entry['vlan_vlan']] = $vlan_entry['vlan_id'];
}
$vlans_by_id = array_flip($vlans_dict);
// Build table of existing vlan/mac table
$existing_fdbs = array();
$sql_result = dbFetchRows("SELECT * FROM `ports_fdb` WHERE `device_id` = ?", array($device['device_id']));
$existing_fdbs = [];
$sql_result = dbFetchRows("SELECT * FROM `ports_fdb` WHERE `device_id` = ?", [$device['device_id']]);
foreach ($sql_result as $entry) {
$existing_fdbs[(int) $entry['vlan_id']][$entry['mac_address']] = $entry;
}

View File

@ -23,23 +23,22 @@
* @author Tony Murray <murraytony@gmail.com>
* @author JoseUPV
*/
if (empty($fdbPort_table)) { // no empty if come from aos7 script
// try nokia/ALCATEL-IND1-MAC-ADDRESS-MIB::slMacAddressDisposition
$dot1d = snmpwalk_group($device, 'slMacAddressDisposition', 'ALCATEL-IND1-MAC-ADDRESS-MIB', 0, array(), 'nokia');
$dot1d = snmpwalk_group($device, 'slMacAddressDisposition', 'ALCATEL-IND1-MAC-ADDRESS-MIB', 0, [], 'nokia');
if (! empty($dot1d)) {
echo 'AOS6 MAC-ADDRESS-MIB: ';
$fdbPort_table=array();
$fdbPort_table = [];
foreach ($dot1d['slMacAddressDisposition'] as $portLocal => $data) {
foreach ($data as $vlanLocal => $data2) {
$fdbPort_table[$vlanLocal]=array('dot1qTpFdbPort' => array_combine(array_keys($data2), array_fill(0, count($data2), $portLocal)));
$fdbPort_table[$vlanLocal] = ['dot1qTpFdbPort' => array_combine(array_keys($data2), array_fill(0, count($data2), $portLocal))];
}
}
}
}
if (! empty($fdbPort_table)) {
// Build dot1dBasePort to port_id dictionary
$portid_dict = array();
$portid_dict = [];
$dot1dBasePortIfIndex = snmpwalk_group($device, 'dot1dBasePortIfIndex', 'BRIDGE-MIB');
foreach ($dot1dBasePortIfIndex as $portLocal => $data) {
$port = get_port_by_index_cache($device['device_id'], $data['dot1dBasePortIfIndex']);

View File

@ -25,15 +25,15 @@
*/
// Try nokia/aos7/ALCATEL-IND1-MAC-ADDRESS-MIB::slMacAddressGblManagement first
$dot1d = snmpwalk_group($device, 'slMacAddressGblManagement', 'ALCATEL-IND1-MAC-ADDRESS-MIB', 0, array(), 'nokia/aos7');
$dot1d = snmpwalk_group($device, 'slMacAddressGblManagement', 'ALCATEL-IND1-MAC-ADDRESS-MIB', 0, [], 'nokia/aos7');
if (! empty($dot1d)) {
echo 'AOS7+ MAC-ADDRESS-MIB:';
$fdbPort_table=array();
$fdbPort_table = [];
foreach ($dot1d['slMacAddressGblManagement'] as $slMacDomain => $data) {
foreach ($data as $slLocaleType => $data2) {
foreach ($data2 as $portLocal => $data3) {
foreach ($data3 as $vlanLocal => $data4) {
$fdbPort_table[$vlanLocal]=array('dot1qTpFdbPort' => array_combine(array_keys($data4[0]), array_fill(0, count($data4[0]), $portLocal)));
$fdbPort_table[$vlanLocal] = ['dot1qTpFdbPort' => array_combine(array_keys($data4[0]), array_fill(0, count($data4[0]), $portLocal))];
}
}
}

View File

@ -37,13 +37,13 @@ if (!empty($fdbPort_table)) {
$data_oid = 'dot1dTpFdbPort';
if (! empty($dot1d)) {
echo 'BRIDGE-MIB: ';
$fdbPort_table = array(0 => $dot1d); // dont' have VLAN, so use 0
$fdbPort_table = [0 => $dot1d]; // dont' have VLAN, so use 0
}
}
if (! empty($fdbPort_table)) {
// Build dot1dBasePort to port_id dictionary
$portid_dict = array();
$portid_dict = [];
$dot1dBasePortIfIndex = snmpwalk_group($device, 'dot1dBasePortIfIndex', 'BRIDGE-MIB');
foreach ($fdbPort_table as $vlan => $data) {

View File

@ -35,13 +35,13 @@ if (!empty($fdbPort_table)) {
$data_oid = 'dot1dTpFdbPort';
if (! empty($dot1d)) {
echo 'BRIDGE-MIB: ';
$fdbPort_table = array(0 => $dot1d); // dont' have VLAN, so use 0
$fdbPort_table = [0 => $dot1d]; // dont' have VLAN, so use 0
}
}
if (! empty($fdbPort_table)) {
// Build dot1dBasePort to port_id dictionary
$portid_dict = array();
$portid_dict = [];
$dot1dBasePortIfIndex = snmpwalk_group($device, 'dot1dBasePortIfIndex', 'BRIDGE-MIB');
foreach ($dot1dBasePortIfIndex as $portLocal => $data) {
$port = get_port_by_index_cache($device['device_id'], $data['dot1dBasePortIfIndex']);
@ -50,7 +50,7 @@ if (!empty($fdbPort_table)) {
// Build VLAN fdb index to real VLAN ID dictionary
$vlan_cur_table = snmpwalk_group($device, 'dot1qVlanFdbId', 'Q-BRIDGE-MIB', 2);
$vlan_fdb_dict = array();
$vlan_fdb_dict = [];
// Indexed first by dot1qVlanTimeMark, which we ignore
foreach ($vlan_cur_table as $dot1qVlanTimeMark => $a) {

View File

@ -22,7 +22,6 @@
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
$binding = snmpwalk_group($device, 'agentDynamicDsBindingTable', 'EdgeSwitch-SWITCHING-MIB', 1);
foreach ($binding as $mac => $data) {

View File

@ -8,22 +8,22 @@ foreach ($vtpdomains as $vtpdomain_id => $vtpdomain) {
foreach ($vlans[$vtpdomain_id] as $vlan_raw => $vlan) {
echo "$vlan_raw ";
if (! array_key_exists($vlan_raw, $vlans_dict)) {
$newvlan_id = dbInsert(array(
$newvlan_id = dbInsert([
'device_id' => $device['device_id'],
'vlan_domain' => $vtpdomain_id,
'vlan_vlan' => $vlan_raw,
'vlan_name' => $vlan['vtpVlanName'],
'vlan_type' => $vlan['vtpVlanType']
), 'vlans');
'vlan_type' => $vlan['vtpVlanType'],
], 'vlans');
$vlans_dict[$vlan_raw] = $newvlan_id;
}
if (($vlan['vtpVlanState'] === '1') && ($vlan_raw < 1002 || $vlan_raw > 1005)) {
$device_vlan = array_merge($device, array('community' => $device['community'] . '@' . $vlan_raw, 'context_name' => "vlan-$vlan_raw"));
$device_vlan = array_merge($device, ['community' => $device['community'] . '@' . $vlan_raw, 'context_name' => "vlan-$vlan_raw"]);
$fdbPort_table = snmpwalk_group($device_vlan, 'dot1dTpFdbPort', 'BRIDGE-MIB', 0);
$portid_dict = array();
$portid_dict = [];
$dot1dBasePortIfIndex = snmpwalk_group($device_vlan, 'dot1dBasePortIfIndex', 'BRIDGE-MIB');
foreach ($dot1dBasePortIfIndex as $portLocal => $data) {
$port = get_port_by_index_cache($device['device_id'], $data['dot1dBasePortIfIndex']);

View File

@ -14,12 +14,12 @@
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Device\YamlDiscovery;
use LibreNMS\Exceptions\HostExistsException;
use LibreNMS\Exceptions\InvalidIpException;
use LibreNMS\OS;
use LibreNMS\Util\IP;
use LibreNMS\Util\IPv6;
use LibreNMS\Device\YamlDiscovery;
function discover_new_device($hostname, $device = '', $method = '', $interface = '')
{
@ -50,6 +50,7 @@ function discover_new_device($hostname, $device = '', $method = '', $interface =
}
} else {
d_echo("Discovery failed: '$hostname' is not a valid ip or dns name\n");
return false;
}
@ -60,11 +61,13 @@ function discover_new_device($hostname, $device = '', $method = '', $interface =
$ip = IP::parse($ip, true);
if ($ip->inNetworks(Config::get('autodiscovery.nets-exclude'))) {
d_echo("$ip in an excluded network - skipping\n");
return false;
}
if (! $ip->inNetworks(Config::get('nets'))) {
d_echo("$ip not in a matched network - skipping\n");
return false;
}
@ -126,7 +129,7 @@ function discover_device(&$device, $force_module = false)
global $valid;
$valid = array();
$valid = [];
// Reset $valid array
$attribs = DeviceCache::getPrimary()->getAttribs();
$device['attribs'] = $attribs;
@ -141,8 +144,8 @@ function discover_device(&$device, $force_module = false)
return false;
}
$discovery_devices = Config::get('discovery_modules', array());
$discovery_devices = array('core' => true) + $discovery_devices;
$discovery_devices = Config::get('discovery_modules', []);
$discovery_devices = ['core' => true] + $discovery_devices;
foreach ($discovery_devices as $module => $module_status) {
$os_module_status = Config::getOsSetting($device['os'], "discovery_modules.$module");
@ -184,11 +187,12 @@ function discover_device(&$device, $force_module = false)
$device_time = round(microtime(true) - $device_start, 3);
dbUpdate(array('last_discovered' => array('NOW()'), 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id']));
dbUpdate(['last_discovered' => ['NOW()'], 'last_discovered_timetaken' => $device_time], 'devices', '`device_id` = ?', [$device['device_id']]);
echo "Discovered in $device_time seconds\n";
echo PHP_EOL;
return true;
}
//end discover_device()
@ -214,10 +218,10 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
if (isset($warn_limit, $low_warn_limit) && $low_warn_limit > $warn_limit) {
// Fix high/low thresholds (i.e. on negative numbers)
list($warn_limit, $low_warn_limit) = [$low_warn_limit, $warn_limit];
[$warn_limit, $low_warn_limit] = [$low_warn_limit, $warn_limit];
}
if (dbFetchCell('SELECT COUNT(sensor_id) FROM `sensors` WHERE `poller_type`= ? AND `sensor_class` = ? AND `device_id` = ? AND sensor_type = ? AND `sensor_index` = ?', array($poller_type, $class, $device['device_id'], $type, (string)$index)) == '0') {
if (dbFetchCell('SELECT COUNT(sensor_id) FROM `sensors` WHERE `poller_type`= ? AND `sensor_class` = ? AND `device_id` = ? AND sensor_type = ? AND `sensor_index` = ?', [$poller_type, $class, $device['device_id'], $type, (string) $index]) == '0') {
if ($guess_limits && is_null($high_limit)) {
$high_limit = sensor_limit($class, $current);
}
@ -228,10 +232,10 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
if (! is_null($high_limit) && $low_limit > $high_limit) {
// Fix high/low thresholds (i.e. on negative numbers)
list($high_limit, $low_limit) = array($low_limit, $high_limit);
[$high_limit, $low_limit] = [$low_limit, $high_limit];
}
$insert = array(
$insert = [
'poller_type' => $poller_type,
'sensor_class' => $class,
'device_id' => $device['device_id'],
@ -250,7 +254,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
'entPhysicalIndex_measured' => $entPhysicalIndex_measured,
'user_func' => $user_func,
'group' => $group,
);
];
foreach ($insert as $key => $val_check) {
if (! isset($val_check)) {
@ -265,7 +269,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
echo '+';
log_event('Sensor Added: ' . $class . ' ' . $type . ' ' . $index . ' ' . $descr, $device, 'sensor', 3, $inserted);
} else {
$sensor_entry = dbFetchRow('SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? AND `sensor_type` = ? AND `sensor_index` = ?', array($class, $device['device_id'], $type, (string)$index));
$sensor_entry = dbFetchRow('SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? AND `sensor_type` = ? AND `sensor_index` = ?', [$class, $device['device_id'], $type, (string) $index]);
if (! isset($high_limit)) {
if ($guess_limits && ! $sensor_entry['sensor_limit']) {
@ -289,12 +293,12 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
// Fix high/low thresholds (i.e. on negative numbers)
if (isset($high_limit) && $low_limit > $high_limit) {
list($high_limit, $low_limit) = array($low_limit, $high_limit);
[$high_limit, $low_limit] = [$low_limit, $high_limit];
}
if ($high_limit != $sensor_entry['sensor_limit'] && $sensor_entry['sensor_custom'] == 'No') {
$update = array('sensor_limit' => ($high_limit == null ? array('NULL') : $high_limit));
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id']));
$update = ['sensor_limit' => ($high_limit == null ? ['NULL'] : $high_limit)];
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', [$sensor_entry['sensor_id']]);
d_echo("( $updated updated )\n");
echo 'H';
@ -302,8 +306,8 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
}
if ($sensor_entry['sensor_limit_low'] != $low_limit && $sensor_entry['sensor_custom'] == 'No') {
$update = array('sensor_limit_low' => ($low_limit == null ? array('NULL') : $low_limit));
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id']));
$update = ['sensor_limit_low' => ($low_limit == null ? ['NULL'] : $low_limit)];
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', [$sensor_entry['sensor_id']]);
d_echo("( $updated updated )\n");
echo 'L';
@ -311,8 +315,8 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
}
if ($warn_limit != $sensor_entry['sensor_limit_warn'] && $sensor_entry['sensor_custom'] == 'No') {
$update = array('sensor_limit_warn' => ($warn_limit == null ? array('NULL') : $warn_limit));
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id']));
$update = ['sensor_limit_warn' => ($warn_limit == null ? ['NULL'] : $warn_limit)];
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', [$sensor_entry['sensor_id']]);
d_echo("( $updated updated )\n");
echo 'WH';
@ -320,8 +324,8 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
}
if ($sensor_entry['sensor_limit_low_warn'] != $low_warn_limit && $sensor_entry['sensor_custom'] == 'No') {
$update = array('sensor_limit_low_warn' => ($low_warn_limit == null ? array('NULL') : $low_warn_limit));
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id']));
$update = ['sensor_limit_low_warn' => ($low_warn_limit == null ? ['NULL'] : $low_warn_limit)];
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', [$sensor_entry['sensor_id']]);
d_echo("( $updated updated )\n");
echo 'WL';
@ -340,7 +344,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
) {
echo '.';
} else {
$update = array(
$update = [
'sensor_oid' => $oid,
'sensor_descr' => $descr,
'sensor_multiplier' => $multiplier,
@ -349,8 +353,8 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
'entPhysicalIndex_measured' => $entPhysicalIndex_measured,
'user_func' => $user_func,
'group' => $group,
);
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id']));
];
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', [$sensor_entry['sensor_id']]);
echo 'U';
log_event('Sensor Updated: ' . $class . ' ' . $type . ' ' . $index . ' ' . $descr, $device, 'sensor', 3, $sensor_id);
d_echo("( $updated updated )\n");
@ -442,7 +446,7 @@ function sensor_limit($class, $current)
function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp')
{
$entries = dbFetchRows('SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?', array($class, $device['device_id'], $poller_type));
$entries = dbFetchRows('SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?', [$class, $device['device_id'], $poller_type]);
if (count($entries)) {
foreach ($entries as $entry) {
@ -454,9 +458,9 @@ function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp')
if (! $valid[$class][$type][$index]) {
echo '-';
if ($class == 'state') {
dbDelete('sensors_to_state_indexes', '`sensor_id` = ?', array($entry['sensor_id']));
dbDelete('sensors_to_state_indexes', '`sensor_id` = ?', [$entry['sensor_id']]);
}
dbDelete('sensors', '`sensor_id` = ?', array($entry['sensor_id']));
dbDelete('sensors', '`sensor_id` = ?', [$entry['sensor_id']]);
log_event('Sensor Deleted: ' . $entry['sensor_class'] . ' ' . $entry['sensor_type'] . ' ' . $entry['sensor_index'] . ' ' . $entry['sensor_descr'], $device, 'sensor', 3, $sensor_id);
}
@ -472,8 +476,8 @@ function discover_juniAtmVp(&$valid, $device, $port_id, $vp_id, $vp_descr)
{
d_echo("Discover Juniper ATM VP: $port_id, $vp_id, $vp_descr\n");
if (dbFetchCell('SELECT COUNT(*) FROM `juniAtmVp` WHERE `port_id` = ? AND `vp_id` = ?', array($port_id, $vp_id)) == '0') {
$inserted = dbInsert(array('port_id' => $port_id, 'vp_id' => $vp_id, 'vp_descr' => $vp_descr), 'juniAtmVp');
if (dbFetchCell('SELECT COUNT(*) FROM `juniAtmVp` WHERE `port_id` = ? AND `vp_id` = ?', [$port_id, $vp_id]) == '0') {
$inserted = dbInsert(['port_id' => $port_id, 'vp_id' => $vp_id, 'vp_descr' => $vp_descr], 'juniAtmVp');
d_echo("( $inserted inserted )\n");
// FIXME vv no $device!
@ -495,14 +499,14 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
if (dbFetchCell(
'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?',
array(
[
$remote_hostname,
$local_port_id,
$protocol,
$remote_port,
)
]
) == '0') {
$insert_data = array(
$insert_data = [
'local_port_id' => $local_port_id,
'local_device_id' => $local_device_id,
'protocol' => $protocol,
@ -511,7 +515,7 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
'remote_port' => $remote_port,
'remote_platform' => $remote_platform,
'remote_version' => $remote_version,
);
];
if (! empty($remote_port_id)) {
$insert_data['remote_port_id'] = (int) $remote_port_id;
@ -524,22 +528,22 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
} else {
$sql = 'SELECT `id`,`local_device_id`,`remote_platform`,`remote_version`,`remote_device_id`,`remote_port_id` FROM `links`';
$sql .= ' WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?';
$data = dbFetchRow($sql, array($remote_hostname, $local_port_id, $protocol, $remote_port));
$data = dbFetchRow($sql, [$remote_hostname, $local_port_id, $protocol, $remote_port]);
$update_data = array(
$update_data = [
'local_device_id' => $local_device_id,
'remote_platform' => $remote_platform,
'remote_version' => $remote_version,
'remote_device_id' => (int) $remote_device_id,
'remote_port_id' => (int)$remote_port_id
);
'remote_port_id' => (int) $remote_port_id,
];
$id = $data['id'];
unset($data['id']);
if ($data == $update_data) {
echo '.';
} else {
$updated = dbUpdate($update_data, 'links', '`id` = ?', array($id));
$updated = dbUpdate($update_data, 'links', '`id` = ?', [$id]);
echo 'U';
d_echo("( $updated updated )");
}//end if
@ -557,7 +561,7 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size,
d_echo("Discover Storage: $index, $type, $mib, $descr, $size, $units, $used\n");
if ($descr && $size > '0') {
$storage = dbFetchRow('SELECT * FROM `storage` WHERE `storage_index` = ? AND `device_id` = ? AND `storage_mib` = ?', array($index, $device['device_id'], $mib));
$storage = dbFetchRow('SELECT * FROM `storage` WHERE `storage_index` = ? AND `device_id` = ? AND `storage_mib` = ?', [$index, $device['device_id'], $mib]);
if ($storage === false || ! count($storage)) {
if (Config::getOsSetting($device['os'], 'storage_perc_warn')) {
$perc_warn = Config::getOsSetting($device['os'], 'storage_perc_warn');
@ -566,7 +570,7 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size,
}
$insert = dbInsert(
array(
[
'device_id' => $device['device_id'],
'storage_descr' => $descr,
'storage_index' => $index,
@ -576,13 +580,13 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size,
'storage_size' => $size,
'storage_used' => $used,
'storage_perc_warn' => $perc_warn,
),
],
'storage'
);
echo '+';
} else {
$updated = dbUpdate(array('storage_descr' => $descr, 'storage_type' => $type, 'storage_units' => $units, 'storage_size' => $size), 'storage', '`device_id` = ? AND `storage_index` = ? AND `storage_mib` = ?', array($device['device_id'], $index, $mib));
$updated = dbUpdate(['storage_descr' => $descr, 'storage_type' => $type, 'storage_units' => $units, 'storage_size' => $size], 'storage', '`device_id` = ? AND `storage_index` = ? AND `storage_mib` = ?', [$device['device_id'], $index, $mib]);
if ($updated) {
echo 'U';
} else {
@ -602,8 +606,8 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec
if ($descr) {
$descr = trim(str_replace('"', '', $descr));
if (dbFetchCell('SELECT COUNT(processor_id) FROM `processors` WHERE `processor_index` = ? AND `device_id` = ? AND `processor_type` = ?', array($index, $device['device_id'], $type)) == '0') {
$insert_data = array(
if (dbFetchCell('SELECT COUNT(processor_id) FROM `processors` WHERE `processor_index` = ? AND `device_id` = ? AND `processor_type` = ?', [$index, $device['device_id'], $type]) == '0') {
$insert_data = [
'device_id' => $device['device_id'],
'processor_descr' => $descr,
'processor_index' => $index,
@ -611,7 +615,7 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec
'processor_usage' => $current,
'processor_type' => $type,
'processor_precision' => $precision,
);
];
$insert_data['hrDeviceIndex'] = (int) $hrDeviceIndex;
$insert_data['entPhysicalIndex'] = (int) $entPhysicalIndex;
@ -621,13 +625,13 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec
log_event('Processor added: type ' . $type . ' index ' . $index . ' descr ' . $descr, $device, 'processor', 3, $inserted);
} else {
echo '.';
$update_data = array(
$update_data = [
'processor_descr' => $descr,
'processor_oid' => $oid,
'processor_usage' => $current,
'processor_precision' => $precision,
);
dbUpdate($update_data, 'processors', '`device_id`=? AND `processor_index`=? AND `processor_type`=?', array($device['device_id'], $index, $type));
];
dbUpdate($update_data, 'processors', '`device_id`=? AND `processor_index`=? AND `processor_type`=?', [$device['device_id'], $index, $type]);
}//end if
$valid[$type][$index] = 1;
}//end if
@ -637,15 +641,14 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec
function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = '1', $entPhysicalIndex = null, $hrDeviceIndex = null, $perc_warn = '90')
{
$descr = substr($descr, 0, 64);
d_echo("Discover Mempool: $index, $type, $descr, $precision, $entPhysicalIndex, $hrDeviceIndex, $perc_warn\n");
// FIXME implement the mempool_perc, mempool_used, etc.
if ($descr) {
if (dbFetchCell('SELECT COUNT(mempool_id) FROM `mempools` WHERE `mempool_index` = ? AND `device_id` = ? AND `mempool_type` = ?', array($index, $device['device_id'], $type)) == '0') {
$insert_data = array(
if (dbFetchCell('SELECT COUNT(mempool_id) FROM `mempools` WHERE `mempool_index` = ? AND `device_id` = ? AND `mempool_type` = ?', [$index, $device['device_id'], $type]) == '0') {
$insert_data = [
'device_id' => $device['device_id'],
'mempool_descr' => $descr,
'mempool_index' => $index,
@ -656,7 +659,7 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision =
'mempool_free' => 0,
'mempool_total' => 0,
'mempool_perc_warn' => $perc_warn,
);
];
if (is_numeric($entPhysicalIndex)) {
$insert_data['entPhysicalIndex'] = $entPhysicalIndex;
@ -671,9 +674,9 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision =
log_event('Memory pool added: type ' . $type . ' index ' . $index . ' descr ' . $descr, $device, 'mempool', 3, $inserted);
} else {
echo '.';
$update_data = array(
$update_data = [
'mempool_descr' => $descr,
);
];
if (is_numeric($entPhysicalIndex)) {
$update_data['entPhysicalIndex'] = $entPhysicalIndex;
@ -683,7 +686,7 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision =
$update_data['hrDeviceIndex'] = $hrDeviceIndex;
}
dbUpdate($update_data, 'mempools', 'device_id=? AND mempool_index=? AND mempool_type=?', array($device['device_id'], $index, $type));
dbUpdate($update_data, 'mempools', 'device_id=? AND mempool_index=? AND mempool_type=?', [$device['device_id'], $index, $type]);
}//end if
$valid[$type][$index] = 1;
}//end if
@ -695,16 +698,16 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity
{
d_echo("Discover Toner: $oid, $index, $type, $descr, $capacity_oid, $capacity, $current\n");
if (dbFetchCell('SELECT COUNT(toner_id) FROM `toner` WHERE device_id = ? AND toner_type = ? AND `toner_index` = ? AND `toner_oid` =?', array($device['device_id'], $type, $index, $oid)) == '0') {
$inserted = dbInsert(array('device_id' => $device['device_id'], 'toner_oid' => $oid, 'toner_capacity_oid' => $capacity_oid, 'toner_index' => $index, 'toner_type' => $type, 'toner_descr' => $descr, 'toner_capacity' => $capacity, 'toner_current' => $current), 'toner');
if (dbFetchCell('SELECT COUNT(toner_id) FROM `toner` WHERE device_id = ? AND toner_type = ? AND `toner_index` = ? AND `toner_oid` =?', [$device['device_id'], $type, $index, $oid]) == '0') {
$inserted = dbInsert(['device_id' => $device['device_id'], 'toner_oid' => $oid, 'toner_capacity_oid' => $capacity_oid, 'toner_index' => $index, 'toner_type' => $type, 'toner_descr' => $descr, 'toner_capacity' => $capacity, 'toner_current' => $current], 'toner');
echo '+';
log_event('Toner added: type ' . $type . ' index ' . $index . ' descr ' . $descr, $device, 'toner', 3, $inserted);
} else {
$toner_entry = dbFetchRow('SELECT * FROM `toner` WHERE `device_id` = ? AND `toner_type` = ? AND `toner_index` =?', array($device['device_id'], $type, $index));
$toner_entry = dbFetchRow('SELECT * FROM `toner` WHERE `device_id` = ? AND `toner_type` = ? AND `toner_index` =?', [$device['device_id'], $type, $index]);
if ($oid == $toner_entry['toner_oid'] && $descr == $toner_entry['toner_descr'] && $capacity == $toner_entry['toner_capacity'] && $capacity_oid == $toner_entry['toner_capacity_oid']) {
echo '.';
} else {
dbUpdate(array('toner_descr' => $descr, 'toner_oid' => $oid, 'toner_capacity_oid' => $capacity_oid, 'toner_capacity' => $capacity), 'toner', 'device_id=? AND toner_type=? AND `toner_index`=?', array($device['device_id'], $type, $index));
dbUpdate(['toner_descr' => $descr, 'toner_oid' => $oid, 'toner_capacity_oid' => $capacity_oid, 'toner_capacity' => $capacity], 'toner', 'device_id=? AND toner_type=? AND `toner_index`=?', [$device['device_id'], $type, $index]);
echo 'U';
}
}
@ -719,8 +722,8 @@ function discover_entity_physical(&$valid, $device, $entPhysicalIndex, $entPhysi
d_echo("Discover Inventory Item: $entPhysicalIndex, $entPhysicalDescr, $entPhysicalClass, $entPhysicalName, $entPhysicalModelName, $entPhysicalSerialNum, $entPhysicalContainedIn, $entPhysicalMfgName, $entPhysicalParentRelPos, $entPhysicalVendorType, $entPhysicalHardwareRev, $entPhysicalFirmwareRev, $entPhysicalSoftwareRev, $entPhysicalIsFRU, $entPhysicalAlias, $entPhysicalAssetID, $ifIndex\n");
if ($entPhysicalDescr || $entPhysicalName) {
if (dbFetchCell('SELECT COUNT(entPhysical_id) FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalIndex` = ?', array($device['device_id'], $entPhysicalIndex)) == '0') {
$insert_data = array(
if (dbFetchCell('SELECT COUNT(entPhysical_id) FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalIndex` = ?', [$device['device_id'], $entPhysicalIndex]) == '0') {
$insert_data = [
'device_id' => $device['device_id'],
'entPhysicalIndex' => $entPhysicalIndex,
'entPhysicalDescr' => $entPhysicalDescr,
@ -738,7 +741,7 @@ function discover_entity_physical(&$valid, $device, $entPhysicalIndex, $entPhysi
'entPhysicalIsFRU' => $entPhysicalIsFRU,
'entPhysicalAlias' => $entPhysicalAlias,
'entPhysicalAssetID' => $entPhysicalAssetID,
);
];
if (! empty($ifIndex)) {
$insert_data['ifIndex'] = $ifIndex;
}
@ -748,7 +751,7 @@ function discover_entity_physical(&$valid, $device, $entPhysicalIndex, $entPhysi
log_event('Inventory Item added: index ' . $entPhysicalIndex . ' descr ' . $entPhysicalDescr, $device, 'entity-physical', 3, $inserted);
} else {
echo '.';
$update_data = array(
$update_data = [
'entPhysicalIndex' => $entPhysicalIndex,
'entPhysicalDescr' => $entPhysicalDescr,
'entPhysicalClass' => $entPhysicalClass,
@ -766,8 +769,8 @@ function discover_entity_physical(&$valid, $device, $entPhysicalIndex, $entPhysi
'entPhysicalAlias' => $entPhysicalAlias,
'entPhysicalAssetID' => $entPhysicalAssetID,
'ifIndex' => $ifIndex,
);
dbUpdate($update_data, 'entPhysical', '`device_id`=? AND `entPhysicalIndex`=?', array($device['device_id'], $entPhysicalIndex));
];
dbUpdate($update_data, 'entPhysical', '`device_id`=? AND `entPhysicalIndex`=?', [$device['device_id'], $entPhysicalIndex]);
}//end if
$valid[$entPhysicalIndex] = 1;
}//end if
@ -788,34 +791,34 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
$ipv6_network = $ipv6->getNetwork($ipv6_prefixlen);
$ipv6_compressed = $ipv6->compressed();
if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') {
$port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex));
if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', [$device['device_id'], $ifIndex]) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') {
$port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', [$device['device_id'], $ifIndex]);
if (is_numeric($port_id)) {
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') {
dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks');
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', [$ipv6_network]) < '1') {
dbInsert(['ipv6_network' => $ipv6_network, 'context_name' => $context_name], 'ipv6_networks');
echo 'N';
} else {
//Update Context
dbUpdate(array('context_name' => $device['context_name']), 'ipv6_networks', '`ipv6_network` = ?', array($ipv6_network));
dbUpdate(['context_name' => $device['context_name']], 'ipv6_networks', '`ipv6_network` = ?', [$ipv6_network]);
echo 'n';
}
if ($context_name == null) {
$ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` IS NULL', array($ipv6_network));
$ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` IS NULL', [$ipv6_network]);
} else {
$ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name));
$ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', [$ipv6_network, $context_name]);
}
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') {
dbInsert(array(
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', [$ipv6_address, $ipv6_prefixlen, $port_id]) == '0') {
dbInsert([
'ipv6_address' => $ipv6_address,
'ipv6_compressed' => $ipv6_compressed,
'ipv6_prefixlen' => $ipv6_prefixlen,
'ipv6_origin' => $ipv6_origin,
'ipv6_network_id' => $ipv6_network_id,
'port_id' => $port_id,
'context_name' => $context_name
), 'ipv6_addresses');
'context_name' => $context_name,
], 'ipv6_addresses');
echo '+';
} elseif (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ? AND `ipv6_network_id` = ""', [$ipv6_address, $ipv6_prefixlen, $port_id]) == '1') {
// Update IPv6 network ID if not set
@ -828,7 +831,7 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
echo 'u';
} else {
//Update Context
dbUpdate(array('context_name' => $device['context_name']), 'ipv6_addresses', '`ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id));
dbUpdate(['context_name' => $device['context_name']], 'ipv6_addresses', '`ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', [$ipv6_address, $ipv6_prefixlen, $port_id]);
echo '.';
}
@ -850,11 +853,12 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
*/
function check_entity_sensor($string, $device)
{
$fringe = array_merge(Config::get('bad_entity_sensor_regex', array()), Config::getOsSetting($device['os'], 'bad_entity_sensor_regex', array()));
$fringe = array_merge(Config::get('bad_entity_sensor_regex', []), Config::getOsSetting($device['os'], 'bad_entity_sensor_regex', []));
foreach ($fringe as $bad) {
if (preg_match($bad . "i", $string)) {
d_echo("Ignored entity sensor: $bad : $string");
return false;
}
}
@ -895,6 +899,7 @@ function get_device_divisor($device, $os_version, $sensor_type, $oid)
if (Str::startsWith($device['hardware'], "UPS2000")) {
return 10;
}
return 100;
}
} elseif ($device['os'] == 'hpe-rtups') {
@ -944,6 +949,7 @@ function get_toner_capacity($raw_capacity)
if (empty($raw_capacity) || $raw_capacity < 0) {
return 100;
}
return $raw_capacity;
}
@ -952,13 +958,14 @@ function get_toner_capacity($raw_capacity)
*
* @param string $os The OS of the device
* @param string $descr The description of the storage
* @return boolean
* @return bool
*/
function ignore_storage($os, $descr)
{
foreach (Config::getCombined($os, 'ignore_mount', []) as $im) {
if ($im == $descr) {
d_echo("ignored $descr (matched: $im)\n");
return true;
}
}
@ -966,6 +973,7 @@ function ignore_storage($os, $descr)
foreach (Config::getCombined($os, 'ignore_mount_string', []) as $ims) {
if (Str::contains($descr, $ims)) {
d_echo("ignored $descr (matched: $ims)\n");
return true;
}
}
@ -973,6 +981,7 @@ function ignore_storage($os, $descr)
foreach (Config::getCombined($os, 'ignore_mount_regexp', []) as $imr) {
if (preg_match($imr, $descr)) {
d_echo("ignored $descr (matched: $imr)\n");
return true;
}
}
@ -989,7 +998,7 @@ function ignore_storage($os, $descr)
function discovery_process(&$valid, $device, $sensor_class, $pre_cache)
{
if ($device['dynamic_discovery']['modules']['sensors'][$sensor_class] && ! can_skip_sensor($device, $sensor_class, '')) {
$sensor_options = array();
$sensor_options = [];
if (isset($device['dynamic_discovery']['modules']['sensors'][$sensor_class]['options'])) {
$sensor_options = $device['dynamic_discovery']['modules']['sensors'][$sensor_class]['options'];
}
@ -1016,7 +1025,7 @@ function discovery_process(&$valid, $device, $sensor_class, $pre_cache)
if (! is_numeric($snmp_value)) {
if ($sensor_class === 'temperature') {
// For temp sensors, try and detect fahrenheit values
if (Str::endsWith($snmp_value, array('f', 'F'))) {
if (Str::endsWith($snmp_value, ['f', 'F'])) {
$user_function = 'fahrenheit_to_celsius';
}
}
@ -1105,7 +1114,7 @@ function discovery_process(&$valid, $device, $sensor_class, $pre_cache)
* @param $device
* @param array $pre_cache
*/
function sensors($types, $device, $valid, $pre_cache = array())
function sensors($types, $device, $valid, $pre_cache = [])
{
foreach ((array) $types as $sensor_class) {
echo ucfirst($sensor_class) . ': ';
@ -1132,23 +1141,23 @@ function sensors($types, $device, $valid, $pre_cache = array())
function build_bgp_peers($device, $data, $peer2)
{
d_echo("Peers : $data\n");
$remove = array(
$remove = [
'ARISTA-BGP4V2-MIB::aristaBgp4V2PeerRemoteAs.1.',
'CISCO-BGP4-MIB::cbgpPeer2RemoteAs.',
'BGP4-MIB::bgpPeerRemoteAs.',
'HUAWEI-BGP-VPN-MIB::hwBgpPeerRemoteAs.',
'.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.',
);
];
$peers = trim(str_replace($remove, '', $data));
$peerlist = array();
$peerlist = [];
$ver = '';
foreach (explode("\n", $peers) as $peer) {
$local_ip = null;
if ($peer2 === true) {
list($ver, $peer) = explode('.', $peer, 2);
[$ver, $peer] = explode('.', $peer, 2);
}
list($peer_ip, $peer_as) = explode(' ', $peer);
[$peer_ip, $peer_as] = explode(' ', $peer);
if ($device['os'] === 'junos') {
$ver = '';
$octets = count(explode(".", $peer_ip));
@ -1168,27 +1177,27 @@ function build_bgp_peers($device, $data, $peer2)
}
if ($peer && $peer_ip != '0.0.0.0') {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
$peerlist[] = [
'ip' => $peer_ip,
'as' => $peer_as,
'localip' => $local_ip ?: '0.0.0.0',
'ver' => $ver,
);
];
}
}
return $peerlist;
}
function build_cbgp_peers($device, $peer, $af_data, $peer2)
{
d_echo('afi data :: ');
d_echo($af_data);
$af_list = array();
$af_list = [];
foreach ($af_data as $k => $v) {
if ($peer2 === true) {
list(,$k) = explode('.', $k, 2);
[,$k] = explode('.', $k, 2);
}
d_echo("AFISAFI = $k\n");
@ -1217,13 +1226,14 @@ function build_cbgp_peers($device, $peer, $af_data, $peer2)
add_cbgp_peer($device, $peer, $afi, $safi);
}
}
return $af_list;
}
function add_bgp_peer($device, $peer)
{
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') {
$bgpPeers = array(
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', [$device['device_id'], $peer['ip']]) < '1') {
$bgpPeers = [
'device_id' => $device['device_id'],
'bgpPeerIdentifier' => $peer['ip'],
'bgpPeerRemoteAs' => $peer['as'],
@ -1239,7 +1249,7 @@ function add_bgp_peer($device, $peer)
'bgpPeerOutTotalMessages' => 0,
'bgpPeerFsmEstablishedTime' => 0,
'bgpPeerInUpdateElapsedTime' => 0,
);
];
dbInsert($bgpPeers, 'bgpPeers');
if (Config::get('autodiscovery.bgp')) {
$name = gethostbyaddr($peer['ip']);
@ -1247,15 +1257,15 @@ function add_bgp_peer($device, $peer)
}
echo '+';
} else {
dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => $peer['astext']), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip']));
dbUpdate(['bgpPeerRemoteAs' => $peer['as'], 'astext' => $peer['astext']], 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', [$device['device_id'], $peer['ip']]);
echo '.';
}
}
function add_cbgp_peer($device, $peer, $afi, $safi)
{
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) {
$cbgp = array(
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', [$device['device_id'], $peer['ip'], $afi, $safi]) == 0) {
$cbgp = [
'device_id' => $device['device_id'],
'bgpPeerIdentifier' => $peer['ip'],
'afi' => $afi,
@ -1279,7 +1289,7 @@ function add_cbgp_peer($device, $peer, $afi, $safi)
'SuppressedPrefixes_prev' => 0,
'WithdrawnPrefixes_delta' => 0,
'WithdrawnPrefixes_prev' => 0,
);
];
dbInsert($cbgp, 'bgpPeers_cbgp');
}
}
@ -1301,10 +1311,10 @@ function can_skip_sensor($device, $sensor_class = '', $sensor_descr = '')
return true;
}
}
return false;
}
/**
* check if we should skip this device from discovery
* @param string $sysName
@ -1318,6 +1328,7 @@ function can_skip_discovery($sysName, $sysDescr = '', $platform = '')
foreach ((array) Config::get('autodiscovery.xdp_exclude.sysname_regexp') as $needle) {
if (preg_match($needle . 'i', $sysName)) {
d_echo("$sysName - regexp '$needle' matches '$sysName' - skipping device discovery \n");
return true;
}
}
@ -1327,6 +1338,7 @@ function can_skip_discovery($sysName, $sysDescr = '', $platform = '')
foreach ((array) Config::get('autodiscovery.xdp_exclude.sysdesc_regexp') as $needle) {
if (preg_match($needle . 'i', $sysDescr)) {
d_echo("$sysName - regexp '$needle' matches '$sysDescr' - skipping device discovery \n");
return true;
}
}
@ -1336,6 +1348,7 @@ function can_skip_discovery($sysName, $sysDescr = '', $platform = '')
foreach ((array) Config::get('autodiscovery.cdp_exclude.platform_regexp') as $needle) {
if (preg_match($needle . 'i', $platform)) {
d_echo("$sysName - regexp '$needle' matches '$platform' - skipping device discovery \n");
return true;
}
}
@ -1355,8 +1368,8 @@ function can_skip_discovery($sysName, $sysDescr = '', $platform = '')
*/
function find_device_id($name = '', $ip = '', $mac_address = '')
{
$where = array();
$params = array();
$where = [];
$params = [];
if ($name && is_valid_hostname($name)) {
$where[] = '`hostname`=?';
@ -1392,14 +1405,14 @@ function find_device_id($name = '', $ip = '', $mac_address = '')
}
if ($mac_address && $mac_address != '000000000000') {
if ($device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE `ifPhysAddress`=?', array($mac_address))) {
if ($device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE `ifPhysAddress`=?', [$mac_address])) {
return (int) $device_id;
}
}
if ($name) {
$where = array();
$params = array();
$where = [];
$params = [];
$where[] = '`sysName`=?';
$params[] = $name;
@ -1441,8 +1454,8 @@ function find_port_id($description, $identifier = '', $device_id = 0, $mac_addre
return 0;
}
$statements = array();
$params = array();
$statements = [];
$params = [];
if ($device_id) {
if ($description) {

View File

@ -1,12 +1,12 @@
<?php
$hrDevice_oids = array(
$hrDevice_oids = [
'hrDeviceEntry',
'hrProcessorEntry',
);
];
d_echo($hrDevices);
$hrDevices = array();
$hrDevices = [];
foreach ($hrDevice_oids as $oid) {
$hrDevices = snmpwalk_cache_oid($device, $oid, $hrDevices, 'HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES');
}
@ -16,21 +16,21 @@ d_echo($hrDevices);
if (is_array($hrDevices)) {
foreach ($hrDevices as $hrDevice) {
if (is_array($hrDevice) && is_numeric($hrDevice['hrDeviceIndex'])) {
if (dbFetchCell('SELECT COUNT(*) FROM `hrDevice` WHERE device_id = ? AND hrDeviceIndex = ?', array($device['device_id'], $hrDevice['hrDeviceIndex']))) {
$update_array = array(
if (dbFetchCell('SELECT COUNT(*) FROM `hrDevice` WHERE device_id = ? AND hrDeviceIndex = ?', [$device['device_id'], $hrDevice['hrDeviceIndex']])) {
$update_array = [
'hrDeviceType' => mres($hrDevice['hrDeviceType']),
'hrDeviceDescr' => mres($hrDevice['hrDeviceDescr']),
'hrDeviceStatus' => mres($hrDevice['hrDeviceStatus']),
'hrDeviceErrors' => mres($hrDevice['hrDeviceErrors']),
);
];
if ($hrDevice['hrDeviceType'] == 'hrDeviceProcessor') {
$update_array['hrProcessorLoad'] = mres($hrDevice['hrProcessorLoad']);
}
dbUpdate($update_array, 'hrDevice', 'device_id=? AND hrDeviceIndex=?', array($device['device_id'], $hrDevice['hrDeviceIndex']));
dbUpdate($update_array, 'hrDevice', 'device_id=? AND hrDeviceIndex=?', [$device['device_id'], $hrDevice['hrDeviceIndex']]);
echo '.';
} else {
$inserted_rows = dbInsert(array('hrDeviceIndex' => mres($hrDevice['hrDeviceIndex']), 'device_id' => mres($device['device_id']), 'hrDeviceType' => mres($hrDevice['hrDeviceType']), 'hrDeviceDescr' => mres($hrDevice['hrDeviceDescr']), 'hrDeviceStatus' => mres($hrDevice['hrDeviceStatus']), 'hrDeviceErrors' => (int) mres($hrDevice['hrDeviceErrors'])), 'hrDevice');
$inserted_rows = dbInsert(['hrDeviceIndex' => mres($hrDevice['hrDeviceIndex']), 'device_id' => mres($device['device_id']), 'hrDeviceType' => mres($hrDevice['hrDeviceType']), 'hrDeviceDescr' => mres($hrDevice['hrDeviceDescr']), 'hrDeviceStatus' => mres($hrDevice['hrDeviceStatus']), 'hrDeviceErrors' => (int) mres($hrDevice['hrDeviceErrors'])], 'hrDevice');
echo '+';
d_echo($hrDevice);
d_echo("$inserted_rows row inserted");
@ -46,7 +46,7 @@ $sql = "SELECT * FROM `hrDevice` WHERE `device_id` = '".$device['device_id']."'
foreach (dbFetchRows($sql) as $test_hrDevice) {
if (! $valid_hrDevice[$test_hrDevice['hrDeviceIndex']]) {
echo '-';
dbDelete('hrDevice', '`hrDevice_id` = ?', array($test_hrDevice['hrDevice_id']));
dbDelete('hrDevice', '`hrDevice_id` = ?', [$test_hrDevice['hrDevice_id']]);
d_echo($test_hrDevice);
}
}

View File

@ -1,12 +1,12 @@
<?php
use LibreNMS\Util\IPv4;
use LibreNMS\Exceptions\InvalidIpException;
use LibreNMS\Util\IPv4;
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
} else {
$vrfs_lite_cisco = array(array('context_name'=>null));
$vrfs_lite_cisco = [['context_name'=>null]];
}
foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name'] = $vrf['context_name'];
@ -15,7 +15,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
$oids = str_replace('ipAdEntIfIndex.', '', $oids);
foreach (explode("\n", $oids) as $data) {
$data = trim($data);
list($oid,$ifIndex) = explode(' ', $data);
[$oid,$ifIndex] = explode(' ', $data);
$mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB'));
$cidr = IPv4::netmask2cidr($mask);
try {
@ -25,36 +25,35 @@ foreach ($vrfs_lite_cisco as $vrf) {
}
$network = $ipv4->getNetworkAddress() . '/' . $ipv4->cidr;
if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') {
$port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex));
if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', [$device['device_id'], $ifIndex]) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') {
$port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', [$device['device_id'], $ifIndex]);
if (is_numeric($port_id)) {
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') {
dbInsert(array('ipv4_network' => $network, 'context_name' => $device['context_name']), 'ipv4_networks');
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', [$network]) < '1') {
dbInsert(['ipv4_network' => $network, 'context_name' => $device['context_name']], 'ipv4_networks');
// echo("Create Subnet $network\n");
echo 'S';
} else {
//Update Context
dbUpdate(array('context_name' => $device['context_name']), 'ipv4_networks', '`ipv4_network` = ?', array($network));
dbUpdate(['context_name' => $device['context_name']], 'ipv4_networks', '`ipv4_network` = ?', [$network]);
echo 's';
}
$ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network));
$ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', [$network]);
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? ', array($oid, $cidr, $port_id)) == '0') {
dbInsert(array(
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? ', [$oid, $cidr, $port_id]) == '0') {
dbInsert([
'ipv4_address' => $oid,
'ipv4_prefixlen' => $cidr,
'ipv4_network_id' => $ipv4_network_id,
'port_id' => $port_id,
'context_name' => $device['context_name']
), 'ipv4_addresses');
'context_name' => $device['context_name'],
], 'ipv4_addresses');
// echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n");
echo '+';
} else {
//Update Context
dbUpdate(array('context_name' => $device['context_name']), 'ipv4_addresses', '`ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id));
dbUpdate(['context_name' => $device['context_name']], 'ipv4_addresses', '`ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', [$oid, $cidr, $port_id]);
echo '.';
}
$full_address = "$oid/$cidr|$ifIndex";
@ -70,14 +69,14 @@ foreach ($vrfs_lite_cisco as $vrf) {
$sql = 'SELECT `ipv4_addresses`.*, `ports`.`device_id`, `ports`.`ifIndex` FROM `ipv4_addresses`';
$sql .= ' LEFT JOIN `ports` ON `ipv4_addresses`.`port_id` = `ports`.`port_id`';
$sql .= ' WHERE `ports`.device_id = ? OR `ports`.`device_id` IS NULL';
foreach (dbFetchRows($sql, array($device['device_id'])) as $row) {
foreach (dbFetchRows($sql, [$device['device_id']]) as $row) {
$full_address = $row['ipv4_address'] . '/' . $row['ipv4_prefixlen'] . '|' . $row['ifIndex'];
if (! $valid_v4[$full_address]) {
echo '-';
$query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id']));
if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) {
$query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id']));
$query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', [$row['ipv4_address_id']]);
if (! dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', [$row['ipv4_network_id']])) {
$query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', [$row['ipv4_network_id']]);
}
}
}

View File

@ -3,7 +3,7 @@
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
} else {
$vrfs_lite_cisco = array(array('context_name'=>null));
$vrfs_lite_cisco = [['context_name'=>null]];
}
foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name'] = $vrf['context_name'];
@ -17,7 +17,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
foreach (explode("\n", $oids) as $data) {
if ($data) {
$data = trim($data);
list($ipv6addr,$ifIndex) = explode(' ', $data);
[$ipv6addr,$ifIndex] = explode(' ', $data);
$oid = '';
$sep = '';
$adsep = '';
@ -61,8 +61,8 @@ foreach ($vrfs_lite_cisco as $vrf) {
foreach (explode("\n", $oids) as $data) {
if ($data) {
$data = trim($data);
list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data);
list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2);
[$if_ipv6addr,$ipv6_prefixlen] = explode(' ', $data);
[$ifIndex,$ipv6addr] = explode('.', $if_ipv6addr, 2);
$ipv6_address = snmp2ipv6($ipv6addr);
$ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB');
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']);
@ -73,15 +73,15 @@ foreach ($vrfs_lite_cisco as $vrf) {
$sql = 'SELECT `ipv6_addresses`.*, `ports`.`device_id`, `ports`.`ifIndex` FROM `ipv6_addresses`';
$sql .= ' LEFT JOIN `ports` ON `ipv6_addresses`.`port_id` = `ports`.`port_id`';
$sql .= ' WHERE `ports`.device_id = ? OR `ports`.`device_id` IS NULL';
foreach (dbFetchRows($sql, array($device['device_id'])) as $row) {
foreach (dbFetchRows($sql, [$device['device_id']]) as $row) {
$full_address = $row['ipv6_address'] . '/' . $row['ipv6_prefixlen'];
$port_id = $row['port_id'];
$valid_address = $full_address . '-' . $port_id;
if (! $valid['ipv6'][$valid_address]) {
echo '-';
$query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id']));
if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) {
$query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id']));
$query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', [$row['ipv6_address_id']]);
if (! dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', [$row['ipv6_network_id']])) {
$query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', [$row['ipv6_network_id']]);
}
}
}

View File

@ -7,14 +7,14 @@ use LibreNMS\Config;
if ($device['os'] == 'junose' && Config::get('enable_ports_junoseatmvp')) {
$vp_array = snmpwalk_cache_multi_oid($device, 'juniAtmVpStatsInCells', $vp_array, 'Juniper-UNI-ATM-MIB', 'junose');
$valid_vp = array();
$valid_vp = [];
d_echo($vp_array);
if (is_array($vp_array)) {
foreach ($vp_array as $index => $entry) {
list($ifIndex,$vp_id) = explode('.', $index);
[$ifIndex,$vp_id] = explode('.', $index);
$port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex));
$port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', [$device['device_id'], $ifIndex]);
if (is_numeric($port_id) && is_numeric($vp_id)) {
discover_juniAtmvp($valid_vp, $port_id, $vp_id, null);
@ -36,7 +36,7 @@ if ($device['os'] == 'junose' && Config::get('enable_ports_junoseatmvp')) {
if (! $valid_vp[$port_id][$vp_id]) {
echo '-';
dbDelete('juniAtmvp', '`juniAtmVp` = ?', array($test['juniAtmvp']));
dbDelete('juniAtmvp', '`juniAtmVp` = ?', [$test['juniAtmvp']]);
}
unset($port_id);

View File

@ -6,7 +6,7 @@ use LibreNMS\Config;
// FIXME should do the deletion etc in a common file perhaps? like for the sensors
// Try to discover Libvirt Virtual Machines.
if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
$libvirt_vmlist = array();
$libvirt_vmlist = [];
$ssh_ok = 0;
@ -37,7 +37,7 @@ if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
exec(Config::get('virsh') . ' -rc ' . $uri . ' list', $domlist);
foreach ($domlist as $dom) {
list($dom_id,) = explode(' ', trim($dom), 2);
[$dom_id,] = explode(' ', trim($dom), 2);
if (is_numeric($dom_id)) {
// Fetch the Virtual Machine information.
@ -116,9 +116,9 @@ if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
}
// Check whether the Virtual Machine is already known for this host.
$result = dbFetchRow("SELECT * FROM `vminfo` WHERE `device_id` = ? AND `vmwVmVMID` = ? AND `vm_type` = 'libvirt'", array($device['device_id'], $dom_id));
$result = dbFetchRow("SELECT * FROM `vminfo` WHERE `device_id` = ? AND `vmwVmVMID` = ? AND `vm_type` = 'libvirt'", [$device['device_id'], $dom_id]);
if (count($result['device_id']) == 0) {
$inserted_id = dbInsert(array('device_id' => $device['device_id'], 'vm_type' => 'libvirt', 'vmwVmVMID' => $dom_id, 'vmwVmDisplayName' => mres($vmwVmDisplayName), 'vmwVmGuestOS' => mres($vmwVmGuestOS), 'vmwVmMemSize' => mres($vmwVmMemSize), 'vmwVmCpus' => mres($vmwVmCpus), 'vmwVmState' => mres($vmwVmState)), 'vminfo');
$inserted_id = dbInsert(['device_id' => $device['device_id'], 'vm_type' => 'libvirt', 'vmwVmVMID' => $dom_id, 'vmwVmDisplayName' => mres($vmwVmDisplayName), 'vmwVmGuestOS' => mres($vmwVmGuestOS), 'vmwVmMemSize' => mres($vmwVmMemSize), 'vmwVmCpus' => mres($vmwVmCpus), 'vmwVmState' => mres($vmwVmState)], 'vminfo');
echo '+';
log_event("Virtual Machine added: $vmwVmDisplayName ($vmwVmMemSize MB)", $device, 'vm', 3, $inserted_id);
} else {
@ -128,7 +128,7 @@ if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
|| $result['vmwVmGuestOS'] != $vmwVmGuestOS
|| $result['vmwVmMemSize'] != $vmwVmMemSize
) {
dbUpdate(array('vmwVmState' => mres($vmwVmState), 'vmwVmGuestOS' => mres($vmwVmGuestOS), 'vmwVmDisplayName' => mres($vmwVmDisplayName), 'vmwVmMemSize' => mres($vmwVmMemSize), 'vmwVmCpus' => mres($vmwVmCpus)), 'vminfo', "device_id=? AND vm_type='libvirt' AND vmwVmVMID=?", array($device['device_id'], $dom_id));
dbUpdate(['vmwVmState' => mres($vmwVmState), 'vmwVmGuestOS' => mres($vmwVmGuestOS), 'vmwVmDisplayName' => mres($vmwVmDisplayName), 'vmwVmMemSize' => mres($vmwVmMemSize), 'vmwVmCpus' => mres($vmwVmCpus)], 'vminfo', "device_id=? AND vm_type='libvirt' AND vmwVmVMID=?", [$device['device_id'], $dom_id]);
echo 'U';
// FIXME eventlog
} else {
@ -154,7 +154,7 @@ if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
foreach (dbFetchRows($sql) as $db_vm) {
// Delete the Virtual Machines that are removed from the host.
if (! in_array($db_vm['vmwVmVMID'], $libvirt_vmlist)) {
dbDelete('vminfo', '`id` = ?', array($db_vm['id']));
dbDelete('vminfo', '`id` = ?', [$db_vm['id']]);
echo '-';
log_event('Virtual Machine removed: ' . $db_vm['vmwVmDisplayName'], $device, 'vm', 4, $db_vm['id']);
}

View File

@ -15,7 +15,7 @@
// Define some error messages
use LibreNMS\Util\IP;
$error_poolaction = array();
$error_poolaction = [];
$error_poolaction[0] = "Unused";
$error_poolaction[1] = "Reboot";
$error_poolaction[2] = "Restart";
@ -31,8 +31,8 @@ $components = $component->getComponents($device['device_id']);
$components = $components[$device['device_id']];
// We extracted all the components for this device, now lets only get the LTM ones.
$keep = array();
$types = array($module, 'bigip', 'f5-gtm-wide', 'f5-gtm-pool');
$keep = [];
$types = [$module, 'bigip', 'f5-gtm-wide', 'f5-gtm-pool'];
foreach ($components as $k => $v) {
foreach ($types as $type) {
if ($v['type'] == $type) {
@ -43,7 +43,7 @@ foreach ($components as $k => $v) {
$components = $keep;
// Begin our master array, all other values will be processed into this array.
$tblBigIP = array();
$tblBigIP = [];
if ((snmp_get($device, 'sysModuleAllocationProvisionLevel.3.103.116.109', '-Ovqs', 'F5-BIGIP-SYSTEM-MIB')) != false) {
$gtmWideIPEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.3.12.1.2.1', 0);
@ -65,11 +65,11 @@ if (!is_null($gtmWideIPEntry) || !is_null($gtmWideStatusEntry) || !is_null($gtmP
// Process the Virtual Servers
if (is_array($gtmWideStatusEntry)) {
foreach ($gtmWideStatusEntry as $oid => $value) {
$result = array();
$result = [];
// Find all Virtual server names and UID's, then we can find everything else we need.
if (strpos($oid, '1.3.6.1.4.1.3375.2.3.12.3.2.1.1.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.3.12.3.2.1.1.', $oid);
[$null, $index] = explode('1.3.6.1.4.1.3375.2.3.12.3.2.1.1.', $oid);
$result['type'] = 'f5-gtm-wide';
$result['UID'] = (string) $index;
$result['label'] = $value;
@ -110,11 +110,11 @@ if (!is_null($gtmWideIPEntry) || !is_null($gtmWideStatusEntry) || !is_null($gtmP
// Process the Pools
if (is_array($gtmPoolEntry)) {
foreach ($gtmPoolEntry as $oid => $value) {
$result = array ();
$result = [];
// Find all Pool names and UID's, then we can find everything else we need.
if (strpos($oid, '1.3.6.1.4.1.3375.2.3.6.2.3.1.1.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.3.6.2.3.1.1.', $oid);
[$null, $index] = explode('1.3.6.1.4.1.3375.2.3.6.2.3.1.1.', $oid);
$result['type'] = 'f5-gtm-pool';
$result['UID'] = (string) $index;
$result['label'] = $value;

View File

@ -14,7 +14,7 @@
// Define some error messages
use LibreNMS\Util\IP;
$error_poolaction = array();
$error_poolaction = [];
$error_poolaction[0] = "Unused";
$error_poolaction[1] = "Reboot";
$error_poolaction[2] = "Restart";
@ -30,8 +30,8 @@ $components = $component->getComponents($device['device_id']);
$components = $components[$device['device_id']];
// We extracted all the components for this device, now lets only get the LTM ones.
$keep = array();
$types = array($module, 'bigip', 'f5-ltm-bwc', 'f5-ltm-vs', 'f5-ltm-pool', 'f5-ltm-poolmember');
$keep = [];
$types = [$module, 'bigip', 'f5-ltm-bwc', 'f5-ltm-vs', 'f5-ltm-pool', 'f5-ltm-poolmember'];
foreach ($components as $k => $v) {
foreach ($types as $type) {
if ($v['type'] == $type) {
@ -42,16 +42,16 @@ foreach ($components as $k => $v) {
$components = $keep;
// Begin our master array, all other values will be processed into this array.
$tblBigIP = array();
$tblBigIP = [];
// Virtual Server Data
$ltmVirtualServOID = array(
$ltmVirtualServOID = [
'ip' => '1.3.6.1.4.1.3375.2.2.10.1.2.1.3',
'port' => '1.3.6.1.4.1.3375.2.2.10.1.2.1.6',
'defaultpool' => '1.3.6.1.4.1.3375.2.2.10.1.2.1.19',
'state' => '1.3.6.1.4.1.3375.2.2.10.13.2.1.2',
'errorcode' => '1.3.6.1.4.1.3375.2.2.10.13.2.1.5',
);
];
$ltmVirtualServEntry = [];
//Check for Virtual Server Enries
@ -66,17 +66,17 @@ if (!empty($ltmVirtualServEntry['name'])) {
}
// Pool Data
$ltmPoolEntryOID = array(
$ltmPoolEntryOID = [
'mode' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.2',
'minup' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.4',
'minupstatus' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.5',
'minupaction' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.6',
'currentup' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.8',
'monitor' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.17',
);
];
// Pool Member Data
$ltmPoolMemberEntryOID = array(
$ltmPoolMemberEntryOID = [
'ip' => '1.3.6.1.4.1.3375.2.2.5.3.2.1.3',
'port' => '1.3.6.1.4.1.3375.2.2.5.3.2.1.4',
'ratio' => '1.3.6.1.4.1.3375.2.2.5.3.2.1.6',
@ -85,7 +85,7 @@ $ltmPoolMemberEntryOID = array(
'state' => '1.3.6.1.4.1.3375.2.2.5.6.2.1.5',
'available' => '1.3.6.1.4.1.3375.2.2.5.6.2.1.6',
'errorcode' => '1.3.6.1.4.1.3375.2.2.5.6.2.1.8',
);
];
//Check for Pool Enries
$ltmPoolEntry = [];
@ -131,11 +131,11 @@ if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry
// Process the Virtual Servers
if (is_array($ltmVirtualServEntry['name'])) {
foreach ($ltmVirtualServEntry['name'] as $oid => $value) {
$result = array();
$result = [];
// Find all Virtual server names and UID's, then we can find everything else we need.
if (strpos($oid, '1.3.6.1.4.1.3375.2.2.10.1.2.1.1.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.2.10.1.2.1.1.', $oid);
[$null, $index] = explode('1.3.6.1.4.1.3375.2.2.10.1.2.1.1.', $oid);
$result['type'] = 'f5-ltm-vs';
$result['UID'] = (string) $index;
$result['label'] = $value;
@ -185,11 +185,11 @@ if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry
// Process the BWC
if (is_array($ltmBwcEntry['name'])) {
foreach ($ltmBwcEntry['name'] as $oid => $value) {
$result = array();
$result = [];
// Find all Bandwidth Controller names and UID's, then we can find everything else we need.
if (strpos($oid, '1.3.6.1.4.1.3375.2.2.13.1.3.1.1.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.2.13.1.3.1.1.', $oid);
[$null, $index] = explode('1.3.6.1.4.1.3375.2.2.13.1.3.1.1.', $oid);
$result['type'] = 'f5-ltm-bwc';
$result['UID'] = (string) $index;
$result['label'] = $value;
@ -208,11 +208,11 @@ if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry
// Process the Pools
if (is_array($ltmPoolEntry['name'])) {
foreach ($ltmPoolEntry['name'] as $oid => $value) {
$result = array ();
$result = [];
// Find all Pool names and UID's, then we can find everything else we need.
if (strpos($oid, '1.3.6.1.4.1.3375.2.2.5.1.2.1.1.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.2.5.1.2.1.1.', $oid);
[$null, $index] = explode('1.3.6.1.4.1.3375.2.2.5.1.2.1.1.', $oid);
$result['type'] = 'f5-ltm-pool';
$result['UID'] = (string) $index;
$result['label'] = $value;
@ -255,11 +255,11 @@ if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry
// Process the Pool Members
if (is_array($ltmPoolMemberEntry['name'])) {
foreach ($ltmPoolMemberEntry['name'] as $oid => $value) {
$result = array ();
$result = [];
// Find all Pool member names and UID's, then we can find everything else we need.
if (strpos($oid, '1.3.6.1.4.1.3375.2.2.5.3.2.1.1.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.2.5.3.2.1.1.', $oid);
[$null, $index] = explode('1.3.6.1.4.1.3375.2.2.5.3.2.1.1.', $oid);
$result['type'] = 'f5-ltm-poolmember';
$result['UID'] = (string) $index;
$result['label'] = $value;

View File

@ -8,7 +8,7 @@
* Variable to hold the discovered MEF Links.
*/
$mef_list = array();
$mef_list = [];
/*
* Fetch information about MEF Links.
@ -35,8 +35,8 @@ foreach ($oids as $index => $entry) {
/*
* Check if the MEF is already known for this host
*/
if (dbFetchCell("SELECT COUNT(id) FROM `mefinfo` WHERE `device_id` = ? AND `mefID` = ?", array($device['device_id'], $index)) == 0) {
$mefid = dbInsert(array('device_id' => $device['device_id'], 'mefID' => $index, 'mefType' => mres($mefType), 'mefIdent' => mres($mefIdent), 'mefMTU' => mres($mefMtu), 'mefAdmState' => mres($mefAdmState), 'mefRowState' => mres($mefRowState)), 'mefinfo');
if (dbFetchCell("SELECT COUNT(id) FROM `mefinfo` WHERE `device_id` = ? AND `mefID` = ?", [$device['device_id'], $index]) == 0) {
$mefid = dbInsert(['device_id' => $device['device_id'], 'mefID' => $index, 'mefType' => mres($mefType), 'mefIdent' => mres($mefIdent), 'mefMTU' => mres($mefMtu), 'mefAdmState' => mres($mefAdmState), 'mefRowState' => mres($mefRowState)], 'mefinfo');
log_event("MEF link: " . mres($mefIdent) . " (" . $index . ") Discovered", $device, 'system', 2);
echo '+';
} else {
@ -58,7 +58,7 @@ foreach (dbFetchRows($sql) as $db_mef) {
* Delete the MEF Link that are removed from the host.
*/
if (! in_array($db_mef['mefID'], $mef_list)) {
dbDelete('mefinfo', '`id` = ?', array($db_mef['id']));
dbDelete('mefinfo', '`id` = ?', [$db_mef['id']]);
log_event("MEF link: " . mres($db_mef['mefIdent']) . ' Removed', $device, 'system', 3);
echo '-';
}

View File

@ -16,7 +16,7 @@ foreach (dbFetchRows($sql) as $test_mempool) {
if (! $valid_mempool[$mempool_type][$mempool_index]) {
echo '-';
dbDelete('mempools', '`mempool_id` = ?', array($test_mempool['mempool_id']));
dbDelete('mempools', '`mempool_id` = ?', [$test_mempool['mempool_id']]);
}
unset($mempool_oid);

View File

@ -22,7 +22,6 @@
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
if ($device['os'] === '3com') {
echo '3COM:';

View File

@ -22,7 +22,6 @@
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <gh+n@laf.io>
*/
if ($device['os'] === 'acos') {
echo 'ACOS: ';
$usage = snmp_get($device, 'axSysMemoryUsage.0', '-Ovq', 'A10-AX-MIB');

View File

@ -12,14 +12,12 @@
* the source code distribution for details.
*/
/*
/ ADTRAN-AOSCPU::adGenAOSMemPool.0 = Gauge32: 67108863
/ ADTRAN-AOSCPU::adGenAOSHeapSize.0 = Gauge32: 39853040
/ ADTRAN-AOSCPU::adGenAOSHeapFree.0 = Gauge32: 25979888
*/
if ($device['os'] == 'adtran-aos') {
echo 'Adtran AOS: ';

View File

@ -12,10 +12,8 @@
* the source code distribution for details.
*/
if ($device['os'] == "binos") {
echo("telco systems: ");
echo "telco systems: ";
$used = snmp_get($device, ".1.3.6.1.4.1.738.1.111.2.1.1.5.0", "-Ovq"); // PRVT-SYS-INFO-MIB::numBytesAlloc.0 = INTEGER: 48993320
$free = snmp_get($device, ".1.3.6.1.4.1.738.1.111.2.1.1.1.0", "-Ovq"); // PRVT-SYS-INFO-MIB::numBytesFree.0 = INTEGER: 183136616

View File

@ -12,10 +12,8 @@
* the source code distribution for details.
*/
if ($device['os'] == "binox") {
echo("telco systems: ");
echo "telco systems: ";
$used = snmp_get($device, ".1.3.6.1.4.1.738.10.111.3.1.3.0", "-Ovq");
$used = str_replace('%', '', $used);

View File

@ -8,7 +8,7 @@ if ($device['os_group'] == 'cisco') {
if (is_array($array)) {
foreach ($array as $index => $entry) {
if (is_numeric($entry['cempMemPoolUsed']) && $entry['cempMemPoolValid'] == 'true') {
list($entPhysicalIndex) = explode('.', $index);
[$entPhysicalIndex] = explode('.', $index);
$entPhysicalName = snmp_get($device, 'entPhysicalName.' . $entPhysicalIndex, '-Oqv', 'ENTITY-MIB');
$descr = $entPhysicalName . ' - ' . $entry['cempMemPoolName'];

View File

@ -1,7 +1,7 @@
<?php
// Ignore this discovery module if we have already discovered things in CISCO-ENHANCED-MEMPOOL-MIB. Dirty duplication.
$cemp_count = dbFetchCell("SELECT COUNT(*) FROM `mempools` WHERE `device_id` = ? AND `mempool_type` = 'cemp'", array($device['device_id']));
$cemp_count = dbFetchCell("SELECT COUNT(*) FROM `mempools` WHERE `device_id` = ? AND `mempool_type` = 'cemp'", [$device['device_id']]);
if (($device['os_group'] == 'cisco') && $cemp_count == '0') {
echo 'OLD-CISCO-MEMORY-POOL: ';

View File

@ -22,11 +22,10 @@
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <gh+n@laf.io>
*/
if ($device['os'] === 'comware') {
echo 'hh3cEntityExtMemUsage: ';
$entphydata = dbFetchRows("SELECT `entPhysicalIndex`, `entPhysicalClass`, `entPhysicalName` FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalClass` = 'module' ORDER BY `entPhysicalIndex`", array($device['device_id']));
$entphydata = dbFetchRows("SELECT `entPhysicalIndex`, `entPhysicalClass`, `entPhysicalName` FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalClass` = 'module' ORDER BY `entPhysicalIndex`", [$device['device_id']]);
if ($entphydata) {
$comware_mem = snmpwalk_cache_oid($device, 'hh3cEntityExtMemUsage', null, 'HH3C-ENTITY-EXT-MIB');

View File

@ -22,7 +22,6 @@
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
if ($device['os'] === 'cyberoam-utm') {
echo 'Cyberoam UTM: ';

View File

@ -22,7 +22,6 @@
* @copyright 2016 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
if ($device['os'] === 'dasan-nos') {
echo 'Dasan NOS: ';

View File

@ -24,7 +24,7 @@ if ($device['os'] == 'dlink') {
$dlink_mempools = snmpwalk_cache_oid($device, 'dEntityExtMemoryUtilTable', [], 'DLINKSW-ENTITY-EXT-MIB');
foreach ($dlink_mempools as $tmp_index => $dlink_data) {
list(,$dlink_type) = explode('.', $tmp_index);
[,$dlink_type] = explode('.', $tmp_index);
discover_mempool($valid_mempool, $device, $tmp_index, 'dlink', ucfirst($dlink_type) . " Memory");
}
}

View File

@ -22,7 +22,6 @@
* @copyright 2019 Spencer Butler
* @author Spencer Butler <github@crooked.app>
*/
$mem_data = snmpwalk_cache_oid($device, 'dellNetCpuUtilTable', [], 'DELL-NETWORKING-CHASSIS-MIB', 'dell', '-OUseQ');
$mem_data = snmpwalk_cache_oid($device, 'DellNetProcessorEntry', $mem_data, 'DELL-NETWORKING-CHASSIS-MIB', 'dell', '-OUseQ');

View File

@ -29,7 +29,7 @@ if ($device['os'] == 'edgecos') {
$temp_mibs = 'ECS3510-MIB';
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.43.')) { //ECS2100
$temp_mibs = 'ECS2100-MIB';
};
}
$temp_data = snmp_get_multi_oid($device, ['memoryTotal.0', 'memoryFreed.0', 'memoryAllocated.0'], '-OUQs', $temp_mibs);
$total = $temp_data['memoryTotal.0'];

View File

@ -12,7 +12,7 @@
*/
if ($device['os'] == 'enterasys' || $device['os'] == 'ewc') {
$enterasys_mem = snmpwalk_cache_threepart_oid($device, 'etsysResourceStorageTable', array(), 'ENTERASYS-RESOURCE-UTILIZATION-MIB');
$enterasys_mem = snmpwalk_cache_threepart_oid($device, 'etsysResourceStorageTable', [], 'ENTERASYS-RESOURCE-UTILIZATION-MIB');
foreach ($enterasys_mem as $index => $mem_data) {
foreach ($mem_data['ram'] as $mem_id => $ram) {
$free = $ram['etsysResourceStorageAvailable'];

View File

@ -22,7 +22,6 @@
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
if ($device['os'] === 'fabos') {
$usage = snmp_get($device, 'swMemUsage.0', '-Ovq', 'SW-MIB');
discover_mempool($valid_mempool, $device, 0, 'fabos', 'Memory', '1');

View File

@ -11,9 +11,9 @@ if ($device['os'] == 'fiberhome') {
if ($card1Status == '1') {
$usage = snmp_get($device, 'mgrCardMemUtil.9', '-Ovq', 'GEPON-OLT-COMMON-MIB');
discover_mempool($valid_mempool, $device, 9, 'fiberhome', 'Hswa 9 Memory', '100', null, null);
};
}
if ($card2Status == '1') {
$usage = snmp_get($device, 'mgrCardMemUtil.10', '-Ovq', 'GEPON-OLT-COMMON-MIB');
discover_mempool($valid_mempool, $device, 10, 'fiberhome', 'Hswa 10 Memory', '100', null, null);
};
}
}

View File

@ -1,4 +1,5 @@
<?php
echo 'FORTIAUTHENTICATOR-MEMORY-POOL: ';
$usage = str_replace('"', "", snmp_get($device, 'FORTINET-FORTIAUTHENTICATOR-MIB::facSysMemUsage.0', '-OvQ'));
if (is_numeric($usage)) {

View File

@ -1,4 +1,5 @@
<?php
if ($device['os'] == 'fortimail') {
echo 'FORTIMAIL-MEMORY-POOL: ';
$usage = str_replace('"', "", snmp_get($device, 'FORTINET-FORTIMAIL-MIB::fmlSysMemUsage.0', '-OvQ'));

View File

@ -1,4 +1,5 @@
<?php
echo 'FORTISANDBOX-MEMORY-POOL: ';
$usage = str_replace('"', "", snmp_get($device, 'FORTINET-FORTISANDBOX-MIB::fsaSysMemUsage.0', '-OvQ'));
if (is_numeric($usage)) {

View File

@ -22,7 +22,6 @@
* @copyright 2016 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
if ($device['os'] === 'fortiswitch') {
echo 'Fortiswitch Mempool: ';
discover_mempool($valid_mempool, $device, 0, 'fortiswitch', 'Main Memory', '1024', null, null);

View File

@ -1,4 +1,5 @@
<?php
//
// Discovery for FS gbn devices.
//

View File

@ -1,4 +1,5 @@
<?php
//
// Discovery for FS-switch devices.
//

View File

@ -22,7 +22,6 @@
* @copyright 2019 Spencer Butler
* @author Spencer Butler <github@crooked.app>
*/
if ($device['os'] === 'hikvision-cam') {
echo 'hikvision-cam:';

View File

@ -22,7 +22,6 @@
* @copyright 2019 Spencer Butler
* @author Spencer Butler <github@crooked.app>
*/
if ($device['os'] === 'hikvision-nvr') {
echo 'hikvision-nvr:';

View File

@ -1,4 +1,5 @@
<?php
if ($device['os'] == 'hirschmann') {
$mem_allocated = snmp_get($device, 'HMPRIV-MGMT-SNMP-MIB::hmMemoryAllocated.0', '-OvQ');
$mem_free = snmp_get($device, 'HMPRIV-MGMT-SNMP-MIB::hmMemoryFree.0', '-OvQ');

View File

@ -10,7 +10,6 @@ if ($device['os'] == 'hpe-ilo') {
$page_free = $memory_pool['cpqHoPagingMemoryFree.0'];
$page_capacity = $memory_pool['cpqHoPagingMemorySize.0'];
if ((is_numeric($mem_free)) && (is_numeric($mem_capacity))) {
discover_mempool($valid_mempool, $device, 0, 'hpe-ilo', 'Physical Memory', '1', null, null);
}

View File

@ -3,7 +3,7 @@
use Illuminate\Support\Str;
if ($device['os'] == 'ironware' || $device['os_type'] == 'ironware') {
if (Str::contains($device['sysDescr'], array('NetIron', 'MLX', 'CER')) === false) {
if (Str::contains($device['sysDescr'], ['NetIron', 'MLX', 'CER']) === false) {
echo 'Ironware Dynamic: ';
$percent = snmp_get($device, 'snAgGblDynMemUtil.0', '-OvQ', 'FOUNDRY-SN-AGENT-MIB');

View File

@ -22,9 +22,8 @@
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
if ($device['os'] === 'jetstream') {
$data = snmpwalk_cache_oid($device, 'tpSysMonitorMemoryTable', array(), 'TPLINK-SYSMONITOR-MIB', 'hp');
$data = snmpwalk_cache_oid($device, 'tpSysMonitorMemoryTable', [], 'TPLINK-SYSMONITOR-MIB', 'hp');
foreach ($data as $index => $item) {
if (is_numeric($item['tpSysMonitorMemoryUtilization'])) {
$descr = "Memory #$index";

View File

@ -22,7 +22,6 @@
* @copyright 2016 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
if ($device['os'] == 'netonix') {
echo 'NETONIX : ';

View File

@ -25,7 +25,7 @@ if ($device['os'] == 'nokia-isam') {
'4360' => 'lt:1/1/6/',
'4361' => 'lt:1/1/7/',
'4362' => 'lt:1/1/8/',
'4481' => '4481' // FIXME define this
'4481' => '4481', // FIXME define this
];
$array = snmpwalk_cache_multi_oid($device, 'mem', null, 'ASAM-SYSTEM-MIB');
@ -33,7 +33,7 @@ if ($device['os'] == 'nokia-isam') {
if (is_array($array)) {
foreach ($array as $index => $entry) {
if (is_numeric($entry['memAbsoluteUsage']) && is_numeric($entry['totalMemSize'])) {
list($entPhysicalIndex) = explode('.', $index);
[$entPhysicalIndex] = explode('.', $index);
$entPhysicalName = $entPhysicalIndex;
$descr = $slotTable[$index] . ' Memory (' . $index . ')';

View File

@ -1,7 +1,7 @@
<?php
if ($device['os'] == "nos") {
echo("nos: ");
echo "nos: ";
$used = snmp_get($device, "1.3.6.1.4.1.1588.2.1.1.1.26.6.0", "-Ovq");
$total = "100";

View File

@ -1,4 +1,5 @@
<?php
if ($device['os'] == 'pbn') {
echo 'PBN-MEMORY-POOL: ';

View File

@ -1,4 +1,5 @@
<?php
//
// Hardcoded discovery of Memory usage on SGOS
//

View File

@ -23,15 +23,15 @@
* @author Jozef Rebjak <jozefrebjak@icloud.com>
*/
if ($device['os'] === 'smartax') {
$slotindex = snmpwalk_cache_oid($device, 'hwSlotIndex', array(), 'HWMUSA-DEV-MIB', 'huawei');
$slotdesc = snmpwalk_cache_oid($device, 'hwMusaBoardSlotDesc', array(), 'HWMUSA-DEV-MIB', 'huawei');
$data = snmpwalk_cache_oid($device, 'hwMusaBoardRamUseRate', array(), 'HWMUSA-DEV-MIB', 'huawei');
$slotindex = snmpwalk_cache_oid($device, 'hwSlotIndex', [], 'HWMUSA-DEV-MIB', 'huawei');
$slotdesc = snmpwalk_cache_oid($device, 'hwMusaBoardSlotDesc', [], 'HWMUSA-DEV-MIB', 'huawei');
$data = snmpwalk_cache_oid($device, 'hwMusaBoardRamUseRate', [], 'HWMUSA-DEV-MIB', 'huawei');
foreach ($data as $index => $item) {
if (is_numeric($item['hwMusaBoardRamUseRate']) && $item['hwMusaBoardRamUseRate'] != -1) {
$string = "Slot";
$number = $slotindex[$index]['hwSlotIndex'];
$boarddescr = $slotdesc[$index]['hwMusaBoardSlotDesc'];
$descr = implode(' ', array($string, $number, $boarddescr));
$descr = implode(' ', [$string, $number, $boarddescr]);
discover_mempool($valid_mempool, $device, $index, 'smartax', $descr, '1');
}
}

View File

@ -1,4 +1,5 @@
<?php
if ($device['os'] === 'stoneos') {
$currentMemory = snmp_get($device, 'sysCurMemory.0', '-OvQU', 'HILLSTONE-SYSTEM-MIB');
if (is_numeric($currentMemory)) {

View File

@ -22,7 +22,6 @@
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <gh+n@laf.io>
*/
if ($device['os'] === 'timos') {
echo 'TiMOS Memory: ';

View File

@ -22,7 +22,6 @@
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
if ($device['os_group'] == 'zyxel') {
d_echo('Zyxel');
$usage = snmp_get($device, "sysMgmtMemUsage.0", '-OvQ', 'ZYXEL-ES-COMMON');

View File

@ -16,13 +16,13 @@ use LibreNMS\Util\IP;
$module = 'ntp';
$component = new LibreNMS\Component();
$components = $component->getComponents($device['device_id'], array('type'=>$module));
$components = $component->getComponents($device['device_id'], ['type'=>$module]);
// We only care about our device id.
$components = $components[$device['device_id']];
// Begin our master array, all other values will be processed into this array.
$tblComponents = array();
$tblComponents = [];
// Let's gather some data..
// For Reference:
@ -43,7 +43,7 @@ if (is_null($atNtpAssociationEntry)) {
// Let's grab the index for each NTP peer
foreach ($atNtpAssociationEntry as $index => $value) {
$result = array();
$result = [];
$result['UID'] = (string) $index; // This is cast as a string so it can be compared with the database value.
$result['peer'] = $atNtpAssociationEntry[$index]['atNtpAssociationPeerAddr'];
$result['port'] = '123'; // awplus only supports default NTP Port.
@ -122,9 +122,9 @@ if (is_null($atNtpAssociationEntry)) {
$module = strtolower($module);
if (count($components) > 0) {
if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?', array($device['device_id'], $module)) == '0') {
dbInsert(array('device_id' => $device['device_id'], 'app_type' => $module, 'app_status' => '', 'app_instance' => ''), 'applications');
if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?', [$device['device_id'], $module]) == '0') {
dbInsert(['device_id' => $device['device_id'], 'app_type' => $module, 'app_status' => '', 'app_instance' => ''], 'applications');
}
} else {
dbDelete('applications', '`device_id` = ? AND `app_type` = ?', array($device['device_id'], $module));
dbDelete('applications', '`device_id` = ? AND `app_type` = ?', [$device['device_id'], $module]);
}

View File

@ -16,13 +16,13 @@ use LibreNMS\Util\IP;
$module = 'ntp';
$component = new LibreNMS\Component();
$components = $component->getComponents($device['device_id'], array('type'=>$module));
$components = $component->getComponents($device['device_id'], ['type'=>$module]);
// We only care about our device id.
$components = $components[$device['device_id']];
// Begin our master array, all other values will be processed into this array.
$tblComponents = array();
$tblComponents = [];
// Let's gather some data..
// For Reference:
@ -43,7 +43,7 @@ if (is_null($cntpPeersVarEntry)) {
// Let's grab the index for each NTP peer
foreach ((array) $cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][2] as $index => $value) {
$result = array();
$result = [];
$result['UID'] = (string) $index; // This is cast as a string so it can be compared with the database value.
$result['peer'] = $cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][3][$index];
$result['port'] = $cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][4][$index];
@ -122,9 +122,9 @@ if (is_null($cntpPeersVarEntry)) {
$module = strtolower($module);
if (! empty($components)) {
if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?', array($device['device_id'], $module)) == '0') {
dbInsert(array('device_id' => $device['device_id'], 'app_type' => $module, 'app_status' => '', 'app_instance' => ''), 'applications');
if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?', [$device['device_id'], $module]) == '0') {
dbInsert(['device_id' => $device['device_id'], 'app_type' => $module, 'app_status' => '', 'app_instance' => ''], 'applications');
}
} else {
dbDelete('applications', '`device_id` = ? AND `app_type` = ?', array($device['device_id'], $module));
dbDelete('applications', '`device_id` = ? AND `app_type` = ?', [$device['device_id'], $module]);
}

View File

@ -3,7 +3,7 @@
use Illuminate\Support\Str;
if (Str::startsWith($device['sysDescr'], 'Linux') || Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.8072.3.2.10')) {
if (Str::startsWith($device['sysObjectID'], array('.1.3.6.1.4.1.10002.1', '.1.3.6.1.4.1.41112.1.4'))
if (Str::startsWith($device['sysObjectID'], ['.1.3.6.1.4.1.10002.1', '.1.3.6.1.4.1.41112.1.4'])
|| Str::contains(snmp_walk($device, 'dot11manufacturerName', '-Osqnv', 'IEEE802dot11-MIB'), 'Ubiquiti')
) {
$os = 'airos';

View File

@ -11,7 +11,7 @@ unset(
$entry
);
$stack_poll_array = snmpwalk_cache_twopart_oid($device, 'ifStackStatus', array(), 'IF-MIB');
$stack_poll_array = snmpwalk_cache_twopart_oid($device, 'ifStackStatus', [], 'IF-MIB');
foreach ($stack_poll_array as $port_id_high => $entry_high) {
foreach ($entry_high as $port_id_low => $entry_low) {
@ -20,13 +20,13 @@ foreach ($stack_poll_array as $port_id_high => $entry_high) {
if ($stack_db_array[$port_id_high][$port_id_low]['ifStackStatus'] == $ifStackStatus) {
echo '.';
} else {
dbUpdate(array('ifStackStatus' => $ifStackStatus), 'ports_stack', 'device_id=? AND port_id_high=? AND `port_id_low`=?', array($device['device_id'], $port_id_high, $port_id_low));
dbUpdate(['ifStackStatus' => $ifStackStatus], 'ports_stack', 'device_id=? AND port_id_high=? AND `port_id_low`=?', [$device['device_id'], $port_id_high, $port_id_low]);
echo 'U';
}
unset($stack_db_array[$port_id_high][$port_id_low]);
} else {
dbInsert(array('device_id' => $device['device_id'], 'port_id_high' => $port_id_high, 'port_id_low' => $port_id_low, 'ifStackStatus' => $ifStackStatus), 'ports_stack');
dbInsert(['device_id' => $device['device_id'], 'port_id_high' => $port_id_high, 'port_id_low' => $port_id_low, 'ifStackStatus' => $ifStackStatus], 'ports_stack');
echo '+';
}
}//end foreach
@ -40,7 +40,7 @@ unset($stack_poll_array);
foreach ($stack_db_array as $port_id_high => $array) {
foreach ($array as $port_id_low => $blah) {
echo $device['device_id'] . ' ' . $port_id_low . ' ' . $port_id_high . "\n";
dbDelete('ports_stack', '`device_id` = ? AND port_id_high = ? AND port_id_low = ?', array($device['device_id'], $port_id_high, $port_id_low));
dbDelete('ports_stack', '`device_id` = ? AND port_id_high = ? AND port_id_low = ?', [$device['device_id'], $port_id_high, $port_id_low]);
echo '-';
}
}

View File

@ -18,7 +18,6 @@ if ($device['os'] == 'airos-af-ltu') {
// End Building SNMP Cache Array
d_echo($port_stats);
// By default libreNMS uses the ifIndex to associate ports on devices with ports discoverd/polled
// before and stored in the database. On Linux boxes this is a problem as ifIndexes may be
// unstable between reboots or (re)configuration of tunnel interfaces (think: GRE/OpenVPN/Tinc/...)

View File

@ -22,8 +22,7 @@
* @copyright 2020 Denny Friebe
* @author Denny Friebe <denny.friebe@icera-network.de>
*/
$airos_eth_stat = snmpwalk_cache_oid($device, 'afLTUethConnected', array(), 'UBNT-AFLTU-MIB', null, '-OteQUsb');
$airos_eth_stat = snmpwalk_cache_oid($device, 'afLTUethConnected', [], 'UBNT-AFLTU-MIB', null, '-OteQUsb');
foreach ($port_stats as $index => $afport_stats) {
if ($afport_stats['ifDescr'] == 'eth0') {
@ -36,7 +35,6 @@ foreach ($port_stats as $index => $afport_stats) {
* Because "IF-MIB" reads wrong information we remove the existing entry for "eth0" if "afLTUethConnected"
* could not be read to prevent wrong information from being stored.
*/
unset($port_stats[$index]);
}
break;

View File

@ -1,4 +1,5 @@
<?php
$brocade_stats = snmpwalk_group($device, 'swFCPortName', 'SW-MIB', 1, $brocade_stats);
foreach ($brocade_stats as $index => $port) {
$index_brocade = $index + 1073741823;

View File

@ -20,8 +20,8 @@
//We can use RFC1213 or IP-FORWARD-MIB or MPLS-L3VPN-STD-MIB
use App\Models\Device;
use LibreNMS\Util\IPv4;
use LibreNMS\Config;
use LibreNMS\Util\IPv4;
$ipForwardMibRoutesNumber = snmp_get($device, 'IP-FORWARD-MIB::inetCidrRouteNumber.0', '-Osqn');
@ -42,7 +42,7 @@ $delete_row = [];
$update_timestamp = dbFetchRows('select now() as now')[0]['now'];
//Load current DB entries:
$dbRoute = dbFetchRows('select * from `route` where `device_id` = ?', array($device['device_id']));
$dbRoute = dbFetchRows('select * from `route` where `device_id` = ?', [$device['device_id']]);
foreach ($dbRoute as $dbRow) {
$current = $mixed[$dbRow['context_name']][$dbRow['inetCidrRouteDestType']][$dbRow['inetCidrRouteDest']][$dbRow['inetCidrRoutePfxLen']][$dbRow['inetCidrRoutePolicy']][$dbRow['inetCidrRouteNextHopType']][$dbRow['inetCidrRouteNextHop']];
if (isset($current) && isset($current['db']) && count($current['db']) > 0) {
@ -63,7 +63,7 @@ foreach ($dbRoute as $dbRow) {
if (! isset($ipForwardNb['0']['inetCidrRouteNumber'])) {
//RFC1213-MIB
$mib = "RFC1213-MIB";
$tableRoute = array();
$tableRoute = [];
$oid = '.1.3.6.1.2.1.4.21';
$tableRoute = snmpwalk_group($device, $oid, $mib, 1, []);
@ -98,7 +98,7 @@ if (! isset($ipForwardNb['0']['inetCidrRouteNumber'])) {
$entryClean['route_id'] = $current['db']['route_id'];
$update_row[] = $entryClean;
} else {
$entry['created_at'] = array('NOW()');
$entry['created_at'] = ['NOW()'];
$create_row[] = $entryClean;
}
}
@ -109,7 +109,6 @@ if (! isset($ipForwardNb['0']['inetCidrRouteNumber'])) {
// IP-FORWARD-MIB with inetCidrRouteTable
if (isset($ipForwardNb['0']['inetCidrRouteNumber']) && $ipForwardNb['0']['inetCidrRouteNumber'] < $max_routes) {
// We have ip forward mib available
d_echo('IP FORWARD MIB (with inetCidr support)');
@ -156,7 +155,7 @@ if (isset($ipForwardNb['0']['inetCidrRouteNumber']) && $ipForwardNb['0']['inetCi
d_echo($current['db']);
d_echo(count($current['db']));
d_echo($delete_row[$current['db']['route_id']]);
$entry['created_at'] = array('NOW()');
$entry['created_at'] = ['NOW()'];
$create_row[] = $entry;
}
}
@ -208,7 +207,7 @@ if (isset($ipForwardNb['0']['ipCidrRouteNumber']) && $ipForwardNb['0']['ipCidrRo
$entryClean['route_id'] = $current['db']['route_id'];
$update_row[] = $entryClean;
} else {
$entryClean['created_at'] = array('NOW()');
$entryClean['created_at'] = ['NOW()'];
$create_row[] = $entryClean;
}
}
@ -221,14 +220,13 @@ if (isset($ipForwardNb['0']['ipCidrRouteNumber']) && $ipForwardNb['0']['ipCidrRo
// MPLS-L3VPN-STD-MIB::mplsL3VpnVrfRteTable
// Route numbers : MPLS-L3VPN-STD-MIB::mplsL3VpnVrfPerfCurrNumRoutes
$mib = 'MPLS-L3VPN-STD-MIB';
$oid = 'mplsL3VpnVrfPerfCurrNumRoutes';
$mpls_vpn_route_nb = snmpwalk_group($device, $oid, $mib, 6, []);
foreach ($mpls_vpn_route_nb as $vpnId => $route_nb) {
if ($route_nb['mplsL3VpnVrfPerfCurrNumRoutes'] > $max_routes) {
echo("Skipping all MPLS routes because vpn instance $vpnId has more than $max_routes routes.");
echo "Skipping all MPLS routes because vpn instance $vpnId has more than $max_routes routes.";
$mpls_skip = 1;
}
}
@ -287,7 +285,7 @@ if ($mpls_skip != 1) {
d_echo($current['db']);
d_echo(count($current['db']));
d_echo($delete_row[$current['db']['route_id']]);
$entry['created_at'] = array('NOW()');
$entry['created_at'] = ['NOW()'];
$create_row[] = $entry;
}
}
@ -304,7 +302,7 @@ foreach ($delete_row as $k => $v) {
dbDelete(
'route',
'`route_id` = ?',
array($k)
[$k]
);
echo '-';
d_echo($delete_row_data[$k]);
@ -316,7 +314,7 @@ foreach ($update_row as $upd_entry) {
$upd_entry,
'route',
'`route_id` = ?',
array($upd_entry['route_id'])
[$upd_entry['route_id']]
);
echo '.';
}

View File

@ -4,7 +4,7 @@ use LibreNMS\Config;
use LibreNMS\Device\YamlDiscovery;
use LibreNMS\OS;
$valid['sensor'] = array();
$valid['sensor'] = [];
/** @var OS $os */
$pre_cache = $os->preCache();
@ -42,7 +42,7 @@ if ($device['os_group'] == 'printer') {
include 'includes/discovery/sensors/state/printer.inc.php';
}
$run_sensors = array(
$run_sensors = [
'airflow',
'current',
'charge',
@ -70,7 +70,7 @@ $run_sensors = array(
'ber',
'eer',
'waterflow',
);
];
// filter submodules
$run_sensors = array_intersect($run_sensors, Config::get('discovery_submodules.sensors', $run_sensors));

View File

@ -22,7 +22,6 @@
* @copyright 2016 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
foreach ($pre_cache['cooling_unit_analog'] as $index => $data) {
$cur_oid = '.1.3.6.1.4.1.318.1.1.27.1.4.1.2.1.3.' . $index;
$descr = $data['coolingUnitStatusAnalogDescription'];

View File

@ -22,7 +22,6 @@
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <gh+n@laf.io>
*/
$value = snmp_get($device, 'climateAirflow', '-Oqv', 'GEIST-MIB-V3');
$current_oid = '.1.3.6.1.4.1.21239.2.2.1.9.1';
$descr = 'Airflow';

View File

@ -24,7 +24,6 @@
*
* Modified for FEC, Magnus Bergroth
*/
foreach ($pre_cache['infineragroove_portTable'] as $index => $data) {
if (is_numeric($data['ochOsPreFecBer']) && $data['ochOsPreFecBer'] > 0) {
$descr = $data['portAlias'] . ' PreFecBer';

View File

@ -7,7 +7,7 @@ d_echo($oids."\n");
if (! empty($oids)) {
echo 'APC UPS Battery Charge High Precision';
$type = 'apc';
list($oid,$current) = explode(' ', $oids);
[$oid,$current] = explode(' ', $oids);
$precision = 10;
$sensorType = 'apc';
@ -28,7 +28,7 @@ if (!empty($oids)) {
if (! empty($oids)) {
echo 'APC UPS Battery Charge';
$type = 'apc';
list($oid,$current) = explode(' ', $oids);
[$oid,$current] = explode(' ', $oids);
$precision = 1;
$sensorType = 'apc';

View File

@ -20,7 +20,6 @@ $ups_device_manufacturer = str_replace('"', '', snmp_get($device, $ups_devic
$ups_device_model_oid = '.1.3.6.1.4.1.6574.4.1.1.0';
$ups_device_model = str_replace('"', '', snmp_get($device, $ups_device_model_oid, '-Oqv'));
// UPS Battery Charge Value, example return : SNMPv2-SMI::enterprises.6574.4.3.1.1.0 = Opaque: Float: 100.000000
$ups_charge_oid = '.1.3.6.1.4.1.6574.4.3.1.1.0';
$ups_charge = snmp_get($device, $ups_charge_oid, '-Oqv');

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