mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 02:18:39 +00:00
Apply fixes from StyleCI (#12120)
This commit is contained in:
parent
77c531527c
commit
82f43cb98d
@ -208,6 +208,7 @@ class CiHelper
|
||||
|
||||
// Disabled in favor of styleci
|
||||
echo "Style check disabled.\n";
|
||||
|
||||
return 0;
|
||||
|
||||
$cs_cmd = [
|
||||
|
@ -4,80 +4,78 @@ use LibreNMS\Config;
|
||||
|
||||
function format_bytes_billing($value)
|
||||
{
|
||||
return format_number($value, Config::get('billing.base')).'B';
|
||||
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);
|
||||
$year = date('Y');
|
||||
$month = date('m');
|
||||
$year = date('Y');
|
||||
$month = date('m');
|
||||
|
||||
if (date('d') > $dayofmonth) {
|
||||
// Billing day is past, so it is next month
|
||||
$date_end = date_create($year.'-'.$month.'-'.$dayofmonth);
|
||||
$date_start = date_create($year.'-'.$month.'-'.$dayofmonth);
|
||||
$date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
|
||||
$date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
|
||||
date_add($date_end, date_interval_create_from_date_string('1 month'));
|
||||
} else {
|
||||
// Billing day will happen this month, therefore started last month
|
||||
$date_end = date_create($year.'-'.$month.'-'.$dayofmonth);
|
||||
$date_start = date_create($year.'-'.$month.'-'.$dayofmonth);
|
||||
$date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
|
||||
$date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
|
||||
date_sub($date_start, date_interval_create_from_date_string('1 month'));
|
||||
}
|
||||
|
||||
if ($months > 0) {
|
||||
date_sub($date_start, date_interval_create_from_date_string($months.' month'));
|
||||
date_sub($date_end, date_interval_create_from_date_string($months.' month'));
|
||||
date_sub($date_start, date_interval_create_from_date_string($months . ' month'));
|
||||
date_sub($date_end, date_interval_create_from_date_string($months . ' month'));
|
||||
}
|
||||
|
||||
// date_sub($date_start, date_interval_create_from_date_string('1 month'));
|
||||
date_sub($date_end, date_interval_create_from_date_string('1 day'));
|
||||
|
||||
$date_from = date_format($date_start, 'Ymd').'000000';
|
||||
$date_to = date_format($date_end, 'Ymd').'235959';
|
||||
$date_from = date_format($date_start, 'Ymd') . '000000';
|
||||
$date_to = date_format($date_end, 'Ymd') . '235959';
|
||||
|
||||
date_sub($date_start, date_interval_create_from_date_string('1 month'));
|
||||
date_sub($date_end, date_interval_create_from_date_string('1 month'));
|
||||
|
||||
$last_from = date_format($date_start, 'Ymd').'000000';
|
||||
$last_to = date_format($date_end, 'Ymd').'235959';
|
||||
$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()));
|
||||
$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));
|
||||
$value = snmp_get($device, $oid, '-Oqv');
|
||||
$oid = 'IF-MIB::ifHC' . $inout . 'Octets.' . $id;
|
||||
$device = dbFetchRow("SELECT * from `devices` WHERE `hostname` = ? LIMIT 1", [$host]);
|
||||
$value = snmp_get($device, $oid, '-Oqv');
|
||||
|
||||
if (!is_numeric($value)) {
|
||||
$oid = 'IF-MIB::if'.$inout.'Octets.'.$id;
|
||||
if (! is_numeric($value)) {
|
||||
$oid = 'IF-MIB::if' . $inout . 'Octets.' . $id;
|
||||
$value = snmp_get($device, $oid, '-Oqv');
|
||||
}
|
||||
|
||||
@ -86,97 +84,95 @@ 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));
|
||||
if (!is_null($row)) {
|
||||
$return['timestamp'] = $row['timestamp'];
|
||||
$return['in_counter'] = $row['in_counter'];
|
||||
$return['in_delta'] = $row['in_delta'];
|
||||
$return['out_counter'] = $row['out_counter'];
|
||||
$return['out_delta'] = $row['out_delta'];
|
||||
$return['state'] = 'ok';
|
||||
} 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));
|
||||
if (!is_null($row)) {
|
||||
$return['delta'] = $row['delta'];
|
||||
$return['delta_in'] = $row['delta_in'];
|
||||
$return['delta_out'] = $row['delta_out'];
|
||||
$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['state'] = 'ok';
|
||||
$return['in_counter'] = $row['in_counter'];
|
||||
$return['in_delta'] = $row['in_delta'];
|
||||
$return['out_counter'] = $row['out_counter'];
|
||||
$return['out_delta'] = $row['out_delta'];
|
||||
$return['state'] = 'ok';
|
||||
} else {
|
||||
$return['state'] = 'failed';
|
||||
}
|
||||
return ($return);
|
||||
|
||||
return $return;
|
||||
}//end getLastPortCounter()
|
||||
|
||||
function getLastMeasurement($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'];
|
||||
$return['delta_out'] = $row['delta_out'];
|
||||
$return['timestamp'] = $row['timestamp'];
|
||||
$return['state'] = 'ok';
|
||||
} else {
|
||||
$return['state'] = 'failed';
|
||||
}
|
||||
|
||||
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));
|
||||
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
|
||||
$mq_sql .= " AND timestamp > ? AND timestamp <= ?";
|
||||
$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 = "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));
|
||||
$m_95th = $a_95th[$measurement_95th];
|
||||
$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));
|
||||
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
|
||||
$mq_sql .= " AND timestamp > ? AND timestamp <= ?";
|
||||
$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 = "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));
|
||||
$m_95th = $a_95th[$measurement_95th];
|
||||
$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));
|
||||
$mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
|
||||
$mq_sql .= " AND timestamp > ? AND timestamp <= ?";
|
||||
$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 = "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));
|
||||
$m_95th = $a_95th[$measurement_95th];
|
||||
$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 = [];
|
||||
|
||||
$sum_data = getSum($bill_id, $datefrom, $dateto);
|
||||
$mtot = $sum_data['total'];
|
||||
$mtot_in = $sum_data['inbound'];
|
||||
$mtot = $sum_data['total'];
|
||||
$mtot_in = $sum_data['inbound'];
|
||||
$mtot_out = $sum_data['outbound'];
|
||||
$ptot = $sum_data['period'];
|
||||
$ptot = $sum_data['period'];
|
||||
|
||||
$data['rate_95th_in'] = get95thIn($bill_id, $datefrom, $dateto);
|
||||
$data['rate_95th_in'] = get95thIn($bill_id, $datefrom, $dateto);
|
||||
$data['rate_95th_out'] = get95thout($bill_id, $datefrom, $dateto);
|
||||
|
||||
if ($dir_95th == 'agg') {
|
||||
@ -185,48 +181,48 @@ function getRates($bill_id, $datefrom, $dateto, $dir_95th)
|
||||
} else {
|
||||
if ($data['rate_95th_out'] > $data['rate_95th_in']) {
|
||||
$data['rate_95th'] = $data['rate_95th_out'];
|
||||
$data['dir_95th'] = 'out';
|
||||
$data['dir_95th'] = 'out';
|
||||
} else {
|
||||
$data['rate_95th'] = $data['rate_95th_in'];
|
||||
$data['dir_95th'] = 'in';
|
||||
$data['dir_95th'] = 'in';
|
||||
}
|
||||
}
|
||||
|
||||
$data['total_data'] = $mtot;
|
||||
$data['total_data_in'] = $mtot_in;
|
||||
$data['total_data'] = $mtot;
|
||||
$data['total_data_in'] = $mtot_in;
|
||||
$data['total_data_out'] = $mtot_out;
|
||||
$data['rate_average'] = ($mtot / $ptot * 8);
|
||||
$data['rate_average_in'] = ($mtot_in / $ptot * 8);
|
||||
$data['rate_average_out'] = ($mtot_out / $ptot * 8);
|
||||
$data['rate_average'] = ($mtot / $ptot * 8);
|
||||
$data['rate_average_in'] = ($mtot_in / $ptot * 8);
|
||||
$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;
|
||||
@ -235,86 +231,86 @@ function getBillingHistoryBitsGraphData($bill_id, $bill_hist_id, $reducefactor)
|
||||
$graph_data = getBillingBitsGraphData($bill_id, $histrow['from'], $histrow['to'], $reducefactor);
|
||||
|
||||
// Overwrite the rate data with the historical version
|
||||
$graph_data['rate_95th'] = $histrow['rate_95th'];
|
||||
$graph_data['rate_95th'] = $histrow['rate_95th'];
|
||||
$graph_data['rate_average'] = $histrow['rate_average'];
|
||||
$graph_data['bill_type'] = $histrow['bill_type'];
|
||||
$graph_data['bill_type'] = $histrow['bill_type'];
|
||||
|
||||
return $graph_data;
|
||||
}
|
||||
|
||||
function getBillingBitsGraphData($bill_id, $from, $to, $reducefactor)
|
||||
{
|
||||
$i = '0';
|
||||
$iter = 0;
|
||||
$first = null;
|
||||
$last = null;
|
||||
$iter_in = 0;
|
||||
$iter_out = 0;
|
||||
$i = '0';
|
||||
$iter = 0;
|
||||
$first = null;
|
||||
$last = null;
|
||||
$iter_in = 0;
|
||||
$iter_out = 0;
|
||||
$iter_period = 0;
|
||||
$max_in = 0;
|
||||
$max_out = 0;
|
||||
$tot_in = 0;
|
||||
$tot_out = 0;
|
||||
$max_in = 0;
|
||||
$max_out = 0;
|
||||
$tot_in = 0;
|
||||
$tot_out = 0;
|
||||
$tot_period = 0;
|
||||
$in_delta = null;
|
||||
$out_delta = null;
|
||||
$period = null;
|
||||
$in_data = array();
|
||||
$out_data = array();
|
||||
$tot_data = array();
|
||||
$ticks = array();
|
||||
$in_delta = null;
|
||||
$out_delta = null;
|
||||
$period = null;
|
||||
$in_data = [];
|
||||
$out_data = [];
|
||||
$tot_data = [];
|
||||
$ticks = [];
|
||||
|
||||
if (!isset($reducefactor) || !is_numeric($reducefactor) || $reducefactor < 1) {
|
||||
if (! isset($reducefactor) || ! is_numeric($reducefactor) || $reducefactor < 1) {
|
||||
// Auto calculate reduce factor
|
||||
$expectedpoints = ceil(($to - $from) / 300);
|
||||
$desiredpoints = 400;
|
||||
$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) {
|
||||
if (! $first) {
|
||||
$first = $timestamp;
|
||||
}
|
||||
|
||||
$period = $row['period'];
|
||||
$in_delta = $row['in_delta'] * 8;
|
||||
$period = $row['period'];
|
||||
$in_delta = $row['in_delta'] * 8;
|
||||
$out_delta = $row['out_delta'] * 8;
|
||||
$last = $timestamp;
|
||||
$last = $timestamp;
|
||||
|
||||
$iter_in += $in_delta;
|
||||
$iter_out += $out_delta;
|
||||
$iter_in += $in_delta;
|
||||
$iter_out += $out_delta;
|
||||
$iter_period += $period;
|
||||
|
||||
if ($period > 0) {
|
||||
$max_in = max($max_in, $in_delta / $period);
|
||||
$max_out = max($max_out, $out_delta / $period);
|
||||
$tot_in += $in_delta;
|
||||
$tot_out += $out_delta;
|
||||
$tot_period+= $period;
|
||||
$max_in = max($max_in, $in_delta / $period);
|
||||
$max_out = max($max_out, $out_delta / $period);
|
||||
$tot_in += $in_delta;
|
||||
$tot_out += $out_delta;
|
||||
$tot_period += $period;
|
||||
|
||||
if (++$iter >= $reducefactor) {
|
||||
$out_data[$i] = round(($iter_out / $iter_period), 2);
|
||||
$in_data[$i] = round(($iter_in / $iter_period), 2);
|
||||
$in_data[$i] = round(($iter_in / $iter_period), 2);
|
||||
$tot_data[$i] = ($out_data[$i] + $in_data[$i]);
|
||||
$ticks[$i] = $timestamp;
|
||||
$ticks[$i] = $timestamp;
|
||||
$i++;
|
||||
$iter = 0;
|
||||
$iter = 0;
|
||||
unset($iter_out, $iter_in, $iter_period);
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
if (!empty($iter_in)) { // Write last element
|
||||
if (! empty($iter_in)) { // Write last element
|
||||
$out_data[$i] = round(($iter_out / $iter_period), 2);
|
||||
$in_data[$i] = round(($iter_in / $iter_period), 2);
|
||||
$in_data[$i] = round(($iter_in / $iter_period), 2);
|
||||
$tot_data[$i] = ($out_data[$i] + $in_data[$i]);
|
||||
$ticks[$i] = $timestamp;
|
||||
$ticks[$i] = $timestamp;
|
||||
$i++;
|
||||
}
|
||||
$result = array(
|
||||
$result = [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'first' => $first,
|
||||
@ -327,17 +323,18 @@ 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;
|
||||
$result['max_out'] = $max_out;
|
||||
$result['ave_in'] = $tot_in / $tot_period;
|
||||
$result['ave_out'] = $tot_out / $tot_period;
|
||||
$result['last_in'] = $in_delta / $period;
|
||||
$result['max_in'] = $max_in;
|
||||
$result['max_out'] = $max_out;
|
||||
$result['ave_in'] = $tot_in / $tot_period;
|
||||
$result['ave_out'] = $tot_out / $tot_period;
|
||||
$result['last_in'] = $in_delta / $period;
|
||||
$result['last_out'] = $out_delta / $period;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}//end getBillingBitsGraphData
|
||||
|
||||
@ -345,19 +342,19 @@ 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();
|
||||
$allowed_val = null;
|
||||
$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) {
|
||||
$datefrom = strftime('%Y-%m-%d', strtotime($data['bill_datefrom']));
|
||||
$dateto = strftime('%Y-%m-%d', strtotime($data['bill_dateto']));
|
||||
$datelabel = $datefrom." - ".$dateto;
|
||||
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;
|
||||
|
||||
array_push($ticklabels, $datelabel);
|
||||
array_push($in_data, $data['traf_in']);
|
||||
@ -371,7 +368,7 @@ function getHistoricTransferGraphData($bill_id)
|
||||
if ($i < 12) {
|
||||
$y = (12 - $i);
|
||||
for ($x = 0; $x < $y; $x++) {
|
||||
$allowed = (($x == '0') ? $allowed_val : '0' );
|
||||
$allowed = (($x == '0') ? $allowed_val : '0');
|
||||
array_push($in_data, '0');
|
||||
array_push($out_data, '0');
|
||||
array_push($tot_data, '0');
|
||||
@ -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,38 +388,38 @@ 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;
|
||||
}
|
||||
$from = $histrow['from'];
|
||||
$to = $histrow['to'];
|
||||
$from = $histrow['from'];
|
||||
$to = $histrow['to'];
|
||||
} else {
|
||||
if (!is_numeric($from) || !is_numeric($to)) {
|
||||
die('Must supply from and to if bill_hist_id is not supplied');
|
||||
if (! is_numeric($from) || ! is_numeric($to)) {
|
||||
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);
|
||||
@ -460,9 +457,9 @@ function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgt
|
||||
array_push($ave_data, $average);
|
||||
}
|
||||
|
||||
$graph_name = date('M j g:ia', $from).' - '.date('M j g:ia', $to);
|
||||
$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
|
||||
|
@ -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));
|
||||
$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,
|
||||
];
|
||||
}
|
||||
|
@ -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));
|
||||
$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
|
||||
|
@ -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()],
|
||||
];
|
||||
|
@ -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));
|
||||
$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
|
||||
|
@ -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));
|
||||
$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
|
||||
|
@ -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));
|
||||
$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,
|
||||
];
|
||||
}
|
||||
|
@ -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);
|
||||
$data = dbFetchRows($query);
|
||||
$response[$name] = $data;
|
||||
}
|
||||
$response['php_version'][] = array('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['php_version'][] = ['total' => 1, 'version' => $version['php_ver']];
|
||||
$response['python_version'][] = ['total' => 1, 'version' => $version['python_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`
|
||||
@ -83,12 +82,12 @@ if ($enabled == 1) {
|
||||
$device_info = array_map(function ($entry) {
|
||||
// remove hostnames from linux, macosx, and SunOS
|
||||
$entry['sysDescr'] = preg_replace_callback('/^(Linux |Darwin |FreeBSD |SunOS )[A-Za-z0-9._\-]+ ([0-9.]{3,9})/', function ($matches) {
|
||||
return $matches[1] . 'hostname ' .$matches[2];
|
||||
return $matches[1] . 'hostname ' . $matches[2];
|
||||
}, $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,17 +99,17 @@ 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);
|
||||
];
|
||||
$data = json_encode($output);
|
||||
$submit = ['data' => $data];
|
||||
|
||||
$fields = '';
|
||||
foreach ($submit as $key => $value) {
|
||||
$fields .= $key.'='.$value.'&';
|
||||
$fields .= $key . '=' . $value . '&';
|
||||
}
|
||||
|
||||
rtrim($fields, '&');
|
||||
@ -123,7 +122,7 @@ if ($enabled == 1) {
|
||||
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
|
||||
$result = curl_exec($post);
|
||||
} elseif ($enabled == 2) {
|
||||
$uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'");
|
||||
$uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'");
|
||||
$fields = "uuid=$uuid";
|
||||
|
||||
$clear = curl_init();
|
||||
@ -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"', []);
|
||||
}
|
||||
|
@ -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 .'"> </span>';
|
||||
|
||||
return '<span class="alert-status ' . $barColor . '"> </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,9 +71,10 @@ 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>';
|
||||
|
||||
return '<span class="alert-status ' . $barColor . '" style="margin-right:8px;float:left;"></span>';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,7 +90,7 @@ function external_exec($command)
|
||||
$proc = new \Symfony\Component\Process\Process($command);
|
||||
$proc->setTimeout(Config::get('snmp.exec_timeout', 1200));
|
||||
|
||||
if ($debug && !$vdebug) {
|
||||
if ($debug && ! $vdebug) {
|
||||
$patterns = [
|
||||
'/-c\' \'[\S]+\'/',
|
||||
'/-u\' \'[\S]+\'/',
|
||||
@ -113,13 +115,13 @@ function external_exec($command)
|
||||
$debug_command = preg_replace($patterns, $replacements, $proc->getCommandLine());
|
||||
c_echo('SNMP[%c' . $debug_command . "%n]\n");
|
||||
} elseif ($vdebug) {
|
||||
c_echo('SNMP[%c'.$proc->getCommandLine()."%n]\n");
|
||||
c_echo('SNMP[%c' . $proc->getCommandLine() . "%n]\n");
|
||||
}
|
||||
|
||||
$proc->run();
|
||||
$output = $proc->getOutput();
|
||||
|
||||
if ($debug && !$vdebug) {
|
||||
if ($debug && ! $vdebug) {
|
||||
$ip_regex = '/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/';
|
||||
$debug_output = preg_replace($ip_regex, '*', $output);
|
||||
d_echo($debug_output . PHP_EOL);
|
||||
@ -142,11 +144,12 @@ function shorthost($hostname, $len = 12)
|
||||
$parts = explode(".", $hostname);
|
||||
$shorthost = $parts[0];
|
||||
$i = 1;
|
||||
while ($i < count($parts) && strlen($shorthost.'.'.$parts[$i]) < $len) {
|
||||
$shorthost = $shorthost.'.'.$parts[$i];
|
||||
while ($i < count($parts) && strlen($shorthost . '.' . $parts[$i]) < $len) {
|
||||
$shorthost = $shorthost . '.' . $parts[$i];
|
||||
$i++;
|
||||
}
|
||||
return ($shorthost);
|
||||
|
||||
return $shorthost;
|
||||
}
|
||||
|
||||
function isCli()
|
||||
@ -161,18 +164,18 @@ function isCli()
|
||||
function print_error($text)
|
||||
{
|
||||
if (isCli()) {
|
||||
c_echo("%r".$text."%n\n");
|
||||
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>';
|
||||
}
|
||||
}
|
||||
|
||||
function print_message($text)
|
||||
{
|
||||
if (isCli()) {
|
||||
c_echo("%g".$text."%n\n");
|
||||
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)
|
||||
@ -226,7 +229,7 @@ function table_from_entity_type($type)
|
||||
if ($type == "storage") {
|
||||
return $type;
|
||||
} else {
|
||||
return $type."s";
|
||||
return $type . "s";
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,19 +320,16 @@ 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);
|
||||
$model = $refresh ? DeviceCache::refresh((int) $device_id) : DeviceCache::get((int) $device_id);
|
||||
|
||||
$device = $model->toArray();
|
||||
$device['location'] = $model->location->location ?? null;
|
||||
@ -360,28 +361,29 @@ 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)
|
||||
{
|
||||
return DeviceCache::get((int)$device_id)->hostname;
|
||||
return DeviceCache::get((int) $device_id)->hostname;
|
||||
}
|
||||
|
||||
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',
|
||||
'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');
|
||||
$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', ];
|
||||
$string = "";
|
||||
|
||||
for ($i=0; $i<$length; $i++) {
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$key = mt_rand(0, 61);
|
||||
$string .= $entropy[$key];
|
||||
}
|
||||
@ -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)
|
||||
@ -436,43 +438,46 @@ function zeropad($num, $length = 2)
|
||||
|
||||
function set_dev_attrib($device, $attrib_type, $attrib_value)
|
||||
{
|
||||
return DeviceCache::get((int)$device['device_id'])->setAttrib($attrib_type, $attrib_value);
|
||||
return DeviceCache::get((int) $device['device_id'])->setAttrib($attrib_type, $attrib_value);
|
||||
}
|
||||
|
||||
function get_dev_attribs($device_id)
|
||||
{
|
||||
return DeviceCache::get((int)$device_id)->getAttribs();
|
||||
return DeviceCache::get((int) $device_id)->getAttribs();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function get_dev_attrib($device, $attrib_type)
|
||||
{
|
||||
return DeviceCache::get((int)$device['device_id'])->getAttrib($attrib_type);
|
||||
return DeviceCache::get((int) $device['device_id'])->getAttrib($attrib_type);
|
||||
}
|
||||
|
||||
function del_dev_attrib($device, $attrib_type)
|
||||
{
|
||||
return DeviceCache::get((int)$device['device_id'])->forgetAttrib($attrib_type);
|
||||
return DeviceCache::get((int) $device['device_id'])->forgetAttrib($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,18 +490,18 @@ 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];
|
||||
$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;
|
||||
$ext = $sizes[$i];
|
||||
$ext = $sizes[$i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -504,7 +509,7 @@ function format_si($value, $round = '2', $sf = '3')
|
||||
$value = $value * -1;
|
||||
}
|
||||
|
||||
return (number_format(round($value, $round), $sf, '.', '')+0)." ".$ext;
|
||||
return (number_format(round($value, $round), $sf, '.', '') + 0) . " " . $ext;
|
||||
}
|
||||
|
||||
function format_bi($value, $round = '2', $sf = '3')
|
||||
@ -513,17 +518,18 @@ 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;
|
||||
$ext = $sizes[$i];
|
||||
$ext = $sizes[$i];
|
||||
}
|
||||
|
||||
if ($neg) {
|
||||
$value = $value * -1;
|
||||
}
|
||||
return (number_format(round($value, $round), $sf, '.', '')+0)." ".$ext;
|
||||
|
||||
return (number_format(round($value, $round), $sf, '.', '') + 0) . " " . $ext;
|
||||
}
|
||||
|
||||
function format_number($value, $base = '1000', $round = 2, $sf = 3)
|
||||
@ -543,7 +549,7 @@ function is_valid_hostname($hostname)
|
||||
/*
|
||||
* convenience function - please use this instead of 'if ($debug) { echo ...; }'
|
||||
*/
|
||||
if (!function_exists('d_echo')) {
|
||||
if (! function_exists('d_echo')) {
|
||||
//TODO remove this after installs have updated, leaving it for for transition
|
||||
function d_echo($text, $no_debug_text = null)
|
||||
{
|
||||
@ -555,7 +561,7 @@ if (!function_exists('d_echo')) {
|
||||
print_r($text);
|
||||
}
|
||||
|
||||
if (!$debug && $no_debug_text) {
|
||||
if (! $debug && $no_debug_text) {
|
||||
echo "$no_debug_text";
|
||||
}
|
||||
}
|
||||
@ -570,7 +576,7 @@ if (!function_exists('d_echo')) {
|
||||
*/
|
||||
function c_echo($string, $enabled = true)
|
||||
{
|
||||
if (!$enabled) {
|
||||
if (! $enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -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']));
|
||||
$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']));
|
||||
$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)
|
||||
*/
|
||||
@ -672,24 +680,24 @@ function round_Nth($val, $round_to)
|
||||
if (($round_to == "10") || ($round_to == "100") || ($round_to == "1000")) {
|
||||
$diff = $val % $round_to;
|
||||
if ($diff >= ($round_to / 2)) {
|
||||
$ret = $val + ($round_to-$diff);
|
||||
$ret = $val + ($round_to - $diff);
|
||||
} else {
|
||||
$ret = $val - $diff;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
} // end round_Nth
|
||||
|
||||
|
||||
function is_customoid_graph($type, $subtype)
|
||||
{
|
||||
if (!empty($subtype) && $type == 'customoid') {
|
||||
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
|
||||
@ -721,14 +727,13 @@ function object_is_cached($section, $obj)
|
||||
**/
|
||||
function can_ping_device($attribs)
|
||||
{
|
||||
if (Config::get('icmp_check') && !(isset($attribs['override_icmp_disable']) && $attribs['override_icmp_disable'] == "true")) {
|
||||
if (Config::get('icmp_check') && ! (isset($attribs['override_icmp_disable']) && $attribs['override_icmp_disable'] == "true")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} // 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
|
||||
|
||||
/**
|
||||
@ -807,14 +814,14 @@ function version_info($remote = false)
|
||||
$output['github'] = json_decode(curl_exec($api), true);
|
||||
}
|
||||
[$local_sha, $local_date] = explode('|', rtrim(`git show --pretty='%H|%ct' -s HEAD`));
|
||||
$output['local_sha'] = $local_sha;
|
||||
$output['local_date'] = $local_date;
|
||||
$output['local_sha'] = $local_sha;
|
||||
$output['local_date'] = $local_date;
|
||||
$output['local_branch'] = rtrim(`git rev-parse --abbrev-ref HEAD`);
|
||||
}
|
||||
$output['db_schema'] = vsprintf('%s (%s)', $version->database());
|
||||
$output['php_ver'] = phpversion();
|
||||
$output['python_ver'] = \LibreNMS\Util\Version::python();
|
||||
$output['mysql_ver'] = dbIsConnected() ? dbFetchCell('SELECT version()') : '?';
|
||||
$output['db_schema'] = vsprintf('%s (%s)', $version->database());
|
||||
$output['php_ver'] = phpversion();
|
||||
$output['python_ver'] = \LibreNMS\Util\Version::python();
|
||||
$output['mysql_ver'] = dbIsConnected() ? dbFetchCell('SELECT version()') : '?';
|
||||
$output['rrdtool_ver'] = str_replace('1.7.01.7.0', '1.7.0', implode(' ', array_slice(explode(' ', shell_exec(
|
||||
Config::get('rrdtool', 'rrdtool') . ' --version |head -n1'
|
||||
)), 1, 1)));
|
||||
@ -837,6 +844,7 @@ function inet6_ntop($ip)
|
||||
if ($l == 4 or $l == 16) {
|
||||
return inet_ntop(pack('A' . $l, $ip));
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
@ -852,13 +860,13 @@ function format_hostname($device, $hostname = null)
|
||||
$hostname = $device['hostname'];
|
||||
}
|
||||
|
||||
if (Config::get('force_hostname_to_sysname') && !empty($device['sysName'])) {
|
||||
if (is_valid_hostname($hostname) && !IP::isValid($hostname)) {
|
||||
if (Config::get('force_hostname_to_sysname') && ! empty($device['sysName'])) {
|
||||
if (is_valid_hostname($hostname) && ! IP::isValid($hostname)) {
|
||||
return $device['sysName'];
|
||||
}
|
||||
}
|
||||
|
||||
if (Config::get('force_ip_to_sysname') && !empty($device['sysName'])) {
|
||||
if (Config::get('force_ip_to_sysname') && ! empty($device['sysName'])) {
|
||||
if (IP::isValid($hostname)) {
|
||||
return $device['sysName'];
|
||||
}
|
||||
@ -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,20 +940,20 @@ 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;
|
||||
|
||||
// Build maps from ifIndex, ifName, ifDescr to port_id
|
||||
$maps['ifIndex'][$port['ifIndex']] = $port['port_id'];
|
||||
$maps['ifName'][$port['ifName']] = $port['port_id'];
|
||||
$maps['ifName'][$port['ifName']] = $port['port_id'];
|
||||
$maps['ifDescr'][$port['ifDescr']] = $port['port_id'];
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
'ports' => $ports,
|
||||
'maps' => $maps,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -967,9 +975,9 @@ function get_port_id($ports_mapped, $port, $port_association_mode)
|
||||
*
|
||||
* $ports = $ports_mapped['ports'];
|
||||
*/
|
||||
$maps = $ports_mapped['maps'];
|
||||
$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,48 +1010,48 @@ 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';
|
||||
$tmp = dbFetchRows('SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE "'.substr($table, 0, -1).'_%" && TABLE_NAME != "'.$table.'"');
|
||||
$ntables[] = $tmp . 's';
|
||||
$tmp = dbFetchRows('SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE "' . substr($table, 0, -1) . '_%" && TABLE_NAME != "' . $table . '"');
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
@ -1066,25 +1074,25 @@ function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()
|
||||
*/
|
||||
function str_i_contains($haystack, $needles)
|
||||
{
|
||||
foreach ((array)$needles as $needle) {
|
||||
foreach ((array) $needles as $needle) {
|
||||
if ($needle != '' && stripos($haystack, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get alert_rules sql filter by minimal severity
|
||||
*
|
||||
* @param string|int $min_severity
|
||||
* @param string $alert_rules_name
|
||||
* @return string
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get alert_rules sql filter by minimal severity
|
||||
*
|
||||
* @param string|int $min_severity
|
||||
* @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,15 +1100,16 @@ 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)) {
|
||||
} elseif (! empty($min_severity)) {
|
||||
$min_severity_id = $alert_severities[$min_severity];
|
||||
}
|
||||
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 "";
|
||||
}
|
||||
|
||||
@ -1136,8 +1145,9 @@ function display($value, $purifier_config = [])
|
||||
*/
|
||||
function load_os(&$device)
|
||||
{
|
||||
if (!isset($device['os'])) {
|
||||
if (! isset($device['os'])) {
|
||||
d_echo("No OS to load\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1145,7 +1155,7 @@ function load_os(&$device)
|
||||
|
||||
// Set type to a predefined type for the OS if it's not already set
|
||||
$loaded_os_type = Config::get("os.{$device['os']}.type");
|
||||
if ((!isset($device['attribs']['override_device_type']) && $device['attribs']['override_device_type'] != 1) && array_key_exists('type', $device) && $loaded_os_type != $device['type']) {
|
||||
if ((! isset($device['attribs']['override_device_type']) && $device['attribs']['override_device_type'] != 1) && array_key_exists('type', $device) && $loaded_os_type != $device['type']) {
|
||||
log_event('Device type changed ' . $device['type'] . ' => ' . $loaded_os_type, $device, 'system', 3);
|
||||
$device['type'] = $loaded_os_type;
|
||||
dbUpdate(['type' => $loaded_os_type], 'devices', 'device_id=?', [$device['device_id']]);
|
||||
@ -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)
|
||||
{
|
||||
@ -1212,13 +1221,12 @@ function uw_to_dbm($value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts mW to dBm
|
||||
* $value must be positive
|
||||
*
|
||||
*/
|
||||
* Converts mW to dBm
|
||||
* $value must be positive
|
||||
*/
|
||||
function mw_to_dbm($value)
|
||||
{
|
||||
return 10 * log10($value);
|
||||
return 10 * log10($value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1229,7 +1237,7 @@ function mw_to_dbm($value)
|
||||
*/
|
||||
function set_null($value, $default = null, $min = null)
|
||||
{
|
||||
if (!is_numeric($value)) {
|
||||
if (! is_numeric($value)) {
|
||||
return $default;
|
||||
} elseif (is_nan($value)) {
|
||||
return $default;
|
||||
@ -1238,6 +1246,7 @@ function set_null($value, $default = null, $min = null)
|
||||
} elseif (isset($min) && $value < $min) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
/*
|
||||
@ -1247,12 +1256,13 @@ function set_null($value, $default = null, $min = null)
|
||||
*/
|
||||
function set_numeric($value, $default = 0)
|
||||
{
|
||||
if (!is_numeric($value) ||
|
||||
if (! is_numeric($value) ||
|
||||
is_nan($value) ||
|
||||
is_infinite($value)
|
||||
) {
|
||||
$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;
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
@ -47,12 +47,12 @@ function dbConnect($db_host = null, $db_user = '', $db_pass = '', $db_name = '',
|
||||
return Eloquent::DB();
|
||||
}
|
||||
|
||||
if (!extension_loaded('pdo_mysql')) {
|
||||
if (! extension_loaded('pdo_mysql')) {
|
||||
throw new DatabaseConnectException("PHP pdo_mysql extension not loaded!");
|
||||
}
|
||||
|
||||
try {
|
||||
if (!is_null($db_host) || !empty($db_name)) {
|
||||
if (! is_null($db_host) || ! empty($db_name)) {
|
||||
// legacy connection override
|
||||
\Config::set('database.connections.setup', [
|
||||
"driver" => "mysql",
|
||||
@ -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');
|
||||
}
|
||||
@ -93,14 +93,14 @@ function dbQuery($sql, $parameters = [])
|
||||
return Eloquent::DB()->getPdo()->exec($sql) !== false;
|
||||
}
|
||||
|
||||
return Eloquent::DB()->statement($sql, (array)$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
|
||||
@ -110,10 +110,10 @@ function dbInsert($data, $table)
|
||||
{
|
||||
$time_start = microtime(true);
|
||||
|
||||
$sql = 'INSERT IGNORE INTO `'.$table.'` (`'.implode('`,`', array_keys($data)).'`) VALUES ('.implode(',', dbPlaceHolders($data)).')';
|
||||
$sql = 'INSERT IGNORE INTO `' . $table . '` (`' . implode('`,`', array_keys($data)) . '`) VALUES (' . implode(',', dbPlaceHolders($data)) . ')';
|
||||
|
||||
try {
|
||||
$result = Eloquent::DB()->insert($sql, (array)$data);
|
||||
$result = Eloquent::DB()->insert($sql, (array) $data);
|
||||
} catch (PDOException $pdoe) {
|
||||
dbHandleException(new QueryException($sql, $data, $pdoe));
|
||||
}
|
||||
@ -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.
|
||||
@ -157,9 +156,10 @@ function dbBulkInsert($data, $table)
|
||||
|
||||
foreach ($data_chunks as $data_chunk) {
|
||||
try {
|
||||
$result = Eloquent::DB()->table($table)->insert((array)$data_chunk);
|
||||
$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
|
||||
@ -187,9 +186,9 @@ function dbUpdate($data, $table, $where = null, $parameters = [])
|
||||
|
||||
// need field name and placeholder value
|
||||
// but how merge these field placeholders with actual $parameters array for the WHERE clause
|
||||
$sql = 'UPDATE `'.$table.'` set ';
|
||||
$sql = 'UPDATE `' . $table . '` set ';
|
||||
foreach ($data as $key => $value) {
|
||||
$sql .= '`'.$key.'`=';
|
||||
$sql .= '`' . $key . '`=';
|
||||
if (is_array($value)) {
|
||||
$sql .= reset($value);
|
||||
unset($data[$key]);
|
||||
@ -205,14 +204,15 @@ function dbUpdate($data, $table, $where = null, $parameters = [])
|
||||
$sql = substr($sql, 0, -1);
|
||||
// strip off last comma
|
||||
if ($where) {
|
||||
$sql .= ' WHERE '.$where;
|
||||
$sql .= ' WHERE ' . $where;
|
||||
$data = array_merge($data, $parameters);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = Eloquent::DB()->update($sql, (array)$data);
|
||||
$result = Eloquent::DB()->update($sql, (array) $data);
|
||||
|
||||
recordDbStatistic('update', $time_start);
|
||||
|
||||
return $result;
|
||||
} catch (PDOException $pdoe) {
|
||||
dbHandleException(new QueryException($sql, $data, $pdoe));
|
||||
@ -221,27 +221,26 @@ 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);
|
||||
|
||||
$sql = 'DELETE FROM `'.$table.'`';
|
||||
$sql = 'DELETE FROM `' . $table . '`';
|
||||
if ($where) {
|
||||
$sql .= ' WHERE '.$where;
|
||||
$sql .= ' WHERE ' . $where;
|
||||
}
|
||||
|
||||
try {
|
||||
$result = Eloquent::DB()->delete($sql, (array)$parameters);
|
||||
$result = Eloquent::DB()->delete($sql, (array) $parameters);
|
||||
} catch (PDOException $pdoe) {
|
||||
dbHandleException(new QueryException($sql, $parameters, $pdoe));
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
@ -304,9 +303,10 @@ function dbFetchRows($sql, $parameters = [])
|
||||
|
||||
try {
|
||||
$PDO_FETCH_ASSOC = true;
|
||||
$rows = Eloquent::DB()->select($sql, (array)$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;
|
||||
@ -353,9 +349,10 @@ function dbFetchRow($sql = null, $parameters = [])
|
||||
|
||||
try {
|
||||
$PDO_FETCH_ASSOC = true;
|
||||
$row = Eloquent::DB()->selectOne($sql, (array)$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;
|
||||
@ -379,7 +374,7 @@ function dbFetchCell($sql, $parameters = [])
|
||||
|
||||
try {
|
||||
$PDO_FETCH_ASSOC = true;
|
||||
$row = Eloquent::DB()->selectOne($sql, (array)$parameters);
|
||||
$row = Eloquent::DB()->selectOne($sql, (array) $parameters);
|
||||
recordDbStatistic('fetchcell', $time_start);
|
||||
if ($row) {
|
||||
return reset($row);
|
||||
@ -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;
|
||||
@ -410,12 +403,13 @@ function dbFetchColumn($sql, $parameters = [])
|
||||
|
||||
try {
|
||||
$PDO_FETCH_ASSOC = true;
|
||||
foreach (Eloquent::DB()->select($sql, (array)$parameters) as $row) {
|
||||
foreach (Eloquent::DB()->select($sql, (array) $parameters) as $row) {
|
||||
$cells[] = reset($row);
|
||||
}
|
||||
$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
|
||||
@ -516,26 +508,23 @@ function dbPlaceHolders(&$values)
|
||||
} elseif (is_numeric($key)) {
|
||||
$data[] = '?';
|
||||
} else {
|
||||
$data[] = ':'.$key;
|
||||
$data[] = ':' . $key;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}//end dbPlaceHolders()
|
||||
|
||||
|
||||
function dbBeginTransaction()
|
||||
{
|
||||
Eloquent::DB()->beginTransaction();
|
||||
}//end dbBeginTransaction()
|
||||
|
||||
|
||||
function dbCommitTransaction()
|
||||
{
|
||||
Eloquent::DB()->commit();
|
||||
}//end dbCommitTransaction()
|
||||
|
||||
|
||||
function dbRollbackTransaction()
|
||||
{
|
||||
Eloquent::DB()->rollBack();
|
||||
@ -564,9 +553,9 @@ function recordDbStatistic($stat, $start_time)
|
||||
{
|
||||
global $db_stats, $db_stats_last;
|
||||
|
||||
if (!isset($db_stats)) {
|
||||
$db_stats = array(
|
||||
'ops' => array(
|
||||
if (! isset($db_stats)) {
|
||||
$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;
|
||||
}
|
||||
|
||||
@ -621,15 +610,15 @@ function dbSyncRelationship($table, $target_column = null, $target = null, $list
|
||||
|
||||
$delete_query = "`$target_column`=? AND `$list_column`";
|
||||
$delete_params = [$target];
|
||||
if (!empty($list)) {
|
||||
if (! empty($list)) {
|
||||
$delete_query .= ' NOT IN ' . dbGenPlaceholders(count($list));
|
||||
$delete_params = array_merge($delete_params, $list);
|
||||
}
|
||||
$deleted = (int)dbDelete($table, $delete_query, $delete_params);
|
||||
$deleted = (int) dbDelete($table, $delete_query, $delete_params);
|
||||
|
||||
$db_list = dbFetchColumn("SELECT `$list_column` FROM `$table` WHERE `$target_column`=?", [$target]);
|
||||
foreach ($list as $item) {
|
||||
if (!in_array($item, $db_list)) {
|
||||
if (! in_array($item, $db_list)) {
|
||||
dbInsert([$target_column => $target, $list_column => $item], $table);
|
||||
$inserted++;
|
||||
}
|
||||
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -25,15 +25,15 @@
|
||||
|
||||
use LibreNMS\Config;
|
||||
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) {
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
} else {
|
||||
$vrfs_lite_cisco = array(array('context_name'=>''));
|
||||
$vrfs_lite_cisco = [['context_name'=>'']];
|
||||
}
|
||||
|
||||
foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$context = $vrf['context_name'];
|
||||
$device['context_name']=$context;
|
||||
$device['context_name'] = $context;
|
||||
|
||||
if (file_exists(Config::get('install_dir') . "/includes/discovery/arp-table/{$device['os']}.inc.php")) {
|
||||
include Config::get('install_dir') . "/includes/discovery/arp-table/{$device['os']}.inc.php";
|
||||
@ -43,21 +43,21 @@ 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'];
|
||||
|
||||
$port_arp = array_merge(
|
||||
(array)$data['ipNetToMediaPhysAddress'],
|
||||
(array)$data['ipNetToPhysicalPhysAddress']['ipv4']
|
||||
(array) $data['ipNetToMediaPhysAddress'],
|
||||
(array) $data['ipNetToPhysicalPhysAddress']['ipv4']
|
||||
);
|
||||
|
||||
echo "{$interface['ifName']}: \n";
|
||||
@ -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,
|
||||
);
|
||||
'context_name' => (string) $context,
|
||||
];
|
||||
}
|
||||
}
|
||||
echo PHP_EOL;
|
||||
@ -100,23 +100,23 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
);
|
||||
|
||||
// add new entries
|
||||
if (!empty($insert_data)) {
|
||||
if (! empty($insert_data)) {
|
||||
dbBulkInsert($insert_data, 'ipv4_mac');
|
||||
}
|
||||
|
||||
// remove stale entries
|
||||
foreach ($existing_data as $entry) {
|
||||
$entry_mac = $entry['mac_address'];
|
||||
$entry_if = $entry['port_id'];
|
||||
$entry_ip = $entry['ipv4_address'];
|
||||
$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(
|
||||
|
@ -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) {
|
||||
|
@ -27,7 +27,7 @@
|
||||
// collect arp data
|
||||
$nsIpArpTable = snmpwalk_group($device, 'nsIpArpTable', 'NETSCREEN-IP-ARP-MIB');
|
||||
|
||||
if (!empty($nsIpArpTable)) {
|
||||
if (! empty($nsIpArpTable)) {
|
||||
// get internal id to ifIndex map
|
||||
$nsIfInfo = snmpwalk_group($device, 'nsIfInfo', 'NETSCREEN-INTERFACE-MIB', 0);
|
||||
$nsIfInfo = array_flip($nsIfInfo['nsIfInfo']);
|
||||
|
@ -12,10 +12,10 @@ if (Config::get('enable_bgp')) {
|
||||
include Config::get('install_dir') . "/includes/discovery/bgp-peers/{$device['os']}.inc.php";
|
||||
}
|
||||
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) {
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
} else {
|
||||
$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 ';
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ if (Config::get('enable_bgp')) {
|
||||
$peers_data = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', 'junos');
|
||||
} elseif ($device['os_group'] === 'cisco') {
|
||||
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB');
|
||||
$peer2 = !empty($peers_data);
|
||||
$peer2 = ! empty($peers_data);
|
||||
}
|
||||
|
||||
if (empty($peers_data)) {
|
||||
@ -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) ';
|
||||
}
|
||||
}
|
||||
@ -56,9 +56,9 @@ if (Config::get('enable_bgp')) {
|
||||
$peerlist = build_bgp_peers($device, $peers_data, $peer2);
|
||||
|
||||
// Process discovered peers
|
||||
if (!empty($peerlist)) {
|
||||
$af_data = array();
|
||||
$af_list = array();
|
||||
if (! empty($peerlist)) {
|
||||
$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') {
|
||||
@ -80,26 +80,26 @@ if (Config::get('enable_bgp')) {
|
||||
}
|
||||
|
||||
// build the list
|
||||
if (!empty($af_data)) {
|
||||
if (! empty($af_data)) {
|
||||
$af_list = build_cbgp_peers($device, $peer, $af_data, $peer2);
|
||||
}
|
||||
|
||||
if (!$bgp4_mib && $device['os'] == 'junos') {
|
||||
if (! $bgp4_mib && $device['os'] == 'junos') {
|
||||
$afis['ipv4'] = 'ipv4';
|
||||
$afis['ipv6'] = 'ipv6';
|
||||
$afis[25] = 'l2vpn';
|
||||
$safis[1] = 'unicast';
|
||||
$safis[2] = 'multicast';
|
||||
$safis[3] = 'unicastAndMulticast';
|
||||
$safis[4] = 'labeledUnicast';
|
||||
$safis[5] = 'mvpn';
|
||||
$safis[65] = 'vpls';
|
||||
$safis[70] = 'evpn';
|
||||
$safis[128] = 'vpn';
|
||||
$safis[132] = 'rtfilter';
|
||||
$safis[133] = 'flow';
|
||||
$afis[25] = 'l2vpn';
|
||||
$safis[1] = 'unicast';
|
||||
$safis[2] = 'multicast';
|
||||
$safis[3] = 'unicastAndMulticast';
|
||||
$safis[4] = 'labeledUnicast';
|
||||
$safis[5] = 'mvpn';
|
||||
$safis[65] = 'vpls';
|
||||
$safis[70] = 'evpn';
|
||||
$safis[128] = 'vpn';
|
||||
$safis[132] = 'rtfilter';
|
||||
$safis[133] = 'flow';
|
||||
|
||||
if (!isset($j_peerIndexes)) {
|
||||
if (! isset($j_peerIndexes)) {
|
||||
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerEntry', $jbgp, 'BGP4-V2-MIB-JUNIPER', 'junos');
|
||||
d_echo($j_bgp);
|
||||
foreach ($j_bgp as $index => $entry) {
|
||||
@ -107,25 +107,25 @@ if (Config::get('enable_bgp')) {
|
||||
try {
|
||||
$ip = IP::fromHexString($entry['jnxBgpM2PeerRemoteAddr']);
|
||||
d_echo("peerindex for " . $ip->getFamily() . " $ip is $peer_index\n");
|
||||
$j_peerIndexes[(string)$ip] = $peer_index;
|
||||
$j_peerIndexes[(string) $ip] = $peer_index;
|
||||
} catch (InvalidIpException $e) {
|
||||
d_echo("Unable to parse IP for peer $peer_index: " . $entry['jnxBgpM2PeerRemoteAddr'] . PHP_EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($j_afisafi)) {
|
||||
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);
|
||||
$j_afisafi[$index][] = $afisafi;
|
||||
[$index,$afisafi] = explode('.', $key, 2);
|
||||
$j_afisafi[$index][] = $afisafi;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) {
|
||||
list ($afi,$safi) = explode('.', $afisafi);
|
||||
$afi = $afis[$afi];
|
||||
$safi = $safis[$safi];
|
||||
[$afi,$safi] = explode('.', $afisafi);
|
||||
$afi = $afis[$afi];
|
||||
$safi = $safis[$safi];
|
||||
$af_list[$peer['ip']][$afi][$safi] = 1;
|
||||
add_cbgp_peer($device, $peer, $afi, $safi);
|
||||
}
|
||||
@ -133,9 +133,9 @@ if (Config::get('enable_bgp')) {
|
||||
|
||||
$af_query = "SELECT bgpPeerIdentifier, afi, safi FROM bgpPeers_cbgp WHERE `device_id`=? AND bgpPeerIdentifier=? AND context_name=?";
|
||||
foreach (dbFetchRows($af_query, [$device['device_id'], $peer['ip'], $device['context_name']]) as $entry) {
|
||||
$afi = $entry['afi'];
|
||||
$afi = $entry['afi'];
|
||||
$safi = $entry['safi'];
|
||||
if (!$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
|
||||
if (! $af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
|
||||
dbDelete(
|
||||
'bgpPeers_cbgp',
|
||||
'`device_id`=? AND `bgpPeerIdentifier`=? AND context_name=? AND afi=? AND safi=?',
|
||||
@ -153,7 +153,7 @@ if (Config::get('enable_bgp')) {
|
||||
// clean up peers
|
||||
$params = [$device['device_id'], $device['context_name']];
|
||||
$query = 'device_id=? AND context_name=?';
|
||||
if (!empty($peerlist)) {
|
||||
if (! empty($peerlist)) {
|
||||
$query .= ' AND bgpPeerIdentifier NOT IN ' . dbGenPlaceholders(count($peerlist));
|
||||
$params = array_merge($params, array_column($peerlist, 'ip'));
|
||||
}
|
||||
@ -178,7 +178,7 @@ if (Config::get('enable_bgp')) {
|
||||
);
|
||||
$existing_contexts = array_column($vrfs_lite_cisco, 'context_name');
|
||||
foreach ($contexts as $context) {
|
||||
if (!in_array($context, $existing_contexts)) {
|
||||
if (! in_array($context, $existing_contexts)) {
|
||||
dbDelete('bgpPeers', 'device_id=? and context_name=?', [$device['device_id'], $context]);
|
||||
dbDelete('bgpPeers_cbgp', 'device_id=? and context_name=?', [$device['device_id'], $context]);
|
||||
echo '-';
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* timos.inc.php
|
||||
*
|
||||
@ -30,11 +30,11 @@ use LibreNMS\Util\IP;
|
||||
|
||||
if (Config::get('enable_bgp')) {
|
||||
if ($device['os'] == 'timos') {
|
||||
$bgpPeersCache =snmpwalk_cache_multi_oid($device, 'tBgpPeerNgTable', [], 'TIMETRA-BGP-MIB', 'nokia');
|
||||
$bgpPeersCache = snmpwalk_cache_multi_oid($device, 'tBgpPeerNgTable', [], 'TIMETRA-BGP-MIB', 'nokia');
|
||||
foreach ($bgpPeersCache as $key => $value) {
|
||||
$oid = explode(".", $key);
|
||||
$vrfInstance = $oid[0];
|
||||
$address = str_replace($oid[0].".".$oid[1].".", '', $key);
|
||||
$address = str_replace($oid[0] . "." . $oid[1] . ".", '', $key);
|
||||
if (strlen($address) > 15) {
|
||||
$address = IP::fromHexString($address)->compressed();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ if (Config::get('enable_bgp')) {
|
||||
$vrfInstance = '';
|
||||
$value['hwBgpPeerVrfName'] = '';
|
||||
}
|
||||
$address = str_replace($oid[0].".".$oid[1].".".$oid[2].".".$oid[3].".", '', $key);
|
||||
$address = str_replace($oid[0] . "." . $oid[1] . "." . $oid[2] . "." . $oid[3] . ".", '', $key);
|
||||
if ($oid[3] == 'ipv6') {
|
||||
$address = IP::fromHexString($address)->compressed();
|
||||
} elseif ($oid[3] != 'ipv4') {
|
||||
@ -64,7 +64,7 @@ if (Config::get('enable_bgp')) {
|
||||
$bgpPeers[$vrfInstance][$address]['vrf_id'] = $map_vrf['byName'][$vrfInstance]['vrf_id'];
|
||||
$bgpPeers[$vrfInstance][$address]['afi'] = $oid[1];
|
||||
$bgpPeers[$vrfInstance][$address]['safi'] = $oid[2];
|
||||
$bgpPeers[$vrfInstance][$address]['typePeer'] = $oid[3];
|
||||
$bgpPeers[$vrfInstance][$address]['typePeer'] = $oid[3];
|
||||
}
|
||||
|
||||
foreach ($bgpPeers as $vrfName => $vrf) {
|
||||
@ -98,21 +98,21 @@ if (Config::get('enable_bgp')) {
|
||||
unset($peers['vrf_id']);
|
||||
}
|
||||
dbInsert($peers, 'bgpPeers');
|
||||
$seenPeer[$address]=1;
|
||||
$seenPeer[$address] = 1;
|
||||
|
||||
if (Config::get('autodiscovery.bgp')) {
|
||||
$name = gethostbyaddr($address);
|
||||
discover_new_device($name, $device, 'BGP');
|
||||
}
|
||||
echo '+';
|
||||
$vrp_bgp_peer_count ++;
|
||||
$vrp_bgp_peer_count++;
|
||||
} else {
|
||||
dbUpdate(['bgpPeerRemoteAs' => $value['hwBgpPeerRemoteAs'], 'astext' => $astext], 'bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? AND vrf_id = ?', [$device['device_id'], $address, $vrfId]);
|
||||
$seenPeer[$address]=1;
|
||||
$seenPeer[$address] = 1;
|
||||
echo '.';
|
||||
$vrp_bgp_peer_count ++;
|
||||
$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']);
|
||||
@ -135,8 +135,8 @@ if (Config::get('enable_bgp')) {
|
||||
continue; //we just added this peer
|
||||
}
|
||||
if ((empty($vrfId) && empty($bgpPeers[''][$address])) ||
|
||||
(!empty($vrfId) && !empty($vrfName) && empty($bgpPeers[$vrfName][$address])) ||
|
||||
(!empty($vrfId) && empty($vrfName))) {
|
||||
(! empty($vrfId) && ! empty($vrfName) && empty($bgpPeers[$vrfName][$address])) ||
|
||||
(! empty($vrfId) && empty($vrfName))) {
|
||||
$deleted = dbDelete('bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? ' . $checkVrf, [$device['device_id'], $address, $vrfId]);
|
||||
|
||||
echo str_repeat('-', $deleted);
|
||||
@ -146,11 +146,11 @@ if (Config::get('enable_bgp')) {
|
||||
|
||||
$af_query = "SELECT bgpPeerIdentifier, afi, safi FROM bgpPeers_cbgp WHERE `device_id`=? AND bgpPeerIdentifier=?";
|
||||
foreach (dbFetchRows($af_query, [$device['device_id'], $peer['ip']]) as $entry) {
|
||||
$afi = $entry['afi'];
|
||||
$afi = $entry['afi'];
|
||||
$safi = $entry['safi'];
|
||||
$vrfName = $entry['context_name'];
|
||||
if (!exist($bgpPeersCache[$vrfName]) ||
|
||||
!exist($bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']]) ||
|
||||
if (! exist($bgpPeersCache[$vrfName]) ||
|
||||
! exist($bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']]) ||
|
||||
$bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']][$entry['afi']] != $afi ||
|
||||
$bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']][$entry['safi']] != $safi) {
|
||||
dbDelete(
|
||||
|
@ -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,10 +43,10 @@ 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);
|
||||
$result['UID'] = hash('crc32', $spid . "-" . $spobj);
|
||||
|
||||
// Now that we have a valid identifiers, lets add some more data
|
||||
$result['sp-id'] = $spid;
|
||||
@ -66,29 +65,29 @@ if ($device['os_group'] == 'cisco') {
|
||||
switch ($type) {
|
||||
case 1:
|
||||
// Policy-map, get data from that table.
|
||||
d_echo("\nIndex: ".$index."\n");
|
||||
d_echo(" UID: ".$result['UID']."\n");
|
||||
d_echo(" SPID.SPOBJ: ".$result['sp-id'].".".$result['sp-obj']."\n");
|
||||
d_echo(" If-Index: ".$result['ifindex']."\n");
|
||||
d_echo("\nIndex: " . $index . "\n");
|
||||
d_echo(" UID: " . $result['UID'] . "\n");
|
||||
d_echo(" SPID.SPOBJ: " . $result['sp-id'] . "." . $result['sp-obj'] . "\n");
|
||||
d_echo(" If-Index: " . $result['ifindex'] . "\n");
|
||||
d_echo(" Type: 1 - Policy-Map\n");
|
||||
$result['label'] = $tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.1'][$index];
|
||||
if ($tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.2'][$index] != "") {
|
||||
$result['label'] .= " - ".$tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.2'][$index];
|
||||
$result['label'] .= " - " . $tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.2'][$index];
|
||||
}
|
||||
d_echo(" Label: ".$result['label']."\n");
|
||||
d_echo(" Label: " . $result['label'] . "\n");
|
||||
break;
|
||||
case 2:
|
||||
// Class-map, get data from that table.
|
||||
d_echo("\nIndex: ".$index."\n");
|
||||
d_echo(" UID: ".$result['UID']."\n");
|
||||
d_echo(" SPID.SPOBJ: ".$result['sp-id'].".".$result['sp-obj']."\n");
|
||||
d_echo(" If-Index: ".$result['ifindex']."\n");
|
||||
d_echo("\nIndex: " . $index . "\n");
|
||||
d_echo(" UID: " . $result['UID'] . "\n");
|
||||
d_echo(" SPID.SPOBJ: " . $result['sp-id'] . "." . $result['sp-obj'] . "\n");
|
||||
d_echo(" If-Index: " . $result['ifindex'] . "\n");
|
||||
d_echo(" Type: 2 - Class-Map\n");
|
||||
$result['label'] = $tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.1'][$index];
|
||||
if ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index] != "") {
|
||||
$result['label'] .= " - ".$tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index];
|
||||
$result['label'] .= " - " . $tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index];
|
||||
}
|
||||
d_echo(" Label: ".$result['label']."\n");
|
||||
d_echo(" Label: " . $result['label'] . "\n");
|
||||
if ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.3'][$index] == 2) {
|
||||
$result['map-type'] = 'Match-All';
|
||||
} elseif ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.3'][$index] == 3) {
|
||||
@ -102,8 +101,8 @@ if ($device['os_group'] == 'cisco') {
|
||||
if ($value == $result['sp-obj']) {
|
||||
// We have our child, import the match
|
||||
if ($tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.3'][$spid][$id] == 3) {
|
||||
$result['match'] = $result['map-type'].": ".$tblcbQosMatchStmtCfg['1.3.6.1.4.1.9.9.166.1.8.1.1.1'][$tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.2'][$spid][$id]];
|
||||
d_echo(" Match: ".$result['match']."\n");
|
||||
$result['match'] = $result['map-type'] . ": " . $tblcbQosMatchStmtCfg['1.3.6.1.4.1.9.9.166.1.8.1.1.1'][$tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.2'][$spid][$id]];
|
||||
d_echo(" Match: " . $result['match'] . "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,7 +131,7 @@ if ($device['os_group'] == 'cisco') {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$component_key) {
|
||||
if (! $component_key) {
|
||||
// The component doesn't exist, we need to ADD it - ADD.
|
||||
$new_component = $component->createComponent($device['device_id'], $module);
|
||||
$component_key = key($new_component);
|
||||
|
@ -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)) {
|
||||
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';
|
||||
@ -17,16 +17,16 @@ if (is_array($cefs)) {
|
||||
}
|
||||
|
||||
foreach ($cefs as $entity => $afis) {
|
||||
$entity_name = $entity_array[$entity]['entPhysicalName'].' - '.$entity_array[$entity]['entPhysicalModelName'];
|
||||
$entity_name = $entity_array[$entity]['entPhysicalName'] . ' - ' . $entity_array[$entity]['entPhysicalModelName'];
|
||||
echo "\n$entity $entity_name\n";
|
||||
foreach ($afis as $afi => $paths) {
|
||||
echo " |- $afi\n";
|
||||
foreach ($paths as $path => $path_name) {
|
||||
echo ' | |-'.$path.': '.$path_name['cefSwitchingPath']."\n";
|
||||
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 '+';
|
||||
}
|
||||
}
|
||||
|
@ -4,24 +4,24 @@ 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 = 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);
|
||||
[$oid] = explode(' ', $data);
|
||||
$oid = str_replace('.1.3.6.1.4.1.9.9.84.1.2.1.1.4.', '', $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));
|
||||
$ah_a = zeropad(dechex($a_a));
|
||||
$ah_b = zeropad(dechex($a_b));
|
||||
$ah_c = zeropad(dechex($a_c));
|
||||
$ah_d = zeropad(dechex($a_d));
|
||||
$ah_e = zeropad(dechex($a_e));
|
||||
$ah_f = zeropad(dechex($a_f));
|
||||
$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));
|
||||
$ah_d = zeropad(dechex($a_d));
|
||||
$ah_e = zeropad(dechex($a_e));
|
||||
$ah_f = zeropad(dechex($a_f));
|
||||
$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 '+';
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
@ -84,8 +84,8 @@ if ($device['os_group'] == 'cisco') {
|
||||
// No Error, lets process things.
|
||||
|
||||
// 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();
|
||||
foreach ((array) $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.2'] as $index => $name) {
|
||||
$result = [];
|
||||
$message = false;
|
||||
$result['index'] = $index;
|
||||
$result['label'] = $name;
|
||||
@ -95,18 +95,18 @@ if ($device['os_group'] == 'cisco') {
|
||||
$result['transport'] = 'Unicast';
|
||||
}
|
||||
$result['otvtype'] = 'overlay';
|
||||
$result['UID'] = $result['otvtype']."-".$result['index'];
|
||||
$result['UID'] = $result['otvtype'] . "-" . $result['index'];
|
||||
$result['vpn_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.3'][$index];
|
||||
if ($result['vpn_state'] != 2) {
|
||||
$message .= "VPN Down: ".$error_vpn[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.4'][$index]]."\n";
|
||||
$message .= "VPN Down: " . $error_vpn[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.4'][$index]] . "\n";
|
||||
}
|
||||
$result['aed_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.13'][$index];
|
||||
if ($result['aed_state'] == 2) {
|
||||
$message .= "AED Down: ".$error_aed[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.14'][$index]]."\n";
|
||||
$message .= "AED Down: " . $error_aed[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.14'][$index]] . "\n";
|
||||
}
|
||||
$result['overlay_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.23'][$index];
|
||||
if ($result['overlay_state'] == 2) {
|
||||
$message .= "Overlay Down: ".$error_overlay[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.24'][$index]]."\n";
|
||||
$message .= "Overlay Down: " . $error_overlay[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.24'][$index]] . "\n";
|
||||
}
|
||||
|
||||
// If we have set a message, we have an error, activate alert.
|
||||
@ -119,13 +119,13 @@ if ($device['os_group'] == 'cisco') {
|
||||
}
|
||||
|
||||
// Let's log some debugging
|
||||
d_echo("\n\nOverlay: ".$result['label']."\n");
|
||||
d_echo(" Index: ".$result['index']."\n");
|
||||
d_echo(" UID: ".$result['UID']."\n");
|
||||
d_echo(" Transport: ".$result['transport']."\n");
|
||||
d_echo(" Type: ".$result['otvtype']."\n");
|
||||
d_echo(" Status: ".$result['status']."\n");
|
||||
d_echo(" Message: ".$result['error']."\n");
|
||||
d_echo("\n\nOverlay: " . $result['label'] . "\n");
|
||||
d_echo(" Index: " . $result['index'] . "\n");
|
||||
d_echo(" UID: " . $result['UID'] . "\n");
|
||||
d_echo(" Transport: " . $result['transport'] . "\n");
|
||||
d_echo(" Type: " . $result['otvtype'] . "\n");
|
||||
d_echo(" Status: " . $result['status'] . "\n");
|
||||
d_echo(" Message: " . $result['error'] . "\n");
|
||||
|
||||
// Add the result to the parent array.
|
||||
$tblOTV[] = $result;
|
||||
@ -133,17 +133,17 @@ if ($device['os_group'] == 'cisco') {
|
||||
|
||||
// Add each adjacency to the array.
|
||||
if ($tblAdjacentDevName) {
|
||||
foreach ((array)$tblAdjacentDevName as $key => $value) {
|
||||
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;
|
||||
$result['otvtype'] = 'adjacency';
|
||||
$result['UID'] = $result['otvtype']."-".$result['index']."-".str_replace(' ', '', $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.3.'.$result['index'].'.1.4.'.$result['endpoint']]);
|
||||
$result['uptime'] = $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.'.$result['index'].'.1.4.'.$result['endpoint']];
|
||||
$result['UID'] = $result['otvtype'] . "-" . $result['index'] . "-" . str_replace(' ', '', $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.3.' . $result['index'] . '.1.4.' . $result['endpoint']]);
|
||||
$result['uptime'] = $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.' . $result['index'] . '.1.4.' . $result['endpoint']];
|
||||
$message = false;
|
||||
if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.5.'.$result['index'].'.1.4.'.$result['endpoint']] != 1) {
|
||||
if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.5.' . $result['index'] . '.1.4.' . $result['endpoint']] != 1) {
|
||||
$message .= "Adjacency is Down\n";
|
||||
}
|
||||
|
||||
@ -157,21 +157,21 @@ if ($device['os_group'] == 'cisco') {
|
||||
}
|
||||
|
||||
// Set a default name, if for some unknown reason we cant find the parent VPN.
|
||||
$result['label'] = "Unknown (".$result['index'].") - ".$value;
|
||||
$result['label'] = "Unknown (" . $result['index'] . ") - " . $value;
|
||||
// We need to search the existing array to build the name
|
||||
foreach ($tblOTV as $item) {
|
||||
if (($item['otvtype'] == 'overlay') && ($item['index'] == $result['index'])) {
|
||||
$result['label'] = $item['label']." - ".$value;
|
||||
$result['label'] = $item['label'] . " - " . $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Let's log some debugging
|
||||
d_echo("\n\nAdjacency: ".$result['label']."\n");
|
||||
d_echo(" Endpoint: ".$result['endpoint']."\n");
|
||||
d_echo(" Index: ".$result['index']."\n");
|
||||
d_echo(" UID: ".$result['UID']."\n");
|
||||
d_echo(" Status: ".$result['status']."\n");
|
||||
d_echo(" Message: ".$result['error']."\n");
|
||||
d_echo("\n\nAdjacency: " . $result['label'] . "\n");
|
||||
d_echo(" Endpoint: " . $result['endpoint'] . "\n");
|
||||
d_echo(" Index: " . $result['index'] . "\n");
|
||||
d_echo(" UID: " . $result['UID'] . "\n");
|
||||
d_echo(" Status: " . $result['status'] . "\n");
|
||||
d_echo(" Message: " . $result['error'] . "\n");
|
||||
|
||||
// Add the result to the parent array.
|
||||
$tblOTV[] = $result;
|
||||
@ -180,15 +180,15 @@ if ($device['os_group'] == 'cisco') {
|
||||
|
||||
// We retain a list of all endpoints to tie the RRD to.
|
||||
foreach ($tblEndpoints as $k => $v) {
|
||||
$result['label'] = "Endpoint: ".$k;
|
||||
$result['label'] = "Endpoint: " . $k;
|
||||
$result['otvtype'] = 'endpoint';
|
||||
$result['endpoint'] = $k;
|
||||
$result['UID'] = $result['otvtype']."-".$k;
|
||||
$result['UID'] = $result['otvtype'] . "-" . $k;
|
||||
|
||||
// Let's log some debugging
|
||||
d_echo("\n\nEndpoint: ".$result['label']."\n");
|
||||
d_echo(" UID: ".$result['UID']."\n");
|
||||
d_echo(" Type: ".$result['otvtype']."\n");
|
||||
d_echo("\n\nEndpoint: " . $result['label'] . "\n");
|
||||
d_echo(" UID: " . $result['UID'] . "\n");
|
||||
d_echo(" Type: " . $result['otvtype'] . "\n");
|
||||
|
||||
// Add the result to the parent array.
|
||||
$tblOTV[] = $result;
|
||||
@ -204,13 +204,13 @@ if ($device['os_group'] == 'cisco') {
|
||||
$component_key = false;
|
||||
|
||||
// Loop over our components to determine if the component exists, or we need to add it.
|
||||
foreach ((array)$components as $compid => $child) {
|
||||
foreach ((array) $components as $compid => $child) {
|
||||
if ($child['UID'] === $array['UID']) {
|
||||
$component_key = $compid;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$component_key) {
|
||||
if (! $component_key) {
|
||||
// The component doesn't exist, we need to ADD it - ADD.
|
||||
$new_component = $component->createComponent($device['device_id'], $module);
|
||||
$component_key = key($new_component);
|
||||
@ -226,7 +226,7 @@ if ($device['os_group'] == 'cisco') {
|
||||
/*
|
||||
* Loop over the Component data to see if we need to DELETE any components.
|
||||
*/
|
||||
foreach ((array)$components as $key => $array) {
|
||||
foreach ((array) $components as $key => $array) {
|
||||
// Guilty until proven innocent
|
||||
$found = false;
|
||||
|
||||
|
@ -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']));
|
||||
if (!empty($pws_db[$pw['cpwVcID']])) {
|
||||
[$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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
@ -91,7 +90,7 @@ if ($device['os_group'] == 'cisco') {
|
||||
* If $component_id is false QFP Component doesn't exist
|
||||
* Create new component and add it to $components array
|
||||
*/
|
||||
if (!$component_id) {
|
||||
if (! $component_id) {
|
||||
$new_component = $component->createComponent($device['device_id'], $module);
|
||||
$component_id = key($new_component);
|
||||
$components[$component_id] = array_merge($new_component[$component_id], $component_data);
|
||||
@ -108,7 +107,7 @@ if ($device['os_group'] == 'cisco') {
|
||||
*/
|
||||
foreach ($components as $tmp_component_id => $tmp_component) {
|
||||
$found = in_array($tmp_component['entPhysicalIndex'], array_keys($qfp_general_data));
|
||||
if (!$found) {
|
||||
if (! $found) {
|
||||
$component->deleteComponent($tmp_component_id);
|
||||
echo '-';
|
||||
}
|
||||
|
@ -6,51 +6,51 @@ 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) {
|
||||
$key_val[] = '';
|
||||
}
|
||||
|
||||
$key = $key_val[0];
|
||||
$key = $key_val[0];
|
||||
$value = $key_val[1];
|
||||
|
||||
$prop_id = explode('.', $key);
|
||||
if ((count($prop_id) != 2) || !ctype_digit($prop_id[1])) {
|
||||
if ((count($prop_id) != 2) || ! ctype_digit($prop_id[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$property = $prop_id[0];
|
||||
$id = intval($prop_id[1]);
|
||||
$id = intval($prop_id[1]);
|
||||
|
||||
$sla_table[$id][$property] = trim($value);
|
||||
}
|
||||
|
||||
// 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(
|
||||
'device_id' => $device['device_id'],
|
||||
'sla_nr' => $sla_nr,
|
||||
);
|
||||
$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(
|
||||
'device_id' => $device['device_id'],
|
||||
'sla_nr' => $sla_nr,
|
||||
'owner' => $sla_config['rttMonCtrlAdminOwner'],
|
||||
'tag' => $sla_config['rttMonCtrlAdminTag'],
|
||||
'rtt_type' => $sla_config['rttMonCtrlAdminRttType'],
|
||||
'status' => ($sla_config['rttMonCtrlAdminStatus'] == 'active') ? 1 : 0,
|
||||
'opstatus' => ($sla_config['rttMonLatestRttOperSense'] == 'ok') ? 0 : 2,
|
||||
'deleted' => 0,
|
||||
);
|
||||
$data = [
|
||||
'device_id' => $device['device_id'],
|
||||
'sla_nr' => $sla_nr,
|
||||
'owner' => $sla_config['rttMonCtrlAdminOwner'],
|
||||
'tag' => $sla_config['rttMonCtrlAdminTag'],
|
||||
'rtt_type' => $sla_config['rttMonCtrlAdminRttType'],
|
||||
'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']) {
|
||||
if (! $data['tag']) {
|
||||
switch ($data['rtt_type']) {
|
||||
case 'http':
|
||||
$data['tag'] = $sla_config['rttMonEchoAdminURL'];
|
||||
@ -75,12 +75,12 @@ if (Config::get('enable_sla') && $device['os_group'] == 'cisco') {
|
||||
}//end switch
|
||||
}//end if
|
||||
|
||||
if (!$sla_id) {
|
||||
if (! $sla_id) {
|
||||
$sla_id = dbInsert($data, 'slas');
|
||||
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 '.';
|
||||
|
@ -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') {
|
||||
@ -39,7 +38,7 @@ if (Config::get('enable_vrf_lite_cisco')) {
|
||||
foreach (explode("\n", $listVrf) as $lineVrf) {
|
||||
$tmpVrf = explode(" ", $lineVrf, 2);
|
||||
//the $tmpVrf[0] will be the context
|
||||
if (count($tmpVrf) == 2 && !empty($tmpVrf[1])) {
|
||||
if (count($tmpVrf) == 2 && ! empty($tmpVrf[1])) {
|
||||
$tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1];
|
||||
}
|
||||
}
|
||||
@ -56,42 +55,42 @@ if (Config::get('enable_vrf_lite_cisco')) {
|
||||
foreach (explode("\n", $listIntance) as $lineIntance) {
|
||||
$tmpIntance = explode(" ", $lineIntance, 2);
|
||||
//the $tmpIntance[0] will be the context and $tmpIntance[1] the intance
|
||||
if (count($tmpIntance) == 2 && !empty($tmpIntance[1])) {
|
||||
if (count($tmpIntance) == 2 && ! empty($tmpIntance[1])) {
|
||||
$tableVrf[$tmpIntance[0]]['intance_name'] = $tmpIntance[1];
|
||||
}
|
||||
}
|
||||
unset($listIntance);
|
||||
|
||||
foreach ((array)$tableVrf as $context => $vrf) {
|
||||
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
|
||||
));
|
||||
if (!empty($tmpVrf)) {
|
||||
$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) {
|
||||
$vrfUpdate[$key]=$value;
|
||||
if ($vrf[$key] != $value) {
|
||||
$vrfUpdate[$key] = $value;
|
||||
}
|
||||
}
|
||||
if (!empty($vrfUpdate)) {
|
||||
dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array(
|
||||
$tmp['vrf_lite_cisco_id']
|
||||
));
|
||||
if (! empty($vrfUpdate)) {
|
||||
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,17 +98,17 @@ 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
|
||||
foreach ($tmpVrfC as $vrfC) {
|
||||
unset($ids[$vrfC['vrf_lite_cisco_id']]);
|
||||
}
|
||||
if (!empty($ids)) {
|
||||
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);
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
// LibreNMS module to do device discovery by ARP table contents.
|
||||
//
|
||||
@ -34,14 +35,14 @@ $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) {
|
||||
$ip = $entry['ipv4_address'];
|
||||
$mac = $entry['mac_address'];
|
||||
$if = $entry['port_id'];
|
||||
$int = cleanPort($if);
|
||||
foreach (dbFetchRows($sql, [$deviceid]) as $entry) {
|
||||
$ip = $entry['ipv4_address'];
|
||||
$mac = $entry['mac_address'];
|
||||
$if = $entry['port_id'];
|
||||
$int = cleanPort($if);
|
||||
$label = $int['label'];
|
||||
|
||||
// Even though match_network is done inside discover_new_device, we do it here
|
||||
@ -51,7 +52,7 @@ foreach (dbFetchRows($sql, array($deviceid)) as $entry) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!match_network(Config::get('nets'), $ip)) {
|
||||
if (! match_network(Config::get('nets'), $ip)) {
|
||||
echo 'i';
|
||||
log_event("Ignored $ip", $deviceid, 'interface', 3, $if);
|
||||
continue;
|
||||
@ -67,7 +68,7 @@ foreach (dbFetchRows($sql, array($deviceid)) as $entry) {
|
||||
|
||||
$name = gethostbyaddr($ip);
|
||||
echo '+';
|
||||
$names[] = $name;
|
||||
$names[] = $name;
|
||||
$ips[$name] = $ip;
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ if ($device['os'] == 'ironware') {
|
||||
foreach ($fdp_if_array as $entry_key => $fdp) {
|
||||
$remote_device_id = find_device_id($fdp['snFdpCacheDeviceId']);
|
||||
|
||||
if (!$remote_device_id &&
|
||||
!can_skip_discovery($fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheVersion'])
|
||||
if (! $remote_device_id &&
|
||||
! can_skip_discovery($fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheVersion'])
|
||||
) {
|
||||
if (Config::get('autodiscovery.xdp') === true) {
|
||||
$remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId'], $device, 'FDP', $interface);
|
||||
@ -53,13 +53,13 @@ foreach ($cdp_array as $key => $cdp_if_array) {
|
||||
$cdp_ip = IP::fromHexString($cdp['cdpCacheAddress'], true);
|
||||
$remote_device_id = find_device_id($cdp['cdpCacheDeviceId'], $cdp_ip);
|
||||
|
||||
if (!$remote_device_id &&
|
||||
!can_skip_discovery($cdp['cdpCacheDeviceId'], $cdp['cdpCacheVersion'], $cdp['cdpCachePlatform'] &&
|
||||
if (! $remote_device_id &&
|
||||
! can_skip_discovery($cdp['cdpCacheDeviceId'], $cdp['cdpCacheVersion'], $cdp['cdpCachePlatform'] &&
|
||||
Config::get('autodiscovery.xdp') === true)
|
||||
) {
|
||||
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface);
|
||||
|
||||
if (!$remote_device_id && Config::get('discovery_by_ip', false)) {
|
||||
if (! $remote_device_id && Config::get('discovery_by_ip', false)) {
|
||||
$remote_device_id = discover_new_device($cdp_ip, $device, 'CDP', $interface);
|
||||
}
|
||||
}
|
||||
@ -84,25 +84,24 @@ echo PHP_EOL;
|
||||
|
||||
if (($device['os'] == 'routeros')) {
|
||||
echo ' LLDP-MIB: ';
|
||||
$lldp_array = snmpwalk_group($device, 'lldpRemEntry', 'LLDP-MIB', 3);
|
||||
if (!empty($lldp_array)) {
|
||||
$lldp_array = snmpwalk_group($device, 'lldpRemEntry', 'LLDP-MIB', 3);
|
||||
if (! empty($lldp_array)) {
|
||||
$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);
|
||||
|
||||
if (!$remote_device_id &&
|
||||
if (! $remote_device_id &&
|
||||
is_valid_hostname($lldp['lldpRemSysName']) &&
|
||||
!can_skip_discovery($lldp['lldpRemSysName'], $lldp['lldpRemSysDesc']) &&
|
||||
! can_skip_discovery($lldp['lldpRemSysName'], $lldp['lldpRemSysDesc']) &&
|
||||
Config::get('autodiscovery.xdp') === true) {
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
||||
}
|
||||
@ -126,16 +125,16 @@ if (($device['os'] == 'routeros')) {
|
||||
echo PHP_EOL;
|
||||
} elseif (($device['os'] == 'pbn' || $device['os'] == 'bdcom')) {
|
||||
echo ' NMS-LLDP-MIB: ';
|
||||
$lldp_array = snmpwalk_group($device, 'lldpRemoteSystemsData', 'NMS-LLDP-MIB');
|
||||
$lldp_array = snmpwalk_group($device, 'lldpRemoteSystemsData', 'NMS-LLDP-MIB');
|
||||
|
||||
foreach ($lldp_array as $key => $lldp) {
|
||||
d_echo($lldp);
|
||||
$interface = get_port_by_ifIndex($device['device_id'], $lldp['lldpRemLocalPortNum']);
|
||||
$remote_device_id = find_device_id($lldp['lldpRemSysName']);
|
||||
|
||||
if (!$remote_device_id &&
|
||||
if (! $remote_device_id &&
|
||||
is_valid_hostname($lldp['lldpRemSysName']) &&
|
||||
!can_skip_discovery($lldp['lldpRemSysName'], $lldp['lldpRemSysDesc'] &&
|
||||
! can_skip_discovery($lldp['lldpRemSysName'], $lldp['lldpRemSysDesc'] &&
|
||||
Config::get('autodiscovery.xdp') === true)
|
||||
) {
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
||||
@ -159,7 +158,7 @@ if (($device['os'] == 'routeros')) {
|
||||
echo PHP_EOL;
|
||||
} elseif (($device['os'] == 'timos')) {
|
||||
echo ' TIMETRA-LLDP-MIB: ';
|
||||
$lldp_array = snmpwalk_group($device, 'tmnxLldpRemoteSystemsData', 'TIMETRA-LLDP-MIB');
|
||||
$lldp_array = snmpwalk_group($device, 'tmnxLldpRemoteSystemsData', 'TIMETRA-LLDP-MIB');
|
||||
foreach ($lldp_array as $key => $lldp) {
|
||||
$ifIndex = key($lldp['tmnxLldpRemPortId']);
|
||||
$MacIndex = key($lldp['tmnxLldpRemPortId'][$ifIndex]);
|
||||
@ -167,9 +166,9 @@ if (($device['os'] == 'routeros')) {
|
||||
$interface = get_port_by_ifIndex($device['device_id'], $ifIndex);
|
||||
$remote_device_id = find_device_id($lldp['tmnxLldpRemSysName'][$ifIndex][$MacIndex][$RemIndex]);
|
||||
|
||||
if (!$remote_device_id &&
|
||||
if (! $remote_device_id &&
|
||||
is_valid_hostname($lldp['tmnxLldpRemSysName'][$ifIndex][$MacIndex][$RemIndex]) &&
|
||||
!can_skip_discovery($lldp['tmnxLldpRemSysName'][$ifIndex][$MacIndex][$RemIndex], $lldp['tmnxLldpRemSysDesc'][$ifIndex][$MacIndex][$RemIndex]) &&
|
||||
! can_skip_discovery($lldp['tmnxLldpRemSysName'][$ifIndex][$MacIndex][$RemIndex], $lldp['tmnxLldpRemSysDesc'][$ifIndex][$MacIndex][$RemIndex]) &&
|
||||
Config::get('autodiscovery.xdp') === true
|
||||
) {
|
||||
$remote_device_id = discover_new_device($lldp['tmnxLldpRemSysName'][$ifIndex][$MacIndex][$RemIndex], $device, 'LLDP', $interface);
|
||||
@ -194,7 +193,7 @@ if (($device['os'] == 'routeros')) {
|
||||
} else {
|
||||
echo ' LLDP-MIB: ';
|
||||
$lldp_array = snmpwalk_group($device, 'lldpRemTable', 'LLDP-MIB', 3);
|
||||
if (!empty($lldp_array)) {
|
||||
if (! empty($lldp_array)) {
|
||||
$lldp_remAddr_num = snmpwalk_cache_multi_oid($device, '.1.0.8802.1.1.2.1.4.2.1.3', [], 'LLDP-MIB', null, '-OQun');
|
||||
foreach ($lldp_remAddr_num as $key => $value) {
|
||||
$res = preg_match("/1\.0\.8802\.1\.1\.2\.1\.4\.2\.1\.3\.([^\.]*)\.([^\.]*)\.([^\.]*)\.([^\.]*)\.([^\.]*).(([^\.]*)(\.([^\.]*))+)/", $key, $matches);
|
||||
@ -239,17 +238,17 @@ 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);
|
||||
|
||||
// add device if configured to do so
|
||||
if (!$remote_device_id && !can_skip_discovery($lldp['lldpRemSysName'], $lldp['lldpRemSysDesc']) &&
|
||||
if (! $remote_device_id && ! can_skip_discovery($lldp['lldpRemSysName'], $lldp['lldpRemSysDesc']) &&
|
||||
Config::get('autodiscovery.xdp') === true) {
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
||||
|
||||
if (!$remote_device_id && Config::get('discovery_by_ip', false)) {
|
||||
if (! $remote_device_id && Config::get('discovery_by_ip', false)) {
|
||||
$ptopo_array = snmpwalk_group($device, 'ptopoConnEntry', 'PTOPO-MIB');
|
||||
d_echo($ptopo_array);
|
||||
foreach ($ptopo_array as $ptopo) {
|
||||
@ -259,7 +258,7 @@ if (($device['os'] == 'routeros')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$remote_device_id && isset($lldp['lldpRemManAddr'])) {
|
||||
if (! $remote_device_id && isset($lldp['lldpRemManAddr'])) {
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemManAddr'], $device, 'LLDP', $interface);
|
||||
}
|
||||
unset($ptopo_array);
|
||||
@ -274,13 +273,13 @@ if (($device['os'] == 'routeros')) {
|
||||
if ($remote_device['os'] == 'xos') {
|
||||
$slot_port = explode(':', $lldp['lldpRemPortId']);
|
||||
if (sizeof($slot_port) == 2) {
|
||||
$n_slot = (int)$slot_port[0];
|
||||
$n_port = (int)$slot_port[1];
|
||||
$n_slot = (int) $slot_port[0];
|
||||
$n_port = (int) $slot_port[1];
|
||||
} else {
|
||||
$n_slot = 1;
|
||||
$n_port = (int)$slot_port[0];
|
||||
$n_port = (int) $slot_port[0];
|
||||
}
|
||||
$lldp['lldpRemPortId'] = (string)($n_slot * 1000 + $n_port);
|
||||
$lldp['lldpRemPortId'] = (string) ($n_slot * 1000 + $n_port);
|
||||
}
|
||||
|
||||
$remote_port_id = find_port_id(
|
||||
@ -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']);
|
||||
|
||||
@ -329,7 +328,7 @@ if (Config::get('autodiscovery.ospf') === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$ip->inNetworks(Config::get('nets'))) {
|
||||
if (! $ip->inNetworks(Config::get('nets'))) {
|
||||
echo 'i';
|
||||
continue;
|
||||
}
|
||||
@ -346,21 +345,21 @@ 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) {
|
||||
$local_port_id = $test['local_port_id'];
|
||||
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'];
|
||||
$remote_port = $test['remote_port'];
|
||||
d_echo("$local_port_id -> $remote_hostname -> $remote_port \n");
|
||||
|
||||
if (!$link_exists[$local_port_id][$remote_hostname][$remote_port]) {
|
||||
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");
|
||||
|
||||
|
@ -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]) {
|
||||
if (! $valid[$id]) {
|
||||
echo '-';
|
||||
dbDelete('entPhysical', 'entPhysical_id = ?', array ($test['entPhysical_id']));
|
||||
dbDelete('entPhysical', 'entPhysical_id = ?', [$test['entPhysical_id']]);
|
||||
}
|
||||
}
|
||||
unset(
|
||||
|
@ -212,7 +212,7 @@ foreach ($cienaCesChassisFanTrayEntry as $index => $contents) {
|
||||
default:
|
||||
$modeString = "";
|
||||
}
|
||||
|
||||
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => "53$index",
|
||||
'entPhysicalClass' => 'sensor',
|
||||
@ -232,7 +232,7 @@ foreach ($cienaCesChassisFanEntry as $index => $contents) {
|
||||
$indexArr = explode(".", $index);
|
||||
$fanTray = $indexArr[0];
|
||||
$fanIndex = $indexArr[1];
|
||||
|
||||
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => "51$fanIndex",
|
||||
'entPhysicalClass' => 'sensor',
|
||||
@ -250,7 +250,7 @@ foreach ($cienaCesChassisFanTempEntry as $index => $contents) {
|
||||
$indexArr = explode(".", $index);
|
||||
$fanTray = $indexArr[0];
|
||||
$sensorIndex = $indexArr[1];
|
||||
|
||||
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => "52$sensorIndex",
|
||||
'entPhysicalClass' => 'sensor',
|
||||
@ -268,7 +268,7 @@ foreach ($module_array as $index => $contents) {
|
||||
$chassisIndex = $indexArr[0];
|
||||
$shelfIndex = $indexArr[1];
|
||||
$slotIndex = $indexArr[2];
|
||||
|
||||
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => "55$slotIndex",
|
||||
'entPhysicalDescr' => $contents['cienaCesModuleDescription'] . ", " . $contents['cienaCesModuleSwRunningRelease'],
|
||||
@ -325,23 +325,23 @@ foreach ($entity_array as $entPhysicalIndex => $entry) {
|
||||
discover_entity_physical(
|
||||
$valid,
|
||||
$device,
|
||||
array_key_exists('entPhysicalIndex', $entry) ? $entry['entPhysicalIndex'] : '',
|
||||
array_key_exists('entPhysicalDescr', $entry) ? $entry['entPhysicalDescr'] : '',
|
||||
array_key_exists('entPhysicalClass', $entry) ? $entry['entPhysicalClass'] : '',
|
||||
array_key_exists('entPhysicalName', $entry) ? $entry['entPhysicalName'] : '',
|
||||
array_key_exists('entPhysicalModelName', $entry) ? $entry['entPhysicalModelName'] : '',
|
||||
array_key_exists('entPhysicalSerialNum', $entry) ? $entry['entPhysicalSerialNum'] : '',
|
||||
array_key_exists('entPhysicalContainedIn', $entry) ? $entry['entPhysicalContainedIn'] : '',
|
||||
array_key_exists('entPhysicalMfgName', $entry) ? $entry['entPhysicalMfgName'] : '',
|
||||
array_key_exists('entPhysicalIndex', $entry) ? $entry['entPhysicalIndex'] : '',
|
||||
array_key_exists('entPhysicalDescr', $entry) ? $entry['entPhysicalDescr'] : '',
|
||||
array_key_exists('entPhysicalClass', $entry) ? $entry['entPhysicalClass'] : '',
|
||||
array_key_exists('entPhysicalName', $entry) ? $entry['entPhysicalName'] : '',
|
||||
array_key_exists('entPhysicalModelName', $entry) ? $entry['entPhysicalModelName'] : '',
|
||||
array_key_exists('entPhysicalSerialNum', $entry) ? $entry['entPhysicalSerialNum'] : '',
|
||||
array_key_exists('entPhysicalContainedIn', $entry) ? $entry['entPhysicalContainedIn'] : '',
|
||||
array_key_exists('entPhysicalMfgName', $entry) ? $entry['entPhysicalMfgName'] : '',
|
||||
array_key_exists('entPhysicalParentRelPos', $entry) ? $entry['entPhysicalParentRelPos'] : '',
|
||||
array_key_exists('entPhysicalVendorType', $entry) ? $entry['entPhysicalVendorType'] : '',
|
||||
array_key_exists('entPhysicalHardwareRev', $entry) ? $entry['entPhysicalHardwareRev'] : '',
|
||||
array_key_exists('entPhysicalFirmwareRev', $entry) ? $entry['entPhysicalFirmwareRev'] : '',
|
||||
array_key_exists('entPhysicalSoftwareRev', $entry) ? $entry['entPhysicalSoftwareRev'] : '',
|
||||
array_key_exists('entPhysicalIsFRU', $entry) ? $entry['entPhysicalIsFRU'] : '',
|
||||
array_key_exists('entPhysicalAlias', $entry) ? $entry['entPhysicalAlias'] : '',
|
||||
array_key_exists('entPhysicalAssetID', $entry) ? $entry['entPhysicalAssetID'] : '',
|
||||
array_key_exists('ifIndex', $entry) ? $entry['ifIndex'] : ''
|
||||
array_key_exists('entPhysicalVendorType', $entry) ? $entry['entPhysicalVendorType'] : '',
|
||||
array_key_exists('entPhysicalHardwareRev', $entry) ? $entry['entPhysicalHardwareRev'] : '',
|
||||
array_key_exists('entPhysicalFirmwareRev', $entry) ? $entry['entPhysicalFirmwareRev'] : '',
|
||||
array_key_exists('entPhysicalSoftwareRev', $entry) ? $entry['entPhysicalSoftwareRev'] : '',
|
||||
array_key_exists('entPhysicalIsFRU', $entry) ? $entry['entPhysicalIsFRU'] : '',
|
||||
array_key_exists('entPhysicalAlias', $entry) ? $entry['entPhysicalAlias'] : '',
|
||||
array_key_exists('entPhysicalAssetID', $entry) ? $entry['entPhysicalAssetID'] : '',
|
||||
array_key_exists('ifIndex', $entry) ? $entry['ifIndex'] : ''
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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,10 +48,10 @@ 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];
|
||||
$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];
|
||||
}
|
||||
|
||||
// Unset the faults and stats array so it isn't reported as an error later.
|
||||
@ -71,30 +71,30 @@ 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];
|
||||
$result['serial'] = $array[47][$key];
|
||||
$result['string'] = $array[32][$key] ." - ". ($array[49][$key]/1024) ."G Mem, ". $array[36][$key] ." CPU, ". $array[35][$key] ." core";
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.9.35.1.43.'.$key;
|
||||
$result['string'] = $array[32][$key] . " - " . ($array[49][$key] / 1024) . "G Mem, " . $array[36][$key] . " CPU, " . $array[35][$key] . " core";
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.9.35.1.43.' . $key;
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[43][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[43][$key]."\n";
|
||||
$result['error'] = "Error Operability Code: " . $array[43][$key] . "\n";
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -106,7 +106,7 @@ if (is_null($tblUCSObjects)) {
|
||||
if (strpos($id, $result['label']) !== false) {
|
||||
// The fault is on this chassis.
|
||||
$result['status'] = 2;
|
||||
$result['error'] .= $value."\n";
|
||||
$result['error'] .= $value . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,11 +116,11 @@ 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.
|
||||
d_echo("Chassis (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("Chassis (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -128,19 +128,19 @@ 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];
|
||||
$result['serial'] = $array[14][$key];
|
||||
$result['string'] = $array[6][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.9.6.1.9.'.$key;
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.9.6.1.9.' . $key;
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[9][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[9][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[9][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -152,11 +152,11 @@ 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.
|
||||
d_echo("System Board (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("System Board (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -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;
|
||||
@ -174,14 +174,14 @@ if (is_null($tblUCSObjects)) {
|
||||
$result['id'] = substr($array[3][$key], 4);
|
||||
$result['label'] = $array[2][$key];
|
||||
$result['serial'] = $array[19][$key];
|
||||
$result['string'] = $array[11][$key] ." - ". ($array[6][$key]/1024) ."G, ". $array[27][$key] ." Bit, ". $array[7][$key] ." Mhz, ". $array[21][$key] ." MT/s";
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.30.11.1.14.'.$key;
|
||||
$result['string'] = $array[11][$key] . " - " . ($array[6][$key] / 1024) . "G, " . $array[27][$key] . " Bit, " . $array[7][$key] . " Mhz, " . $array[21][$key] . " MT/s";
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.30.11.1.14.' . $key;
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[14][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[14][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[14][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -194,11 +194,11 @@ 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.
|
||||
d_echo("Memory (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("Memory (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -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;
|
||||
@ -216,14 +216,14 @@ if (is_null($tblUCSObjects)) {
|
||||
$result['id'] = substr($array[3][$key], 4);
|
||||
$result['label'] = $array[2][$key];
|
||||
$result['serial'] = $array[15][$key];
|
||||
$result['string'] = $array[8][$key] ." - ". $array[5][$key] ." Cores, ". $array[20][$key] ." Threads";
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.41.9.1.10.'.$key;
|
||||
$result['string'] = $array[8][$key] . " - " . $array[5][$key] . " Cores, " . $array[20][$key] . " Threads";
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.41.9.1.10.' . $key;
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[10][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[10][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[10][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -236,11 +236,11 @@ 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.
|
||||
d_echo("CPU (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("CPU (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -248,19 +248,19 @@ 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];
|
||||
$result['serial'] = $array[14][$key];
|
||||
$result['string'] = $array[5][$key] ." - Rev: ". $array[13][$key] .", ". $array[9][$key] .", RAID Types: ". $array[19][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.1.1.7.'.$key;
|
||||
$result['string'] = $array[5][$key] . " - Rev: " . $array[13][$key] . ", " . $array[9][$key] . ", RAID Types: " . $array[19][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.1.1.7.' . $key;
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[7][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[7][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[7][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -273,11 +273,11 @@ 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.
|
||||
d_echo("SAS Module (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("SAS Module (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -285,30 +285,30 @@ 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];
|
||||
$result['serial'] = $array[12][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.4.1.9.'.$key;
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.4.1.9.' . $key;
|
||||
|
||||
// Old Firmware returns 4294967296 as 1 MB.
|
||||
// The if below assumes we will never have < 1 Gb on old firmware or > 4 Pb on new firmware
|
||||
if (($array[13][$key]) > 4294967296000) {
|
||||
// Old Firmware
|
||||
$result['string'] = $array[14][$key] ." ". $array[7][$key] .", Rev: ". $array[11][$key] .", Size: ". round($array[13][$key]/4294967296000, 2) ." GB";
|
||||
d_echo("Disk: ".$array[2][$key].", Raw Size: ".$array[13][$key].", converted (old FW): ".round($array[13][$key]/4294967296000, 2)."GB\n");
|
||||
$result['string'] = $array[14][$key] . " " . $array[7][$key] . ", Rev: " . $array[11][$key] . ", Size: " . round($array[13][$key] / 4294967296000, 2) . " GB";
|
||||
d_echo("Disk: " . $array[2][$key] . ", Raw Size: " . $array[13][$key] . ", converted (old FW): " . round($array[13][$key] / 4294967296000, 2) . "GB\n");
|
||||
} else {
|
||||
// New Firmware
|
||||
$result['string'] = $array[14][$key] ." ". $array[7][$key] .", Rev: ". $array[11][$key] .", Size: ". round($array[13][$key]/1000, 2) ." GB";
|
||||
d_echo("Disk: ".$array[2][$key].", Raw Size: ".$array[13][$key].", converted (New FW): ".round($array[13][$key]/1000, 2)."GB\n");
|
||||
$result['string'] = $array[14][$key] . " " . $array[7][$key] . ", Rev: " . $array[11][$key] . ", Size: " . round($array[13][$key] / 1000, 2) . " GB";
|
||||
d_echo("Disk: " . $array[2][$key] . ", Raw Size: " . $array[13][$key] . ", converted (New FW): " . round($array[13][$key] / 1000, 2) . "GB\n");
|
||||
}
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[9][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[9][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[9][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -321,11 +321,11 @@ 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.
|
||||
d_echo("SAS Disk (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("SAS Disk (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -333,30 +333,30 @@ 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];
|
||||
$result['serial'] = 'N/A';
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.8.1.9.'.$key;
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.8.1.9.' . $key;
|
||||
|
||||
// Old Firmware returns 4294967296 as 1 MB.
|
||||
// The if below assumes we will never have < 1 Gb on old firmware or > 4 Pb on new firmware
|
||||
if (($array[13][$key]) > 4294967296000) {
|
||||
// Old Firmware
|
||||
$result['string'] = $array[3][$key] .", Size: ". round($array[13][$key]/4294967296000, 2) ." GB";
|
||||
d_echo("LUN: ".$array[2][$key].", Raw Size: ".$array[13][$key].", converted (Old FW): ".round($array[13][$key]/4294967296000, 2)."GB\n");
|
||||
$result['string'] = $array[3][$key] . ", Size: " . round($array[13][$key] / 4294967296000, 2) . " GB";
|
||||
d_echo("LUN: " . $array[2][$key] . ", Raw Size: " . $array[13][$key] . ", converted (Old FW): " . round($array[13][$key] / 4294967296000, 2) . "GB\n");
|
||||
} else {
|
||||
// New Firmware
|
||||
$result['string'] = $array[3][$key] .", Size: ". round($array[13][$key]/1000, 2) ." GB";
|
||||
d_echo("LUN: ".$array[2][$key].", Raw Size: ".$array[13][$key].", converted (New FW): ".round($array[13][$key]/1000, 2)."GB\n");
|
||||
$result['string'] = $array[3][$key] . ", Size: " . round($array[13][$key] / 1000, 2) . " GB";
|
||||
d_echo("LUN: " . $array[2][$key] . ", Raw Size: " . $array[13][$key] . ", converted (New FW): " . round($array[13][$key] / 1000, 2) . "GB\n");
|
||||
}
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[9][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[9][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[9][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -369,11 +369,11 @@ 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.
|
||||
d_echo("LUN (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("LUN (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -381,19 +381,19 @@ 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];
|
||||
$result['serial'] = 'N/A';
|
||||
$result['string'] = $array[3][$key] ." - ". $array[7][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.11.1.9.'.$key;
|
||||
$result['string'] = $array[3][$key] . " - " . $array[7][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.11.1.9.' . $key;
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[9][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[9][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[9][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -406,11 +406,11 @@ 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.
|
||||
d_echo("RAID Battery (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("RAID Battery (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -418,19 +418,19 @@ 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['id'] = $array[8][$key] . "-" . substr($array[3][$key], 4);
|
||||
$result['label'] = $array[2][$key];
|
||||
$result['serial'] = 'N/A';
|
||||
$result['string'] = $array[7][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.15.12.1.10.'.$key;
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.15.12.1.10.' . $key;
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[10][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[10][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[10][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -443,11 +443,11 @@ 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.
|
||||
d_echo("Fan (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("Fan (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -455,19 +455,19 @@ 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];
|
||||
$result['serial'] = $array[13][$key];
|
||||
$result['string'] = $array[6][$key] ." - Rev: ". $array[12][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.15.56.1.8.'.$key;
|
||||
$result['string'] = $array[6][$key] . " - Rev: " . $array[12][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.15.56.1.8.' . $key;
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[8][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[8][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[8][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -480,11 +480,11 @@ 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.
|
||||
d_echo("PSU (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("PSU (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -492,19 +492,19 @@ 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];
|
||||
$result['serial'] = $array[21][$key];
|
||||
$result['string'] = $array[11][$key] ." - Rev: ". $array[20][$key] ." - Part-No: ". $array[26][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.3.85.1.13.'.$key;
|
||||
$result['string'] = $array[11][$key] . " - Rev: " . $array[20][$key] . " - Part-No: " . $array[26][$key];
|
||||
$result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.3.85.1.13.' . $key;
|
||||
|
||||
// What is the Operability, 1 is good, everything else is bad.
|
||||
if ($array[13][$key] != 1) {
|
||||
// Yes, report an error
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Error Operability Code: ".$array[13][$key];
|
||||
$result['error'] = "Error Operability Code: " . $array[13][$key];
|
||||
} else {
|
||||
// No, unset any errors that may exist.
|
||||
$result['status'] = 0;
|
||||
@ -517,11 +517,11 @@ 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.
|
||||
d_echo("Adaptor (".$tbl."): ".print_r($result, true)."\n");
|
||||
d_echo("Adaptor (" . $tbl . "): " . print_r($result, true) . "\n");
|
||||
$tblCIMC[] = $result;
|
||||
}
|
||||
break;
|
||||
@ -531,7 +531,7 @@ if (is_null($tblUCSObjects)) {
|
||||
d_echo("Cisco-CIMC Error...\n");
|
||||
d_echo("Please log an issue on github with the following information:\n");
|
||||
d_echo("-----------------------------------------------\n");
|
||||
d_echo("Subject: CIMC Unknown Table: ".$tbl."\n");
|
||||
d_echo("Subject: CIMC Unknown Table: " . $tbl . "\n");
|
||||
d_echo("Description: The entity-physical module discovered an unknown CIMC table.\nA dump of its contents is below:\n");
|
||||
d_echo($array);
|
||||
d_echo("-----------------------------------------------\n\n");
|
||||
@ -556,7 +556,7 @@ if (is_null($tblUCSObjects)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$component_key) {
|
||||
if (! $component_key) {
|
||||
// The component doesn't exist, we need to ADD it - ADD.
|
||||
$new_component = $component->createComponent($device['device_id'], $comp_module);
|
||||
$component_key = key($new_component);
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -5,16 +5,16 @@ 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';
|
||||
$ai_ig_data = snmpwalk_group($device, 'aiInfoGroup', $ai_mib);
|
||||
discover_entity_physical(
|
||||
discover_entity_physical(
|
||||
$valid,
|
||||
$device,
|
||||
1, // entPhysicalIndex
|
||||
@ -39,15 +39,15 @@ 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');
|
||||
|
||||
if (!empty($entity_array)) {
|
||||
if (! empty($entity_array)) {
|
||||
echo ' entAliasMappingIdentifier';
|
||||
$entity_array = snmpwalk_cache_twopart_oid($device, 'entAliasMappingIdentifier', $entity_array, 'ENTITY-MIB:IF-MIB');
|
||||
}
|
||||
@ -103,7 +103,7 @@ if ($device['os'] == 'saf-cfm') {
|
||||
}
|
||||
|
||||
foreach ([1 => 'm1Description', 2 => 'm2Description', 3 => 'm3Description', 4 => 'm4Description'] as $index => $item) {
|
||||
if (!Str::contains($device_array[$item], 'N/A')) {
|
||||
if (! Str::contains($device_array[$item], 'N/A')) {
|
||||
$entity_array[] = [
|
||||
'entPhysicalDescr' => $device_array[$item],
|
||||
'entPhysicalVendorType' => 'module',
|
||||
@ -123,34 +123,34 @@ foreach ($entity_array as $entPhysicalIndex => $entry) {
|
||||
if ($device['os'] == 'junos') {
|
||||
// Juniper's MIB doesn't have the same objects as the Entity MIB, so some values
|
||||
// are made up here.
|
||||
$entPhysicalDescr = $entry['jnxContentsDescr'];
|
||||
$entPhysicalContainedIn = $entry['jnxContainersWithin'];
|
||||
$entPhysicalClass = $entry['jnxBoxClass'];
|
||||
$entPhysicalName = $entry['jnxOperatingDescr'];
|
||||
$entPhysicalSerialNum = $entry['jnxContentsSerialNo'];
|
||||
$entPhysicalModelName = $entry['jnxContentsPartNo'];
|
||||
$entPhysicalMfgName = 'Juniper';
|
||||
$entPhysicalVendorType = 'Juniper';
|
||||
$entPhysicalDescr = $entry['jnxContentsDescr'];
|
||||
$entPhysicalContainedIn = $entry['jnxContainersWithin'];
|
||||
$entPhysicalClass = $entry['jnxBoxClass'];
|
||||
$entPhysicalName = $entry['jnxOperatingDescr'];
|
||||
$entPhysicalSerialNum = $entry['jnxContentsSerialNo'];
|
||||
$entPhysicalModelName = $entry['jnxContentsPartNo'];
|
||||
$entPhysicalMfgName = 'Juniper';
|
||||
$entPhysicalVendorType = 'Juniper';
|
||||
$entPhysicalParentRelPos = -1;
|
||||
$entPhysicalHardwareRev = $entry['jnxContentsRevision'];
|
||||
$entPhysicalFirmwareRev = $entry['entPhysicalFirmwareRev'];
|
||||
$entPhysicalSoftwareRev = $entry['entPhysicalSoftwareRev'];
|
||||
$entPhysicalIsFRU = $entry['jnxFruType'];
|
||||
$entPhysicalAlias = $entry['entPhysicalAlias'];
|
||||
$entPhysicalAssetID = $entry['entPhysicalAssetID'];
|
||||
$entPhysicalHardwareRev = $entry['jnxContentsRevision'];
|
||||
$entPhysicalFirmwareRev = $entry['entPhysicalFirmwareRev'];
|
||||
$entPhysicalSoftwareRev = $entry['entPhysicalSoftwareRev'];
|
||||
$entPhysicalIsFRU = $entry['jnxFruType'];
|
||||
$entPhysicalAlias = $entry['entPhysicalAlias'];
|
||||
$entPhysicalAssetID = $entry['entPhysicalAssetID'];
|
||||
// fix for issue 1865, $entPhysicalIndex, as it contains a quad dotted number on newer Junipers
|
||||
// using str_replace to remove all dots should fix this even if it changes in future
|
||||
$entPhysicalIndex = str_replace('.', '', $entPhysicalIndex);
|
||||
} elseif ($device['os'] == 'aruba-instant') {
|
||||
$entPhysicalDescr = $entry['aiAPMACAddress'];
|
||||
$entPhysicalContainedIn = 1;
|
||||
$entPhysicalSerialNum = $entry['aiAPSerialNum'];
|
||||
$entPhysicalModelName = $entry['aiAPModel'];
|
||||
$entPhysicalMfgName = 'Aruba';
|
||||
$entPhysicalVendorType = 'Aruba';
|
||||
$entPhysicalDescr = $entry['aiAPMACAddress'];
|
||||
$entPhysicalContainedIn = 1;
|
||||
$entPhysicalSerialNum = $entry['aiAPSerialNum'];
|
||||
$entPhysicalModelName = $entry['aiAPModel'];
|
||||
$entPhysicalMfgName = 'Aruba';
|
||||
$entPhysicalVendorType = 'Aruba';
|
||||
$entPhysicalParentRelPos = -1;
|
||||
$entPhysicalSoftwareRev = $device['version'];
|
||||
$entPhysicalIndex = $instant_index;
|
||||
$entPhysicalSoftwareRev = $device['version'];
|
||||
$entPhysicalIndex = $instant_index;
|
||||
|
||||
if ($entry['aiAPIPAddress'] == $ai_ig_data['aiMasterIPAddress.0']) {
|
||||
$entPhysicalName = sprintf('%s %s Cluster Master', $entry['aiAPName'], $entry['aiAPIPAddress']);
|
||||
@ -160,39 +160,39 @@ foreach ($entity_array as $entPhysicalIndex => $entry) {
|
||||
|
||||
$instant_index += 1;
|
||||
} elseif ($device['os'] == 'timos') {
|
||||
$entPhysicalDescr = $entry['tmnxCardTypeDescription'];
|
||||
$entPhysicalContainedIn = $entry['tmnxHwContainedIn'];
|
||||
$entPhysicalClass = $entry['tmnxHwClass'];
|
||||
$entPhysicalName = $entry['tmnxCardTypeName'];
|
||||
$entPhysicalSerialNum = $entry['tmnxHwSerialNumber'];
|
||||
$entPhysicalModelName = $entry['tmnxHwMfgBoardNumber'];
|
||||
$entPhysicalMfgName = $entry['tmnxHwMfgBoardNumber'];
|
||||
$entPhysicalVendorType = $entry['tmnxCardTypeName'];
|
||||
$entPhysicalDescr = $entry['tmnxCardTypeDescription'];
|
||||
$entPhysicalContainedIn = $entry['tmnxHwContainedIn'];
|
||||
$entPhysicalClass = $entry['tmnxHwClass'];
|
||||
$entPhysicalName = $entry['tmnxCardTypeName'];
|
||||
$entPhysicalSerialNum = $entry['tmnxHwSerialNumber'];
|
||||
$entPhysicalModelName = $entry['tmnxHwMfgBoardNumber'];
|
||||
$entPhysicalMfgName = $entry['tmnxHwMfgBoardNumber'];
|
||||
$entPhysicalVendorType = $entry['tmnxCardTypeName'];
|
||||
$entPhysicalParentRelPos = $entry['tmnxHwParentRelPos'];
|
||||
$entPhysicalHardwareRev = '1.0';
|
||||
$entPhysicalFirmwareRev = $entry['tmnxHwBootCodeVersion'];
|
||||
$entPhysicalSoftwareRev = $entry['tmnxHwBootCodeVersion'];
|
||||
$entPhysicalIsFRU = $entry['tmnxHwIsFRU'];
|
||||
$entPhysicalAlias = $entry['tmnxHwAlias'];
|
||||
$entPhysicalAssetID = $entry['tmnxHwAssetID'];
|
||||
$entPhysicalHardwareRev = '1.0';
|
||||
$entPhysicalFirmwareRev = $entry['tmnxHwBootCodeVersion'];
|
||||
$entPhysicalSoftwareRev = $entry['tmnxHwBootCodeVersion'];
|
||||
$entPhysicalIsFRU = $entry['tmnxHwIsFRU'];
|
||||
$entPhysicalAlias = $entry['tmnxHwAlias'];
|
||||
$entPhysicalAssetID = $entry['tmnxHwAssetID'];
|
||||
$entPhysicalIndex = str_replace('.', '', $entPhysicalIndex);
|
||||
} elseif ($device['os'] == 'vrp') {
|
||||
//Add some details collected in the VRP Entity Mib
|
||||
$entPhysicalDescr = $entry['hwEntityBomEnDesc'];
|
||||
$entPhysicalContainedIn = $entry['entPhysicalContainedIn'];
|
||||
$entPhysicalClass = $entry['entPhysicalClass'];
|
||||
$entPhysicalName = $entry['entPhysicalName'];
|
||||
$entPhysicalSerialNum = $entry['entPhysicalSerialNum'];
|
||||
$entPhysicalModelName = $entry['hwEntityBoardType'];
|
||||
$entPhysicalMfgName = $entry['entPhysicalMfgName'];
|
||||
$entPhysicalVendorType = $entry['entPhysicalVendorType'];
|
||||
$entPhysicalDescr = $entry['hwEntityBomEnDesc'];
|
||||
$entPhysicalContainedIn = $entry['entPhysicalContainedIn'];
|
||||
$entPhysicalClass = $entry['entPhysicalClass'];
|
||||
$entPhysicalName = $entry['entPhysicalName'];
|
||||
$entPhysicalSerialNum = $entry['entPhysicalSerialNum'];
|
||||
$entPhysicalModelName = $entry['hwEntityBoardType'];
|
||||
$entPhysicalMfgName = $entry['entPhysicalMfgName'];
|
||||
$entPhysicalVendorType = $entry['entPhysicalVendorType'];
|
||||
$entPhysicalParentRelPos = $entry['entPhysicalParentRelPos'];
|
||||
$entPhysicalHardwareRev = $entry['entPhysicalHardwareRev'];
|
||||
$entPhysicalFirmwareRev = $entry['entPhysicalFirmwareRev'];
|
||||
$entPhysicalSoftwareRev = $entry['entPhysicalSoftwareRev'];
|
||||
$entPhysicalIsFRU = $entry['entPhysicalIsFRU'];
|
||||
$entPhysicalAlias = $entry['entPhysicalAlias'];
|
||||
$entPhysicalAssetID = $entry['entPhysicalAssetID'];
|
||||
$entPhysicalHardwareRev = $entry['entPhysicalHardwareRev'];
|
||||
$entPhysicalFirmwareRev = $entry['entPhysicalFirmwareRev'];
|
||||
$entPhysicalSoftwareRev = $entry['entPhysicalSoftwareRev'];
|
||||
$entPhysicalIsFRU = $entry['entPhysicalIsFRU'];
|
||||
$entPhysicalAlias = $entry['entPhysicalAlias'];
|
||||
$entPhysicalAssetID = $entry['entPhysicalAssetID'];
|
||||
|
||||
//VRP devices seems to use LogicalEntity '1' instead of '0' like the default code checks.
|
||||
//Standard code is still run after anyway.
|
||||
@ -200,36 +200,36 @@ foreach ($entity_array as $entPhysicalIndex => $entry) {
|
||||
$ifIndex = preg_replace('/ifIndex\.(\d+).*/', '$1', $entry['1']['entAliasMappingIdentifier']);
|
||||
}
|
||||
} else {
|
||||
$entPhysicalDescr = array_key_exists('entPhysicalDescr', $entry) ? $entry['entPhysicalDescr'] : '';
|
||||
$entPhysicalContainedIn = array_key_exists('entPhysicalContainedIn', $entry) ? $entry['entPhysicalContainedIn'] : '';
|
||||
$entPhysicalClass = array_key_exists('entPhysicalClass', $entry) ? $entry['entPhysicalClass'] : '';
|
||||
$entPhysicalName = array_key_exists('entPhysicalName', $entry) ? $entry['entPhysicalName'] : '';
|
||||
$entPhysicalSerialNum = array_key_exists('entPhysicalSerialNum', $entry) ? $entry['entPhysicalSerialNum'] : '';
|
||||
$entPhysicalModelName = array_key_exists('entPhysicalModelName', $entry) ? $entry['entPhysicalModelName'] : '';
|
||||
$entPhysicalMfgName = array_key_exists('entPhysicalMfgName', $entry) ? $entry['entPhysicalMfgName'] : '';
|
||||
$entPhysicalVendorType = array_key_exists('entPhysicalVendorType', $entry) ? $entry['entPhysicalVendorType'] : '';
|
||||
$entPhysicalDescr = array_key_exists('entPhysicalDescr', $entry) ? $entry['entPhysicalDescr'] : '';
|
||||
$entPhysicalContainedIn = array_key_exists('entPhysicalContainedIn', $entry) ? $entry['entPhysicalContainedIn'] : '';
|
||||
$entPhysicalClass = array_key_exists('entPhysicalClass', $entry) ? $entry['entPhysicalClass'] : '';
|
||||
$entPhysicalName = array_key_exists('entPhysicalName', $entry) ? $entry['entPhysicalName'] : '';
|
||||
$entPhysicalSerialNum = array_key_exists('entPhysicalSerialNum', $entry) ? $entry['entPhysicalSerialNum'] : '';
|
||||
$entPhysicalModelName = array_key_exists('entPhysicalModelName', $entry) ? $entry['entPhysicalModelName'] : '';
|
||||
$entPhysicalMfgName = array_key_exists('entPhysicalMfgName', $entry) ? $entry['entPhysicalMfgName'] : '';
|
||||
$entPhysicalVendorType = array_key_exists('entPhysicalVendorType', $entry) ? $entry['entPhysicalVendorType'] : '';
|
||||
$entPhysicalParentRelPos = array_key_exists('entPhysicalParentRelPos', $entry) ? $entry['entPhysicalParentRelPos'] : '';
|
||||
$entPhysicalHardwareRev = array_key_exists('entPhysicalHardwareRev', $entry) ? $entry['entPhysicalHardwareRev'] : '';
|
||||
$entPhysicalFirmwareRev = array_key_exists('entPhysicalFirmwareRev', $entry) ? $entry['entPhysicalFirmwareRev'] : '';
|
||||
$entPhysicalSoftwareRev = array_key_exists('entPhysicalSoftwareRev', $entry) ? $entry['entPhysicalSoftwareRev'] : '';
|
||||
$entPhysicalIsFRU = array_key_exists('entPhysicalIsFRU', $entry) ? $entry['entPhysicalIsFRU'] : '';
|
||||
$entPhysicalAlias = array_key_exists('entPhysicalAlias', $entry) ? $entry['entPhysicalAlias'] : '';
|
||||
$entPhysicalAssetID = array_key_exists('entPhysicalAssetID', $entry) ? $entry['entPhysicalAssetID'] : '';
|
||||
$entPhysicalHardwareRev = array_key_exists('entPhysicalHardwareRev', $entry) ? $entry['entPhysicalHardwareRev'] : '';
|
||||
$entPhysicalFirmwareRev = array_key_exists('entPhysicalFirmwareRev', $entry) ? $entry['entPhysicalFirmwareRev'] : '';
|
||||
$entPhysicalSoftwareRev = array_key_exists('entPhysicalSoftwareRev', $entry) ? $entry['entPhysicalSoftwareRev'] : '';
|
||||
$entPhysicalIsFRU = array_key_exists('entPhysicalIsFRU', $entry) ? $entry['entPhysicalIsFRU'] : '';
|
||||
$entPhysicalAlias = array_key_exists('entPhysicalAlias', $entry) ? $entry['entPhysicalAlias'] : '';
|
||||
$entPhysicalAssetID = array_key_exists('entPhysicalAssetID', $entry) ? $entry['entPhysicalAssetID'] : '';
|
||||
}//end if
|
||||
|
||||
if (isset($entity_array[$entPhysicalIndex]['0']['entAliasMappingIdentifier'])) {
|
||||
$ifIndex = $entity_array[$entPhysicalIndex]['0']['entAliasMappingIdentifier'];
|
||||
if (!strpos($ifIndex, 'fIndex') || $ifIndex == '') {
|
||||
if (! strpos($ifIndex, 'fIndex') || $ifIndex == '') {
|
||||
unset($ifIndex);
|
||||
} else {
|
||||
$ifIndex_array = explode('.', $ifIndex);
|
||||
$ifIndex = $ifIndex_array[1];
|
||||
$ifIndex = $ifIndex_array[1];
|
||||
unset($ifIndex_array);
|
||||
}
|
||||
}
|
||||
|
||||
// List of real names for cisco entities
|
||||
$entPhysicalVendorTypes = array(
|
||||
$entPhysicalVendorTypes = [
|
||||
'cevC7xxxIo1feTxIsl' => 'C7200-IO-FE-MII',
|
||||
'cevChassis7140Dualfe' => 'C7140-2FE',
|
||||
'cevChassis7204' => 'C7204',
|
||||
@ -248,9 +248,9 @@ foreach ($entity_array as $entPhysicalIndex => $entry) {
|
||||
'cevPaA8tX21' => 'PA-8T-X21',
|
||||
'cevMGBIC1000BaseLX' => '1000BaseLX GBIC',
|
||||
'cevPort10GigBaseLR' => '10GigBaseLR',
|
||||
);
|
||||
];
|
||||
|
||||
if ($entPhysicalVendorTypes[$entPhysicalVendorType] && !$entPhysicalModelName) {
|
||||
if ($entPhysicalVendorTypes[$entPhysicalVendorType] && ! $entPhysicalModelName) {
|
||||
$entPhysicalModelName = $entPhysicalVendorTypes[$entPhysicalVendorType];
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ echo "\nCaching OIDs:";
|
||||
$entity_array = [];
|
||||
echo ' MRV OptiDriver';
|
||||
$chassis_array = snmpwalk_cache_multi_oid($device, 'nbsCmmcChassisTable', $chassis_array, 'NBS-CMMC-MIB');
|
||||
$slot_array = snmpwalk_cache_multi_oid($device, 'nbsCmmcSlotTable', $slot_array, 'NBS-CMMC-MIB');
|
||||
$port_array = snmpwalk_cache_multi_oid($device, 'nbsCmmcPortTable', $port_array, 'NBS-CMMC-MIB');
|
||||
$slot_array = snmpwalk_cache_multi_oid($device, 'nbsCmmcSlotTable', $slot_array, 'NBS-CMMC-MIB');
|
||||
$port_array = snmpwalk_cache_multi_oid($device, 'nbsCmmcPortTable', $port_array, 'NBS-CMMC-MIB');
|
||||
|
||||
// We use the last digit in the OID to define an entPhysicalIndex for Power Supply state sensors
|
||||
$nbsCmmcChassisPSStatus_array = [
|
||||
@ -57,39 +57,39 @@ $nbsCmmcPortSensor_array = [
|
||||
'objectType' => 'nbsCmmcPortTemperature',
|
||||
'skipValue' => '-2147483648',
|
||||
'entPhysicalName' => 'Port Temperature',
|
||||
],
|
||||
],
|
||||
31 => [
|
||||
'objectType' => 'nbsCmmcPortTxPower',
|
||||
'skipValue' => '-2147483648',
|
||||
'entPhysicalName' => 'Port Tx Power',
|
||||
],
|
||||
],
|
||||
32 => [
|
||||
'objectType' => 'nbsCmmcPortRxPower',
|
||||
'skipValue' => '-2147483648',
|
||||
'entPhysicalName' => 'Port Rx Power',
|
||||
],
|
||||
],
|
||||
33 => [
|
||||
'objectType' => 'nbsCmmcPortBiasAmps',
|
||||
'skipValue' => '-1',
|
||||
'entPhysicalName' => 'Port Tx Bias Current',
|
||||
],
|
||||
],
|
||||
34 => [
|
||||
'objectType' => 'nbsCmmcPortSupplyVolts',
|
||||
'skipValue' => '-1',
|
||||
'entPhysicalName' => 'Port Tx Supply Voltage',
|
||||
],
|
||||
],
|
||||
38 => [
|
||||
'objectType' => 'nbsCmmcPortDigitalDiags',
|
||||
'skipValue' => '1',
|
||||
'entPhysicalName' => 'Port Overall DigiDiags State',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
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",
|
||||
'entPhysicalIndex' => $chassis_contents['nbsCmmcChassisIfIndex'] . "00",
|
||||
'entPhysicalDescr' => "MRV OptiDriver {$chassis_contents['nbsCmmcChassisModel']}",
|
||||
'entPhysicalClass' => 'chassis',
|
||||
'entPhysicalName' => "Chassis $nbsCmmcChassis",
|
||||
@ -138,7 +138,7 @@ foreach ($chassis_array as $nbsCmmcChassis => $chassis_contents) {
|
||||
if (isset($chassis_contents[$item]) && $chassis_contents[$item] != 'notSupported') {
|
||||
$position = substr($item, 16, 1);
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => $chassis_contents['nbsCmmcChassisIfIndex'].$position,
|
||||
'entPhysicalIndex' => $chassis_contents['nbsCmmcChassisIfIndex'] . $position,
|
||||
'entPhysicalDescr' => "Power Supply",
|
||||
'entPhysicalClass' => 'powerSupply',
|
||||
'entPhysicalName' => "Power Supply $position",
|
||||
@ -148,11 +148,11 @@ foreach ($chassis_array as $nbsCmmcChassis => $chassis_contents) {
|
||||
'entPhysicalIsFRU' => 'false',
|
||||
];
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => $chassis_contents['nbsCmmcChassisIfIndex'].$index,
|
||||
'entPhysicalIndex' => $chassis_contents['nbsCmmcChassisIfIndex'] . $index,
|
||||
'entPhysicalDescr' => "Power Supply State",
|
||||
'entPhysicalClass' => 'sensor',
|
||||
'entPhysicalName' => "Power Supply $position",
|
||||
'entPhysicalContainedIn' => $chassis_contents['nbsCmmcChassisIfIndex'].$position,
|
||||
'entPhysicalContainedIn' => $chassis_contents['nbsCmmcChassisIfIndex'] . $position,
|
||||
'entPhysicalMfgName' => 'MRV Communications',
|
||||
'entPhysicalParentRelPos' => '-1',
|
||||
'entPhysicalIsFRU' => 'true',
|
||||
@ -175,7 +175,7 @@ foreach ($chassis_array as $nbsCmmcChassis => $chassis_contents) {
|
||||
'entPhysicalIsFRU' => 'false',
|
||||
];
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => $chassis_contents['nbsCmmcChassisIfIndex'].$index,
|
||||
'entPhysicalIndex' => $chassis_contents['nbsCmmcChassisIfIndex'] . $index,
|
||||
'entPhysicalDescr' => "Fan State",
|
||||
'entPhysicalClass' => 'sensor',
|
||||
'entPhysicalName' => "Fan $position",
|
||||
@ -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'];
|
||||
@ -197,21 +195,21 @@ foreach ($slot_array as $nbsCmmcSlot => $slot_contents) {
|
||||
$nbsCmmcSlotIfIndex = $nbsCmmcChassisIfIndex + $slot_contents['nbsCmmcSlotIndex'] * 1000;
|
||||
// Discover the slot
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => $nbsCmmcSlotIfIndex."00",
|
||||
'entPhysicalIndex' => $nbsCmmcSlotIfIndex . "00",
|
||||
'entPhysicalDescr' => 'MRV OptiDriver Slot',
|
||||
'entPhysicalClass' => 'container',
|
||||
'entPhysicalName' => "Card Slot $nbsCmmcSlot",
|
||||
'entPhysicalContainedIn' => $nbsCmmcChassisIfIndex."00",
|
||||
'entPhysicalContainedIn' => $nbsCmmcChassisIfIndex . "00",
|
||||
'entPhysicalMfgName' => 'MRV Communications',
|
||||
'entPhysicalParentRelPos' => $slot_contents['nbsCmmcSlotIndex'],
|
||||
'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",
|
||||
'entPhysicalDescr' => "MRV ".ucfirst($slot_contents['nbsCmmcSlotOperationType'])." Card",
|
||||
'entPhysicalIndex' => $slot_contents['nbsCmmcSlotIfIndex'] . "01",
|
||||
'entPhysicalDescr' => "MRV " . ucfirst($slot_contents['nbsCmmcSlotOperationType']) . " Card",
|
||||
'entPhysicalClass' => 'module',
|
||||
'entPhysicalName' => "Card $nbsCmmcSlot",
|
||||
'entPhysicalModelName' => $slot_contents['nbsCmmcSlotModel'],
|
||||
@ -244,7 +242,7 @@ foreach ($slot_array as $nbsCmmcSlot => $slot_contents) {
|
||||
|
||||
foreach ($port_array as $nbsCmmcPort => $port_contents) {
|
||||
// Obtain the nbsCmmcSlotIfIndex of the slot which houses this port
|
||||
$nbsCmmcSlot = $port_contents['nbsCmmcPortChassisIndex'].".".$port_contents['nbsCmmcPortSlotIndex'];
|
||||
$nbsCmmcSlot = $port_contents['nbsCmmcPortChassisIndex'] . "." . $port_contents['nbsCmmcPortSlotIndex'];
|
||||
$nbsCmmcSlotIfIndex = $slot_array[$nbsCmmcSlot]['nbsCmmcSlotIfIndex'];
|
||||
|
||||
// We only need to discover a transceiver container if the port type is pluggable
|
||||
@ -253,41 +251,41 @@ foreach ($port_array as $nbsCmmcPort => $port_contents) {
|
||||
|
||||
// Discover the transceiver container
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => $port_contents['nbsCmmcPortIfIndex']."00",
|
||||
'entPhysicalIndex' => $port_contents['nbsCmmcPortIfIndex'] . "00",
|
||||
'entPhysicalDescr' => "$nbsCmmcPortType Transceiver Container",
|
||||
'entPhysicalClass' => 'container',
|
||||
'entPhysicalName' => "Transceiver Container $nbsCmmcPort",
|
||||
'entPhysicalContainedIn' => $nbsCmmcSlotIfIndex."01",
|
||||
'entPhysicalContainedIn' => $nbsCmmcSlotIfIndex . "01",
|
||||
'entPhysicalMfgName' => 'MRV Communications',
|
||||
'entPhysicalParentRelPos' => $port_contents['nbsCmmcPortIndex'],
|
||||
'entPhysicalIsFRU' => 'false',
|
||||
];
|
||||
// Set a few variables for the port discovery
|
||||
$nbsCmmcPortContainedIn = $port_contents['nbsCmmcPortIfIndex']."00";
|
||||
$nbsCmmcPortVendorInfo = $port_contents['nbsCmmcPortVendorInfo'];
|
||||
$nbsCmmcPortIsFRU = 'true';
|
||||
$nbsCmmcPortContainedIn = $port_contents['nbsCmmcPortIfIndex'] . "00";
|
||||
$nbsCmmcPortVendorInfo = $port_contents['nbsCmmcPortVendorInfo'];
|
||||
$nbsCmmcPortIsFRU = 'true';
|
||||
$nbsCmmcPortParentRelPos = '-1';
|
||||
// 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';
|
||||
|
||||
// Set a few variables for the port discovery
|
||||
$nbsCmmcPortContainedIn = $nbsCmmcSlotIfIndex."01";
|
||||
$nbsCmmcPortVendorInfo = "MRV Communications";
|
||||
$nbsCmmcPortIsFRU = 'false';
|
||||
$nbsCmmcPortContainedIn = $nbsCmmcSlotIfIndex . "01";
|
||||
$nbsCmmcPortVendorInfo = "MRV Communications";
|
||||
$nbsCmmcPortIsFRU = 'false';
|
||||
$nbsCmmcPortParentRelPos = $port_contents['nbsCmmcPortIndex'];
|
||||
$nbsCmmcPortModelName = '';
|
||||
$nbsCmmcPortHardwareRev = '';
|
||||
$nbsCmmcPortModelName = '';
|
||||
$nbsCmmcPortHardwareRev = '';
|
||||
}
|
||||
|
||||
if (isset($port_contents['nbsCmmcPortConnector']) && $port_contents['nbsCmmcPortConnector'] != 'removed') {
|
||||
// Determine the correct entPhysicalDescr for the port
|
||||
if (isset($port_contents['nbsCmmcPortWavelengthX']) && $port_contents['nbsCmmcPortWavelengthX'] != 'N/A') {
|
||||
$portEntPhysicalDescr = "$nbsCmmcPortType Port, {$port_contents['nbsCmmcPortWavelengthX']}nm Tx Signal, {$port_contents['nbsCmmcPortConnector']} Connector";
|
||||
} elseif (!empty($port_contents['nbsCmmcPortDescription'])) {
|
||||
} elseif (! empty($port_contents['nbsCmmcPortDescription'])) {
|
||||
$portEntPhysicalDescr = "$nbsCmmcPortType Port, {$port_contents['nbsCmmcPortDescription']}, {$port_contents['nbsCmmcPortConnector']} Connector";
|
||||
} else {
|
||||
$portEntPhysicalDescr = "$nbsCmmcPortType Port, {$port_contents['nbsCmmcPortConnector']} Connector";
|
||||
@ -315,7 +313,7 @@ foreach ($port_array as $nbsCmmcPort => $port_contents) {
|
||||
foreach ($nbsCmmcPortSensor_array as $index => $nbsCmmcPortSensor) {
|
||||
if (isset($port_contents[$nbsCmmcPortSensor['objectType']]) && $port_contents[$nbsCmmcPortSensor['objectType']] != $nbsCmmcPortSensor['skipValue']) {
|
||||
$entity_array[] = [
|
||||
'entPhysicalIndex' => $port_contents['nbsCmmcPortIfIndex'].$index,
|
||||
'entPhysicalIndex' => $port_contents['nbsCmmcPortIfIndex'] . $index,
|
||||
'entPhysicalDescr' => "{$nbsCmmcPortSensor['entPhysicalName']} Sensor",
|
||||
'entPhysicalClass' => 'sensor',
|
||||
'entPhysicalName' => $nbsCmmcPortSensor['entPhysicalName'],
|
||||
@ -330,23 +328,23 @@ foreach ($port_array as $nbsCmmcPort => $port_contents) {
|
||||
}
|
||||
|
||||
foreach ($entity_array as $entPhysicalIndex => $entry) {
|
||||
$entPhysicalIndex = array_key_exists('entPhysicalIndex', $entry) ? $entry['entPhysicalIndex'] : '';
|
||||
$entPhysicalDescr = array_key_exists('entPhysicalDescr', $entry) ? $entry['entPhysicalDescr'] : '';
|
||||
$entPhysicalClass = array_key_exists('entPhysicalClass', $entry) ? $entry['entPhysicalClass'] : '';
|
||||
$entPhysicalName = array_key_exists('entPhysicalName', $entry) ? $entry['entPhysicalName'] : '';
|
||||
$entPhysicalModelName = array_key_exists('entPhysicalModelName', $entry) ? $entry['entPhysicalModelName'] : '';
|
||||
$entPhysicalSerialNum = array_key_exists('entPhysicalSerialNum', $entry) ? $entry['entPhysicalSerialNum'] : '';
|
||||
$entPhysicalContainedIn = array_key_exists('entPhysicalContainedIn', $entry) ? $entry['entPhysicalContainedIn'] : '';
|
||||
$entPhysicalMfgName = array_key_exists('entPhysicalMfgName', $entry) ? $entry['entPhysicalMfgName'] : '';
|
||||
$entPhysicalParentRelPos = array_key_exists('entPhysicalParentRelPos', $entry) ? $entry['entPhysicalParentRelPos'] : '';
|
||||
$entPhysicalVendorType = array_key_exists('entPhysicalVendorType', $entry) ? $entry['entPhysicalVendorType'] : '';
|
||||
$entPhysicalHardwareRev = array_key_exists('entPhysicalHardwareRev', $entry) ? $entry['entPhysicalHardwareRev'] : '';
|
||||
$entPhysicalFirmwareRev = array_key_exists('entPhysicalFirmwareRev', $entry) ? $entry['entPhysicalFirmwareRev'] : '';
|
||||
$entPhysicalSoftwareRev = array_key_exists('entPhysicalSoftwareRev', $entry) ? $entry['entPhysicalSoftwareRev'] : '';
|
||||
$entPhysicalIsFRU = array_key_exists('entPhysicalIsFRU', $entry) ? $entry['entPhysicalIsFRU'] : '';
|
||||
$entPhysicalAlias = array_key_exists('entPhysicalAlias', $entry) ? $entry['entPhysicalAlias'] : '';
|
||||
$entPhysicalAssetID = array_key_exists('entPhysicalAssetID', $entry) ? $entry['entPhysicalAssetID'] : '';
|
||||
$ifIndex = array_key_exists('ifIndex', $entry) ? $entry['ifIndex'] : '';
|
||||
$entPhysicalIndex = array_key_exists('entPhysicalIndex', $entry) ? $entry['entPhysicalIndex'] : '';
|
||||
$entPhysicalDescr = array_key_exists('entPhysicalDescr', $entry) ? $entry['entPhysicalDescr'] : '';
|
||||
$entPhysicalClass = array_key_exists('entPhysicalClass', $entry) ? $entry['entPhysicalClass'] : '';
|
||||
$entPhysicalName = array_key_exists('entPhysicalName', $entry) ? $entry['entPhysicalName'] : '';
|
||||
$entPhysicalModelName = array_key_exists('entPhysicalModelName', $entry) ? $entry['entPhysicalModelName'] : '';
|
||||
$entPhysicalSerialNum = array_key_exists('entPhysicalSerialNum', $entry) ? $entry['entPhysicalSerialNum'] : '';
|
||||
$entPhysicalContainedIn = array_key_exists('entPhysicalContainedIn', $entry) ? $entry['entPhysicalContainedIn'] : '';
|
||||
$entPhysicalMfgName = array_key_exists('entPhysicalMfgName', $entry) ? $entry['entPhysicalMfgName'] : '';
|
||||
$entPhysicalParentRelPos = array_key_exists('entPhysicalParentRelPos', $entry) ? $entry['entPhysicalParentRelPos'] : '';
|
||||
$entPhysicalVendorType = array_key_exists('entPhysicalVendorType', $entry) ? $entry['entPhysicalVendorType'] : '';
|
||||
$entPhysicalHardwareRev = array_key_exists('entPhysicalHardwareRev', $entry) ? $entry['entPhysicalHardwareRev'] : '';
|
||||
$entPhysicalFirmwareRev = array_key_exists('entPhysicalFirmwareRev', $entry) ? $entry['entPhysicalFirmwareRev'] : '';
|
||||
$entPhysicalSoftwareRev = array_key_exists('entPhysicalSoftwareRev', $entry) ? $entry['entPhysicalSoftwareRev'] : '';
|
||||
$entPhysicalIsFRU = array_key_exists('entPhysicalIsFRU', $entry) ? $entry['entPhysicalIsFRU'] : '';
|
||||
$entPhysicalAlias = array_key_exists('entPhysicalAlias', $entry) ? $entry['entPhysicalAlias'] : '';
|
||||
$entPhysicalAssetID = array_key_exists('entPhysicalAssetID', $entry) ? $entry['entPhysicalAssetID'] : '';
|
||||
$ifIndex = array_key_exists('ifIndex', $entry) ? $entry['ifIndex'] : '';
|
||||
|
||||
discover_entity_physical($valid, $device, $entPhysicalIndex, $entPhysicalDescr, $entPhysicalClass, $entPhysicalName, $entPhysicalModelName, $entPhysicalSerialNum, $entPhysicalContainedIn, $entPhysicalMfgName, $entPhysicalParentRelPos, $entPhysicalVendorType, $entPhysicalHardwareRev, $entPhysicalFirmwareRev, $entPhysicalSoftwareRev, $entPhysicalIsFRU, $entPhysicalAlias, $entPhysicalAssetID, $ifIndex);
|
||||
}//end foreach
|
||||
|
@ -12,26 +12,26 @@
|
||||
*/
|
||||
|
||||
// Let's gather some data about the databus ring..
|
||||
$sdbMgmtStsDevices = snmp_get($device, '.1.3.6.1.4.1.31034.12.1.1.1.1.1.0', '-Oqv', '');
|
||||
$sdbMgmtDatabusRingDescr = "Schleifenbauer databus ring ($sdbMgmtStsDevices units)";
|
||||
$sdbMgmtStsDevices = snmp_get($device, '.1.3.6.1.4.1.31034.12.1.1.1.1.1.0', '-Oqv', '');
|
||||
$sdbMgmtDatabusRingDescr = "Schleifenbauer databus ring ($sdbMgmtStsDevices units)";
|
||||
|
||||
// Let's gather some data about the units..
|
||||
$sdbMgmtCtrlDevUnitAddressArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.1.2.4.1.2', 1));
|
||||
$sdbDevIdNameArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.10', 1));
|
||||
$sdbDevIdLocationArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.11', 1));
|
||||
$sdbDevIdVanityTagArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.12', 1));
|
||||
$sdbDevIdSerialNumberArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.6', 1));
|
||||
$sdbDevIdFirmwareVersionArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.2', 1));
|
||||
$sdbDevIdProductIdArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.5', 1));
|
||||
$sdbDevIdSalesOrderNumberArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.4', 1));
|
||||
$sdbDevCfMaximumLoadArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.2.1.1.6', 1));
|
||||
$sdbDevCfOutletsTotalArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.2.1.1.2', 1));
|
||||
$sdbDevCfSensorsArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.2.1.1.5', 1));
|
||||
$sdbDevIdNameArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.10', 1));
|
||||
$sdbDevIdLocationArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.11', 1));
|
||||
$sdbDevIdVanityTagArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.12', 1));
|
||||
$sdbDevIdSerialNumberArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.6', 1));
|
||||
$sdbDevIdFirmwareVersionArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.2', 1));
|
||||
$sdbDevIdProductIdArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.5', 1));
|
||||
$sdbDevIdSalesOrderNumberArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.1.1.1.4', 1));
|
||||
$sdbDevCfMaximumLoadArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.2.1.1.6', 1));
|
||||
$sdbDevCfOutletsTotalArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.2.1.1.2', 1));
|
||||
$sdbDevCfSensorsArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.2.1.1.5', 1));
|
||||
|
||||
// And let's gather some data about the inputs, outputs, and sensors on those units..
|
||||
$sdbDevInNameArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.6.1.1.13', 2));
|
||||
$sdbDevSnsTypeArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.8.2.1.2', 2));
|
||||
$sdbDevSnsNameArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.8.2.1.4', 2));
|
||||
$sdbDevInNameArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.6.1.1.13', 2));
|
||||
$sdbDevSnsTypeArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.8.2.1.2', 2));
|
||||
$sdbDevSnsNameArray = current(snmpwalk_array_num($device, '.1.3.6.1.4.1.31034.12.1.1.2.8.2.1.4', 2));
|
||||
|
||||
// In a large databus ring, snmpwalking this OID may crash the discovery half way through.
|
||||
// So, we only discover and enumerate outlets if this is a stand-alone, non-databus unit.
|
||||
@ -51,14 +51,14 @@ if ($sdbMgmtStsDevices > 1) {
|
||||
}
|
||||
|
||||
foreach ($sdbMgmtCtrlDevUnitAddressArray as $sdbMgmtCtrlDevUnitAddress => $sdbDevIdIndex) {
|
||||
$entPhysicalDescr = "Schleifenbauer ". count($sdbDevInNameArray[$sdbDevIdIndex]) ."-phase, ". $sdbDevCfOutletsTotalArray[$sdbDevIdIndex] ."-outlet PDU";
|
||||
$entPhysicalName = "Schleifenbauer PDU - SPDM v". $sdbDevIdFirmwareVersionArray[$sdbDevIdIndex];
|
||||
$entPhysicalHardwareRev = "SO# ". $sdbDevIdSalesOrderNumberArray[$sdbDevIdIndex];
|
||||
$entPhysicalDescr = "Schleifenbauer " . count($sdbDevInNameArray[$sdbDevIdIndex]) . "-phase, " . $sdbDevCfOutletsTotalArray[$sdbDevIdIndex] . "-outlet PDU";
|
||||
$entPhysicalName = "Schleifenbauer PDU - SPDM v" . $sdbDevIdFirmwareVersionArray[$sdbDevIdIndex];
|
||||
$entPhysicalHardwareRev = "SO# " . $sdbDevIdSalesOrderNumberArray[$sdbDevIdIndex];
|
||||
|
||||
// We are determining the $entPhysicalAlias for this PDU based on a few optional user-customizable fields.
|
||||
$entPhysicalAlias = null;
|
||||
if ($sdbDevIdNameArray[$sdbDevIdIndex] != '') {
|
||||
$entPhysicalAlias = $sdbDevIdLocationArray[$sdbDevIdIndex] != '' ? $sdbDevIdNameArray[$sdbDevIdIndex] ." @ ". $sdbDevIdLocationArray[$sdbDevIdIndex] : $sdbDevIdNameArray[$sdbDevIdIndex];
|
||||
$entPhysicalAlias = $sdbDevIdLocationArray[$sdbDevIdIndex] != '' ? $sdbDevIdNameArray[$sdbDevIdIndex] . " @ " . $sdbDevIdLocationArray[$sdbDevIdIndex] : $sdbDevIdNameArray[$sdbDevIdIndex];
|
||||
} // end of $entPhysicalAlias if-sequence
|
||||
|
||||
discover_entity_physical($valid, $device, $sdbMgmtCtrlDevUnitAddress * 10, $entPhysicalDescr, 'chassis', $entPhysicalName, $sdbDevIdProductIdArray[$sdbDevIdIndex], $sdbDevIdSerialNumberArray[$sdbDevIdIndex], $entPhysicalContainedIn, 'Schleifenbauer Products B.V.', $sdbMgmtCtrlDevUnitAddress, null, $entPhysicalHardwareRev, null, $sdbDevIdFirmwareVersionArray[$sdbDevIdIndex], 'true', $entPhysicalAlias, $sdbDevIdVanityTagArray[$sdbDevIdIndex], null);
|
||||
@ -66,18 +66,18 @@ foreach ($sdbMgmtCtrlDevUnitAddressArray as $sdbMgmtCtrlDevUnitAddress => $sdbDe
|
||||
// Since a fully numerical entPhysicalIndex is only available for the actual PDU, we are calculating a fake entPhysicalIndex to avoid namespace collision. We have an Integer32 of space per IETF RFC6933 anyway.
|
||||
// The maximum sdbMgmtCtrlDevUnitAddress is 255, but multiplying by 1 million for namespace size. Add +100k for every top-level index below a PDU.
|
||||
foreach ($sdbDevInNameArray[$sdbDevIdIndex] as $sdbDevInIndex => $sdbDevInName) {
|
||||
$inputIndex = $sdbMgmtCtrlDevUnitAddress * 1000000 + 100000 + $sdbDevInIndex * 1000; // +100k for the first top-level namespace. Add 1000 * sdbDevInIndex which goes up to 48. Leave 3 variable digits at the end.
|
||||
$entPhysicalDescr = $sdbDevCfMaximumLoadArray[$sdbDevIdIndex] ."A input phase";
|
||||
$entPhysicalName = "Input L". $sdbDevInIndex;
|
||||
$inputIndex = $sdbMgmtCtrlDevUnitAddress * 1000000 + 100000 + $sdbDevInIndex * 1000; // +100k for the first top-level namespace. Add 1000 * sdbDevInIndex which goes up to 48. Leave 3 variable digits at the end.
|
||||
$entPhysicalDescr = $sdbDevCfMaximumLoadArray[$sdbDevIdIndex] . "A input phase";
|
||||
$entPhysicalName = "Input L" . $sdbDevInIndex;
|
||||
|
||||
discover_entity_physical($valid, $device, $inputIndex, $entPhysicalDescr, 'powerSupply', $entPhysicalName, null, null, $sdbMgmtCtrlDevUnitAddress * 10, 'Schleifenbauer Products B.V.', $sdbDevInIndex, null, null, null, null, 'false', $sdbDevInName, null, null);
|
||||
|
||||
// Enumerate sensors under the Input
|
||||
discover_entity_physical($valid, $device, $inputIndex + 110, $entPhysicalName .' voltage sensor (V)', 'sensor', 'Voltage Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 1, null, null, null, null, 'false', null, null, null);
|
||||
discover_entity_physical($valid, $device, $inputIndex + 120, $entPhysicalName .' RMS current sensor (A)', 'sensor', 'Current Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 2, null, null, null, null, 'false', null, null, null);
|
||||
discover_entity_physical($valid, $device, $inputIndex + 130, $entPhysicalName .' apparent power sensor (W)', 'sensor', 'Power Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 3, null, null, null, null, 'false', null, null, null);
|
||||
discover_entity_physical($valid, $device, $inputIndex + 140, $entPhysicalName .' lifetime power consumed sensor (kWh)', 'sensor', 'Power Consumed Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 4, null, null, null, null, 'false', null, null, null);
|
||||
discover_entity_physical($valid, $device, $inputIndex + 150, $entPhysicalName .' power factor sensor (ratio)', 'sensor', 'Power Factor Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 5, null, null, null, null, 'false', null, null, null);
|
||||
discover_entity_physical($valid, $device, $inputIndex + 110, $entPhysicalName . ' voltage sensor (V)', 'sensor', 'Voltage Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 1, null, null, null, null, 'false', null, null, null);
|
||||
discover_entity_physical($valid, $device, $inputIndex + 120, $entPhysicalName . ' RMS current sensor (A)', 'sensor', 'Current Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 2, null, null, null, null, 'false', null, null, null);
|
||||
discover_entity_physical($valid, $device, $inputIndex + 130, $entPhysicalName . ' apparent power sensor (W)', 'sensor', 'Power Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 3, null, null, null, null, 'false', null, null, null);
|
||||
discover_entity_physical($valid, $device, $inputIndex + 140, $entPhysicalName . ' lifetime power consumed sensor (kWh)', 'sensor', 'Power Consumed Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 4, null, null, null, null, 'false', null, null, null);
|
||||
discover_entity_physical($valid, $device, $inputIndex + 150, $entPhysicalName . ' power factor sensor (ratio)', 'sensor', 'Power Factor Sensor', null, null, $inputIndex, 'Schleifenbauer Products B.V.', 5, null, null, null, null, 'false', null, null, null);
|
||||
} // end Input discovery foreach sdbDevInNameArray
|
||||
|
||||
// Only enumerate outlets if this is a stand-alone, non-databus unit.
|
||||
@ -85,14 +85,14 @@ foreach ($sdbMgmtCtrlDevUnitAddressArray as $sdbMgmtCtrlDevUnitAddress => $sdbDe
|
||||
// Check if we can find any outlets on this PDU..
|
||||
if ($sdbDevOutNameArray[$sdbDevIdIndex] != '') {
|
||||
// We found outlets, so let's spawn an Outlet Backplane.
|
||||
$outletBackplaneIndex = $sdbMgmtCtrlDevUnitAddress * 1000000 + 200000; // +200k for the second top-level index namespace.
|
||||
$entPhysicalDescr = $sdbDevCfOutletsTotalArray[$sdbDevIdIndex] ." outlets";
|
||||
$outletBackplaneIndex = $sdbMgmtCtrlDevUnitAddress * 1000000 + 200000; // +200k for the second top-level index namespace.
|
||||
$entPhysicalDescr = $sdbDevCfOutletsTotalArray[$sdbDevIdIndex] . " outlets";
|
||||
|
||||
discover_entity_physical($valid, $device, $outletBackplaneIndex, $entPhysicalDescr, 'backplane', 'Outlets', null, null, $sdbMgmtCtrlDevUnitAddress * 10, 'Schleifenbauer Products B.V.', '-1', null, null, null, null, 'false', null, null, null);
|
||||
|
||||
foreach ($sdbDevOutNameArray[$sdbDevIdIndex] as $sdbDevOutIndex => $sdbDevOutName) {
|
||||
$outletIndex = $sdbMgmtCtrlDevUnitAddress * 1000000 + 200000 + $sdbDevOutIndex * 1000; // +200k for the second top-level index namespace. Add 1000 * sdbDevOutIndex which goes up to 48. Leave 3 variable digits at the end.
|
||||
$entPhysicalName = "Outlet #". $sdbDevOutIndex;
|
||||
$outletIndex = $sdbMgmtCtrlDevUnitAddress * 1000000 + 200000 + $sdbDevOutIndex * 1000; // +200k for the second top-level index namespace. Add 1000 * sdbDevOutIndex which goes up to 48. Leave 3 variable digits at the end.
|
||||
$entPhysicalName = "Outlet #" . $sdbDevOutIndex;
|
||||
|
||||
discover_entity_physical($valid, $device, $outletIndex, 'PDU outlet', 'powerSupply', $entPhysicalName, null, null, $outletBackplaneIndex, 'Schleifenbauer Products B.V.', $sdbDevOutIndex, null, null, null, null, 'false', $sdbDevOutName, null, null);
|
||||
} // end Outlet discovery foreach sdbDevOutNameArray
|
||||
@ -103,21 +103,21 @@ foreach ($sdbMgmtCtrlDevUnitAddressArray as $sdbMgmtCtrlDevUnitAddress => $sdbDe
|
||||
if ($sdbDevSnsTypeArray[$sdbDevIdIndex] != '') {
|
||||
// We found at least one sensor connection, so let's spawn a Sensor Container.
|
||||
$sensorContainerIndex = $sdbMgmtCtrlDevUnitAddress * 1000000 + 300000; // +300k for the third top-level index namespace.
|
||||
$entPhysicalDescr = $sdbDevCfSensorsArray[$sdbDevIdIndex] == 1 ? "1 external sensor" : $sdbDevCfSensorsArray[$sdbDevIdIndex] ." external sensors";
|
||||
$entPhysicalDescr = $sdbDevCfSensorsArray[$sdbDevIdIndex] == 1 ? "1 external sensor" : $sdbDevCfSensorsArray[$sdbDevIdIndex] . " external sensors";
|
||||
|
||||
discover_entity_physical($valid, $device, $sensorContainerIndex, $entPhysicalDescr, 'container', 'Sensor Container', null, null, $sdbMgmtCtrlDevUnitAddress * 10, 'Schleifenbauer Products B.V.', '-1', null, null, null, null, 'false', null, null, null);
|
||||
|
||||
foreach ($sdbDevSnsNameArray[$sdbDevIdIndex] as $sdbDevSnsIndex => $sdbDevSnsName) {
|
||||
$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;
|
||||
$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;
|
||||
}
|
||||
|
@ -22,18 +22,17 @@
|
||||
* @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)) {
|
||||
if (! empty($entPhysical)) {
|
||||
echo "\nEntity States: ";
|
||||
|
||||
$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
|
||||
@ -59,12 +58,12 @@ if (!empty($entPhysical)) {
|
||||
$db_state = $db_states[$id];
|
||||
$update = array_diff($state, $db_state);
|
||||
|
||||
if (!empty($update)) {
|
||||
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 {
|
||||
@ -84,11 +83,11 @@ if (!empty($entPhysical)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($state_data)) {
|
||||
if (! empty($state_data)) {
|
||||
dbBulkInsert($state_data, 'entityState');
|
||||
}
|
||||
|
||||
if (!empty($db_states)) {
|
||||
if (! empty($db_states)) {
|
||||
dbDelete(
|
||||
'entityState',
|
||||
'entity_state_id IN ' . dbGenPlaceholders(count($db_states)),
|
||||
|
@ -3,23 +3,23 @@
|
||||
// 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;
|
||||
$existing_fdbs[(int) $entry['vlan_id']][$entry['mac_address']] = $entry;
|
||||
}
|
||||
|
||||
$insert = []; // populate $insert with database entries
|
||||
if (file_exists(Config::get('install_dir') . "/includes/discovery/fdb-table/{$device['os']}.inc.php")) {
|
||||
require Config::get('install_dir') . "/includes/discovery/fdb-table/{$device['os']}.inc.php";
|
||||
} elseif ($device['os'] == 'ios' || $device['os'] == 'iosxe'|| $device['os'] == 'nxos') {
|
||||
} elseif ($device['os'] == 'ios' || $device['os'] == 'iosxe' || $device['os'] == 'nxos') {
|
||||
//ios,iosxe,nxos are all Cisco
|
||||
include Config::get('install_dir') . '/includes/discovery/fdb-table/ios.inc.php';
|
||||
}
|
||||
@ -29,7 +29,7 @@ if (empty($insert)) {
|
||||
include Config::get('install_dir') . '/includes/discovery/fdb-table/bridge.inc.php';
|
||||
}
|
||||
|
||||
if (!empty($insert)) {
|
||||
if (! empty($insert)) {
|
||||
$update_time_only = [];
|
||||
$now = \Carbon\Carbon::now();
|
||||
// synchronize with the database
|
||||
@ -62,7 +62,7 @@ if (!empty($insert)) {
|
||||
// If $entry['port_id'] truly is null then Illuminate throws a fatal errory and all subsequent processing stops.
|
||||
// Cisco ISO (and others) may have null ids. We still want them inserted as new
|
||||
// strings work with DB::table->insert().
|
||||
$entry['port_id']='';
|
||||
$entry['port_id'] = '';
|
||||
}
|
||||
|
||||
DB::table('ports_fdb')->insert([
|
||||
|
@ -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');
|
||||
if (!empty($dot1d)) {
|
||||
$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)) {
|
||||
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']);
|
||||
|
@ -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');
|
||||
if (!empty($dot1d)) {
|
||||
$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))];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,22 +28,22 @@
|
||||
// Try Q-BRIDGE-MIB::dot1qTpFdbPort first
|
||||
|
||||
$fdbPort_table = snmpwalk_group($device, 'dot1qTpFdbPort', 'Q-BRIDGE-MIB');
|
||||
if (!empty($fdbPort_table)) {
|
||||
if (! empty($fdbPort_table)) {
|
||||
echo 'Q-BRIDGE-MIB:';
|
||||
$data_oid = 'dot1qTpFdbPort';
|
||||
} else {
|
||||
// If we don't have Q-BRIDGE-MIB::dot1qTpFdbPort, try BRIDGE-MIB::dot1dTpFdbPort
|
||||
$dot1d = snmpwalk_group($device, 'dot1dTpFdbPort', 'BRIDGE-MIB', 0);
|
||||
$data_oid = 'dot1dTpFdbPort';
|
||||
if (!empty($dot1d)) {
|
||||
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)) {
|
||||
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) {
|
||||
|
@ -26,31 +26,31 @@
|
||||
|
||||
// Try Q-BRIDGE-MIB::dot1qTpFdbPort first
|
||||
$fdbPort_table = snmpwalk_group($device, 'dot1qTpFdbPort', 'Q-BRIDGE-MIB');
|
||||
if (!empty($fdbPort_table)) {
|
||||
if (! empty($fdbPort_table)) {
|
||||
echo 'Q-BRIDGE-MIB:';
|
||||
$data_oid = 'dot1qTpFdbPort';
|
||||
} else {
|
||||
// If we don't have Q-BRIDGE-MIB::dot1qTpFdbPort, try BRIDGE-MIB::dot1dTpFdbPort
|
||||
$dot1d = snmpwalk_group($device, 'dot1dTpFdbPort', 'BRIDGE-MIB', 0);
|
||||
$data_oid = 'dot1dTpFdbPort';
|
||||
if (!empty($dot1d)) {
|
||||
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)) {
|
||||
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']);
|
||||
$portid_dict[$portLocal] = $port['port_id'];
|
||||
}
|
||||
|
||||
|
||||
// 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) {
|
||||
@ -67,7 +67,7 @@ if (!empty($fdbPort_table)) {
|
||||
// index *is* the VLAN number. Code in fdb-table.inc.php to map to the
|
||||
// device VLANs table should catch anything invalid.
|
||||
$vlan = isset($vlan_fdb_dict[$vlanIndex]) ? $vlan_fdb_dict[$vlanIndex] : $vlanIndex;
|
||||
|
||||
|
||||
foreach ($data[$data_oid] as $mac => $dot1dBasePort) {
|
||||
if ($dot1dBasePort == 0) {
|
||||
d_echo("No port known for $mac\n");
|
||||
|
@ -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) {
|
||||
|
@ -1,36 +1,36 @@
|
||||
<?php
|
||||
|
||||
$vtpdomains = snmpwalk_group($device, 'managementDomainName', 'CISCO-VTP-MIB');
|
||||
$vlans = snmpwalk_group($device, 'vtpVlanEntry', 'CISCO-VTP-MIB', 2);
|
||||
$vlans = snmpwalk_group($device, 'vtpVlanEntry', 'CISCO-VTP-MIB', 2);
|
||||
|
||||
foreach ($vtpdomains as $vtpdomain_id => $vtpdomain) {
|
||||
echo "VTP Domain $vtpdomain_id {$vtpdomain['managementDomainName']}> ";
|
||||
foreach ($vlans[$vtpdomain_id] as $vlan_raw => $vlan) {
|
||||
echo "$vlan_raw ";
|
||||
if (!array_key_exists($vlan_raw, $vlans_dict)) {
|
||||
$newvlan_id = dbInsert(array(
|
||||
if (! array_key_exists($vlan_raw, $vlans_dict)) {
|
||||
$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']);
|
||||
$portid_dict[$portLocal] = $port['port_id'];
|
||||
}
|
||||
|
||||
foreach ((array)$fdbPort_table['dot1dTpFdbPort'] as $mac => $dot1dBasePort) {
|
||||
foreach ((array) $fdbPort_table['dot1dTpFdbPort'] as $mac => $dot1dBasePort) {
|
||||
$mac_address = implode(array_map('zeropad', explode(':', $mac)));
|
||||
if (strlen($mac_address) != 12) {
|
||||
d_echo("MAC address padding failed for $mac\n");
|
||||
|
@ -16,13 +16,13 @@
|
||||
|
||||
$fdbPort_table = snmpwalk_group($device, 'hwDynFdbPort', 'HUAWEI-L2MAM-MIB');
|
||||
|
||||
if (!empty($fdbPort_table)) {
|
||||
echo 'HUAWEI-L2MAM-MIB:'.PHP_EOL;
|
||||
if (! empty($fdbPort_table)) {
|
||||
echo 'HUAWEI-L2MAM-MIB:' . PHP_EOL;
|
||||
$data_oid = 'hwDynFdbPort';
|
||||
// Collect data and populate $insert
|
||||
foreach ($fdbPort_table as $mac => $data) {
|
||||
foreach ($data[$data_oid] as $vlan => $basePort) {
|
||||
$ifIndex=reset($basePort); // $baseport can be ['' => '119'] or ['0' => '119']
|
||||
$ifIndex = reset($basePort); // $baseport can be ['' => '119'] or ['0' => '119']
|
||||
if (! $ifIndex) {
|
||||
continue;
|
||||
}
|
||||
|
@ -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 = '')
|
||||
{
|
||||
@ -27,7 +27,7 @@ function discover_new_device($hostname, $device = '', $method = '', $interface =
|
||||
|
||||
if (IP::isValid($hostname)) {
|
||||
$ip = $hostname;
|
||||
if (!Config::get('discovery_by_ip', false)) {
|
||||
if (! Config::get('discovery_by_ip', false)) {
|
||||
d_echo('Discovery by IP disabled, skipping ' . $hostname);
|
||||
log_event("$method discovery of " . $hostname . " failed - Discovery by IP disabled", $device['device_id'], 'discovery', 4);
|
||||
|
||||
@ -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'))) {
|
||||
if (! $ip->inNetworks(Config::get('nets'))) {
|
||||
d_echo("$ip not in a matched network - skipping\n");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -75,7 +78,7 @@ function discover_new_device($hostname, $device = '', $method = '', $interface =
|
||||
discover_device($remote_device);
|
||||
device_by_id_cache($remote_device_id, 1);
|
||||
|
||||
if ($remote_device_id && is_array($device) && !empty($method)) {
|
||||
if ($remote_device_id && is_array($device) && ! empty($method)) {
|
||||
$extra_log = '';
|
||||
$int = cleanPort($interface);
|
||||
if (is_array($int)) {
|
||||
@ -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");
|
||||
@ -151,8 +154,8 @@ function discover_device(&$device, $force_module = false)
|
||||
d_echo("Device" . (isset($attribs['discover_' . $module]) ? ($attribs['discover_' . $module] ? '+ ' : '- ') : ' '));
|
||||
if ($force_module === true ||
|
||||
$attribs['discover_' . $module] ||
|
||||
($os_module_status && !isset($attribs['discover_' . $module])) ||
|
||||
($module_status && !isset($os_module_status) && !isset($attribs['discover_' . $module]))
|
||||
($os_module_status && ! isset($attribs['discover_' . $module])) ||
|
||||
($module_status && ! isset($os_module_status) && ! isset($attribs['discover_' . $module]))
|
||||
) {
|
||||
$module_start = microtime(true);
|
||||
$start_memory = memory_get_usage();
|
||||
@ -162,7 +165,7 @@ function discover_device(&$device, $force_module = false)
|
||||
include "includes/discovery/$module.inc.php";
|
||||
} catch (Exception $e) {
|
||||
// isolate module exceptions so they don't disrupt the polling process
|
||||
echo $e->getTraceAsString() .PHP_EOL;
|
||||
echo $e->getTraceAsString() . PHP_EOL;
|
||||
c_echo("%rError in $module module.%n " . $e->getMessage() . PHP_EOL);
|
||||
logfile("Error in $module module. " . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL);
|
||||
}
|
||||
@ -182,13 +185,14 @@ function discover_device(&$device, $force_module = false)
|
||||
}
|
||||
}
|
||||
|
||||
$device_time = round(microtime(true) - $device_start, 3);
|
||||
$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()
|
||||
@ -196,15 +200,15 @@ function discover_device(&$device, $force_module = false)
|
||||
// Discover sensors
|
||||
function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = 1, $multiplier = 1, $low_limit = null, $low_warn_limit = null, $warn_limit = null, $high_limit = null, $current = null, $poller_type = 'snmp', $entPhysicalIndex = null, $entPhysicalIndex_measured = null, $user_func = null, $group = null)
|
||||
{
|
||||
$guess_limits = Config::get('sensors.guess_limits', true);
|
||||
$guess_limits = Config::get('sensors.guess_limits', true);
|
||||
|
||||
$low_limit = set_null($low_limit);
|
||||
$low_limit = set_null($low_limit);
|
||||
$low_warn_limit = set_null($low_warn_limit);
|
||||
$warn_limit = set_null($warn_limit);
|
||||
$high_limit = set_null($high_limit);
|
||||
$warn_limit = set_null($warn_limit);
|
||||
$high_limit = set_null($high_limit);
|
||||
|
||||
if (!is_numeric($divisor)) {
|
||||
$divisor = 1;
|
||||
if (! is_numeric($divisor)) {
|
||||
$divisor = 1;
|
||||
}
|
||||
if (can_skip_sensor($device, $class, $descr)) {
|
||||
return false;
|
||||
@ -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);
|
||||
}
|
||||
@ -226,12 +230,12 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
|
||||
$low_limit = sensor_low_limit($class, $current);
|
||||
}
|
||||
|
||||
if (!is_null($high_limit) && $low_limit > $high_limit) {
|
||||
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,10 +254,10 @@ 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)) {
|
||||
if (! isset($val_check)) {
|
||||
unset($insert[$key]);
|
||||
}
|
||||
}
|
||||
@ -265,10 +269,10 @@ 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']) {
|
||||
if (! isset($high_limit)) {
|
||||
if ($guess_limits && ! $sensor_entry['sensor_limit']) {
|
||||
// Calculate a reasonable limit
|
||||
$high_limit = sensor_limit($class, $current);
|
||||
} else {
|
||||
@ -277,8 +281,8 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($low_limit)) {
|
||||
if ($guess_limits && !$sensor_entry['sensor_limit_low']) {
|
||||
if (! isset($low_limit)) {
|
||||
if ($guess_limits && ! $sensor_entry['sensor_limit_low']) {
|
||||
// Calculate a reasonable limit
|
||||
$low_limit = sensor_low_limit($class, $current);
|
||||
} else {
|
||||
@ -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) {
|
||||
@ -451,12 +455,12 @@ function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp')
|
||||
$class = $entry['sensor_class'];
|
||||
d_echo($index . ' -> ' . $type . "\n");
|
||||
|
||||
if (!$valid[$class][$type][$index]) {
|
||||
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,26 +499,26 @@ 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,
|
||||
)
|
||||
[
|
||||
$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,
|
||||
'remote_hostname' => $remote_hostname,
|
||||
'remote_device_id' => (int)$remote_device_id,
|
||||
'remote_device_id' => (int) $remote_device_id,
|
||||
'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;
|
||||
if (! empty($remote_port_id)) {
|
||||
$insert_data['remote_port_id'] = (int) $remote_port_id;
|
||||
}
|
||||
|
||||
$inserted = dbInsert($insert_data, 'links');
|
||||
@ -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_device_id' => (int) $remote_device_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,8 +561,8 @@ 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));
|
||||
if ($storage === false || !count($storage)) {
|
||||
$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');
|
||||
} else {
|
||||
@ -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,23 +615,23 @@ 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;
|
||||
$insert_data['hrDeviceIndex'] = (int) $hrDeviceIndex;
|
||||
$insert_data['entPhysicalIndex'] = (int) $entPhysicalIndex;
|
||||
|
||||
$inserted = dbInsert($insert_data, 'processors');
|
||||
echo '+';
|
||||
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,8 +741,8 @@ function discover_entity_physical(&$valid, $device, $entPhysicalIndex, $entPhysi
|
||||
'entPhysicalIsFRU' => $entPhysicalIsFRU,
|
||||
'entPhysicalAlias' => $entPhysicalAlias,
|
||||
'entPhysicalAssetID' => $entPhysicalAssetID,
|
||||
);
|
||||
if (!empty($ifIndex)) {
|
||||
];
|
||||
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
|
||||
@ -779,7 +782,7 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
|
||||
{
|
||||
global $device;
|
||||
|
||||
if (!IPv6::isValid($ipv6_address, true)) {
|
||||
if (! IPv6::isValid($ipv6_address, true)) {
|
||||
// ignore link-locals (coming from IPV6-MIB)
|
||||
return;
|
||||
}
|
||||
@ -788,36 +791,36 @@ 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 '+';
|
||||
} else if (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') {
|
||||
} 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
|
||||
if ($context_name == null) {
|
||||
$ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` IS NULL', [$ipv6_network]);
|
||||
@ -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,10 +899,11 @@ 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') {
|
||||
if ($sensor_type == 'voltage' && !Str::startsWith($oid, '.1.3.6.1.2.1.33.1.2.5.') && !Str::startsWith($oid, '.1.3.6.1.2.1.33.1.3.3.1.3')) {
|
||||
if ($sensor_type == 'voltage' && ! Str::startsWith($oid, '.1.3.6.1.2.1.33.1.2.5.') && ! Str::startsWith($oid, '.1.3.6.1.2.1.33.1.3.3.1.3')) {
|
||||
return 1;
|
||||
}
|
||||
} elseif ($device['os'] == 'apc-mgeups') {
|
||||
@ -913,7 +918,7 @@ function get_device_divisor($device, $os_version, $sensor_type, $oid)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($sensor_type == 'voltage' && !Str::startsWith($oid, '.1.3.6.1.2.1.33.1.2.5.')) {
|
||||
if ($sensor_type == 'voltage' && ! Str::startsWith($oid, '.1.3.6.1.2.1.33.1.2.5.')) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -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'];
|
||||
}
|
||||
@ -999,7 +1008,7 @@ function discovery_process(&$valid, $device, $sensor_class, $pre_cache)
|
||||
|
||||
foreach ($device['dynamic_discovery']['modules']['sensors'][$sensor_class]['data'] as $data) {
|
||||
$tmp_name = $data['oid'];
|
||||
$raw_data = (array)$pre_cache[$tmp_name];
|
||||
$raw_data = (array) $pre_cache[$tmp_name];
|
||||
|
||||
d_echo("Data $tmp_name: ");
|
||||
d_echo($raw_data);
|
||||
@ -1013,15 +1022,15 @@ function discovery_process(&$valid, $device, $sensor_class, $pre_cache)
|
||||
$data_name = isset($data['value']) ? $data['value'] : $data['oid']; // fallback to oid if value is not set
|
||||
|
||||
$snmp_value = $snmp_data[$data_name];
|
||||
if (!is_numeric($snmp_value)) {
|
||||
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';
|
||||
}
|
||||
}
|
||||
preg_match('/-?\d*\.?\d+/', $snmp_value, $temp_response);
|
||||
if (!empty($temp_response[0])) {
|
||||
if (! empty($temp_response[0])) {
|
||||
$snmp_value = $temp_response[0];
|
||||
}
|
||||
}
|
||||
@ -1069,7 +1078,7 @@ function discovery_process(&$valid, $device, $sensor_class, $pre_cache)
|
||||
}
|
||||
}
|
||||
|
||||
echo "Cur $value, Low: $low_limit, Low Warn: $low_warn_limit, Warn: $warn_limit, High: $high_limit".PHP_EOL;
|
||||
echo "Cur $value, Low: $low_limit, Low Warn: $low_warn_limit, Warn: $warn_limit, High: $high_limit" . PHP_EOL;
|
||||
$entPhysicalIndex = YamlDiscovery::replaceValues('entPhysicalIndex', $index, null, $data, $pre_cache) ?: null;
|
||||
$entPhysicalIndex_measured = isset($data['entPhysicalIndex_measured']) ? $data['entPhysicalIndex_measured'] : null;
|
||||
|
||||
@ -1105,11 +1114,11 @@ 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) {
|
||||
foreach ((array) $types as $sensor_class) {
|
||||
echo ucfirst($sensor_class) . ': ';
|
||||
$dir = Config::get('install_dir') . '/includes/discovery/sensors/' . $sensor_class .'/';
|
||||
$dir = Config::get('install_dir') . '/includes/discovery/sensors/' . $sensor_class . '/';
|
||||
|
||||
if (is_file($dir . $device['os_group'] . '.inc.php')) {
|
||||
include $dir . $device['os_group'] . '.inc.php';
|
||||
@ -1118,7 +1127,7 @@ function sensors($types, $device, $valid, $pre_cache = array())
|
||||
include $dir . $device['os'] . '.inc.php';
|
||||
}
|
||||
if (Config::getOsSetting($device['os'], 'rfc1628_compat', false)) {
|
||||
if (is_file($dir . '/rfc1628.inc.php')) {
|
||||
if (is_file($dir . '/rfc1628.inc.php')) {
|
||||
include $dir . '/rfc1628.inc.php';
|
||||
}
|
||||
}
|
||||
@ -1132,29 +1141,29 @@ 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));
|
||||
if ($octets > 11) {
|
||||
// ipv6
|
||||
$peer_ip = (string)IP::parse(snmp2ipv6($peer_ip), true);
|
||||
$peer_ip = (string) IP::parse(snmp2ipv6($peer_ip), true);
|
||||
} else {
|
||||
// ipv4
|
||||
$peer_ip = implode('.', array_slice(explode('.', $peer_ip), -4));
|
||||
@ -1168,62 +1177,63 @@ 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");
|
||||
|
||||
$afisafi_tmp = explode('.', $k);
|
||||
if ($device['os_group'] === 'vrp') {
|
||||
$vpninst_id = array_shift($afisafi_tmp);
|
||||
$afi = array_shift($afisafi_tmp);
|
||||
$safi = array_shift($afisafi_tmp);
|
||||
$peertype = array_shift($afisafi_tmp);
|
||||
$bgp_ip = implode('.', $afisafi_tmp);
|
||||
$vpninst_id = array_shift($afisafi_tmp);
|
||||
$afi = array_shift($afisafi_tmp);
|
||||
$safi = array_shift($afisafi_tmp);
|
||||
$peertype = array_shift($afisafi_tmp);
|
||||
$bgp_ip = implode('.', $afisafi_tmp);
|
||||
} else {
|
||||
$safi = array_pop($afisafi_tmp);
|
||||
$afi = array_pop($afisafi_tmp);
|
||||
$bgp_ip = str_replace(".$afi.$safi", '', $k);
|
||||
$safi = array_pop($afisafi_tmp);
|
||||
$afi = array_pop($afisafi_tmp);
|
||||
$bgp_ip = str_replace(".$afi.$safi", '', $k);
|
||||
if ($device['os_group'] === 'arista') {
|
||||
$bgp_ip = str_replace("$afi.", '', $bgp_ip);
|
||||
$bgp_ip = str_replace("$afi.", '', $bgp_ip);
|
||||
}
|
||||
}
|
||||
$bgp_ip = preg_replace('/:/', ' ', $bgp_ip);
|
||||
$bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip);
|
||||
$bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip));
|
||||
$bgp_ip = preg_replace('/:/', ' ', $bgp_ip);
|
||||
$bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip);
|
||||
$bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip));
|
||||
|
||||
if ($afi && $safi && $bgp_ip == $peer['ip']) {
|
||||
$af_list[$bgp_ip][$afi][$safi] = 1;
|
||||
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
|
||||
@ -1315,27 +1325,30 @@ function can_skip_sensor($device, $sensor_class = '', $sensor_descr = '')
|
||||
function can_skip_discovery($sysName, $sysDescr = '', $platform = '')
|
||||
{
|
||||
if ($sysName) {
|
||||
foreach ((array)Config::get('autodiscovery.xdp_exclude.sysname_regexp') as $needle) {
|
||||
if (preg_match($needle .'i', $sysName)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($sysDescr) {
|
||||
foreach ((array)Config::get('autodiscovery.xdp_exclude.sysdesc_regexp') as $needle) {
|
||||
if (preg_match($needle .'i', $sysDescr)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($platform) {
|
||||
foreach ((array)Config::get('autodiscovery.cdp_exclude.platform_regexp') as $needle) {
|
||||
if (preg_match($needle .'i', $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`=?';
|
||||
@ -1384,22 +1397,22 @@ function find_device_id($name = '', $ip = '', $mac_address = '')
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($where)) {
|
||||
if (! empty($where)) {
|
||||
$sql = 'SELECT `device_id` FROM `devices` WHERE ' . implode(' OR ', $where);
|
||||
if ($device_id = dbFetchCell($sql, $params)) {
|
||||
return (int)$device_id;
|
||||
return (int) $device_id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($mac_address && $mac_address != '000000000000') {
|
||||
if ($device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE `ifPhysAddress`=?', array($mac_address))) {
|
||||
return (int)$device_id;
|
||||
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;
|
||||
@ -1416,7 +1429,7 @@ function find_device_id($name = '', $ip = '', $mac_address = '')
|
||||
$sql = 'SELECT `device_id` FROM `devices` WHERE ' . implode(' OR ', $where) . ' LIMIT 2';
|
||||
$ids = dbFetchColumn($sql, $params);
|
||||
if (count($ids) == 1) {
|
||||
return (int)$ids[0];
|
||||
return (int) $ids[0];
|
||||
} elseif (count($ids) > 1) {
|
||||
d_echo("find_device_id: more than one device found with sysName '$name'.\n");
|
||||
// don't do anything, try other methods, if any
|
||||
@ -1437,12 +1450,12 @@ function find_device_id($name = '', $ip = '', $mac_address = '')
|
||||
*/
|
||||
function find_port_id($description, $identifier = '', $device_id = 0, $mac_address = null)
|
||||
{
|
||||
if (!($device_id || $mac_address)) {
|
||||
if (! ($device_id || $mac_address)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$statements = array();
|
||||
$params = array();
|
||||
$statements = [];
|
||||
$params = [];
|
||||
|
||||
if ($device_id) {
|
||||
if ($description) {
|
||||
@ -1489,5 +1502,5 @@ function find_port_id($description, $identifier = '', $device_id = 0, $mac_addre
|
||||
$queries = implode(' UNION ', $statements);
|
||||
$sql = "SELECT * FROM ($queries LIMIT 1) p";
|
||||
|
||||
return (int)dbFetchCell($sql, $params);
|
||||
return (int) dbFetchCell($sql, $params);
|
||||
}
|
||||
|
@ -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");
|
||||
@ -41,12 +41,12 @@ if (is_array($hrDevices)) {
|
||||
}//end foreach
|
||||
}//end if
|
||||
|
||||
$sql = "SELECT * FROM `hrDevice` WHERE `device_id` = '".$device['device_id']."'";
|
||||
$sql = "SELECT * FROM `hrDevice` WHERE `device_id` = '" . $device['device_id'] . "'";
|
||||
|
||||
foreach (dbFetchRows($sql) as $test_hrDevice) {
|
||||
if (!$valid_hrDevice[$test_hrDevice['hrDeviceIndex']]) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +1,59 @@
|
||||
<?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)) {
|
||||
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'];
|
||||
$device['context_name'] = $vrf['context_name'];
|
||||
|
||||
$oids = trim(snmp_walk($device, 'ipAdEntIfIndex', '-Osq', 'IP-MIB'));
|
||||
$oids = str_replace('ipAdEntIfIndex.', '', $oids);
|
||||
foreach (explode("\n", $oids) as $data) {
|
||||
$data = trim($data);
|
||||
list($oid,$ifIndex) = explode(' ', $data);
|
||||
$mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB'));
|
||||
$cidr = IPv4::netmask2cidr($mask);
|
||||
$data = trim($data);
|
||||
[$oid,$ifIndex] = explode(' ', $data);
|
||||
$mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB'));
|
||||
$cidr = IPv4::netmask2cidr($mask);
|
||||
try {
|
||||
$ipv4 = new IPv4("$oid/$cidr");
|
||||
$ipv4 = new IPv4("$oid/$cidr");
|
||||
} catch (InvalidIpException $e) {
|
||||
continue;
|
||||
}
|
||||
$network = $ipv4->getNetworkAddress() . '/' . $ipv4->cidr;
|
||||
$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) {
|
||||
$full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex'];
|
||||
foreach (dbFetchRows($sql, [$device['device_id']]) as $row) {
|
||||
$full_address = $row['ipv4_address'] . '/' . $row['ipv4_prefixlen'] . '|' . $row['ifIndex'];
|
||||
|
||||
if (!$valid_v4[$full_address]) {
|
||||
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']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) {
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
} else {
|
||||
$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'];
|
||||
$device['context_name'] = $vrf['context_name'];
|
||||
|
||||
$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', ['-Osq', '-Ln'], 'IP-MIB');
|
||||
$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids);
|
||||
@ -16,22 +16,22 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
|
||||
foreach (explode("\n", $oids) as $data) {
|
||||
if ($data) {
|
||||
$data = trim($data);
|
||||
list($ipv6addr,$ifIndex) = explode(' ', $data);
|
||||
$oid = '';
|
||||
$sep = '';
|
||||
$data = trim($data);
|
||||
[$ipv6addr,$ifIndex] = explode(' ', $data);
|
||||
$oid = '';
|
||||
$sep = '';
|
||||
$adsep = '';
|
||||
unset($ipv6_address);
|
||||
$do = '0';
|
||||
foreach (explode(':', $ipv6addr) as $part) {
|
||||
$n = hexdec($part);
|
||||
$oid = "$oid"."$sep"."$n";
|
||||
$sep = '.';
|
||||
$ipv6_address = $ipv6_address."$adsep".$part;
|
||||
$n = hexdec($part);
|
||||
$oid = "$oid" . "$sep" . "$n";
|
||||
$sep = '.';
|
||||
$ipv6_address = $ipv6_address . "$adsep" . $part;
|
||||
$do++;
|
||||
if ($do == 2) {
|
||||
$adsep = ':';
|
||||
$do = '0';
|
||||
$do = '0';
|
||||
} else {
|
||||
$adsep = '';
|
||||
}
|
||||
@ -45,7 +45,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
d_echo('Incomplete IPv6 data in IF-MIB');
|
||||
$oids = trim(Str::replaceFirst($data, '', $oids));
|
||||
}
|
||||
|
||||
|
||||
$ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB');
|
||||
|
||||
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']);
|
||||
@ -61,10 +61,10 @@ 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');
|
||||
$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']);
|
||||
} //end if
|
||||
} //end foreach
|
||||
@ -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) {
|
||||
$full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen'];
|
||||
$port_id = $row['port_id'];
|
||||
$valid_address = $full_address.'-'.$port_id;
|
||||
if (!$valid['ipv6'][$valid_address]) {
|
||||
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']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
@ -25,18 +25,18 @@ if ($device['os'] == 'junose' && Config::get('enable_ports_junoseatmvp')) {
|
||||
unset($vp_array);
|
||||
|
||||
// Remove ATM vps which weren't redetected here
|
||||
$sql = "SELECT * FROM `ports` AS P, `juniAtmVp` AS J WHERE P.`device_id` = '".$device['device_id']."' AND J.port_id = P.port_id";
|
||||
$sql = "SELECT * FROM `ports` AS P, `juniAtmVp` AS J WHERE P.`device_id` = '" . $device['device_id'] . "' AND J.port_id = P.port_id";
|
||||
|
||||
d_echo($valid_vp);
|
||||
|
||||
foreach (dbFetchRows($sql) as $test) {
|
||||
$port_id = $test['port_id'];
|
||||
$vp_id = $test['vp_id'];
|
||||
d_echo($port_id.' -> '.$vp_id."\n");
|
||||
$vp_id = $test['vp_id'];
|
||||
d_echo($port_id . ' -> ' . $vp_id . "\n");
|
||||
|
||||
if (!$valid_vp[$port_id][$vp_id]) {
|
||||
if (! $valid_vp[$port_id][$vp_id]) {
|
||||
echo '-';
|
||||
dbDelete('juniAtmvp', '`juniAtmVp` = ?', array($test['juniAtmvp']));
|
||||
dbDelete('juniAtmvp', '`juniAtmVp` = ?', [$test['juniAtmvp']]);
|
||||
}
|
||||
|
||||
unset($port_id);
|
||||
|
@ -6,43 +6,43 @@ 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;
|
||||
|
||||
$userHostname = $device['hostname'];
|
||||
if (Config::has('libvirt_username')) {
|
||||
$userHostname = Config::get('libvirt_username').'@'.$userHostname;
|
||||
$userHostname = Config::get('libvirt_username') . '@' . $userHostname;
|
||||
}
|
||||
|
||||
foreach (Config::get('libvirt_protocols') as $method) {
|
||||
if (Str::contains($method, 'qemu')) {
|
||||
$uri = $method.'://'.$userHostname.'/system';
|
||||
$uri = $method . '://' . $userHostname . '/system';
|
||||
} else {
|
||||
$uri = $method.'://'.$userHostname;
|
||||
$uri = $method . '://' . $userHostname;
|
||||
}
|
||||
|
||||
if (Str::contains($method, 'ssh') && !$ssh_ok) {
|
||||
if (Str::contains($method, 'ssh') && ! $ssh_ok) {
|
||||
// Check if we are using SSH if we can log in without password - without blocking the discovery
|
||||
// Also automatically add the host key so discovery doesn't block on the yes/no question, and run echo so we don't get stuck in a remote shell ;-)
|
||||
exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" '.$userHostname.' echo -e', $out, $ret);
|
||||
exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" ' . $userHostname . ' echo -e', $out, $ret);
|
||||
if ($ret != 255) {
|
||||
$ssh_ok = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ssh_ok || !Str::contains($method, 'ssh')) {
|
||||
if ($ssh_ok || ! Str::contains($method, 'ssh')) {
|
||||
// Fetch virtual machine list
|
||||
unset($domlist);
|
||||
exec(Config::get('virsh').' -rc '.$uri.' list', $domlist);
|
||||
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.
|
||||
unset($vm_info_array);
|
||||
exec(Config::get('virsh').' -rc '.$uri.' dumpxml '.$dom_id, $vm_info_array);
|
||||
exec(Config::get('virsh') . ' -rc ' . $uri . ' dumpxml ' . $dom_id, $vm_info_array);
|
||||
|
||||
// Example xml:
|
||||
// <domain type='kvm' id='3'>
|
||||
@ -66,18 +66,18 @@ if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
|
||||
$vm_info_xml .= $line;
|
||||
}
|
||||
|
||||
$xml = simplexml_load_string('<?xml version="1.0"?> '.$vm_info_xml);
|
||||
$xml = simplexml_load_string('<?xml version="1.0"?> ' . $vm_info_xml);
|
||||
d_echo($xml);
|
||||
|
||||
$vmwVmDisplayName = $xml->name;
|
||||
$vmwVmGuestOS = '';
|
||||
$vmwVmGuestOS = '';
|
||||
// libvirt does not supply this
|
||||
exec(Config::get('virsh').' -rc '.$uri.' domstate '.$dom_id, $vm_state);
|
||||
exec(Config::get('virsh') . ' -rc ' . $uri . ' domstate ' . $dom_id, $vm_state);
|
||||
$vmwVmState = ucfirst($vm_state[0]);
|
||||
|
||||
$vmwVmCpus = $xml->vcpu['current'];
|
||||
if (!isset($vmwVmCpus)) {
|
||||
$vmwVmCpus = $xml->vcpu;
|
||||
$vmwVmCpus = $xml->vcpu['current'];
|
||||
if (! isset($vmwVmCpus)) {
|
||||
$vmwVmCpus = $xml->vcpu;
|
||||
}
|
||||
$vmwVmMemSize = $xml->memory;
|
||||
// Convert memory size to MiB
|
||||
@ -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,9 +128,9 @@ 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
|
||||
// FIXME eventlog
|
||||
} else {
|
||||
echo '.';
|
||||
}
|
||||
@ -149,12 +149,12 @@ if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
|
||||
}//end foreach
|
||||
|
||||
// Get a list of all the known Virtual Machines for this host.
|
||||
$sql = "SELECT id, vmwVmVMID, vmwVmDisplayName FROM vminfo WHERE device_id = '".$device['device_id']."' AND vm_type='libvirt'";
|
||||
$sql = "SELECT id, vmwVmVMID, vmwVmDisplayName FROM vminfo WHERE device_id = '" . $device['device_id'] . "' AND vm_type='libvirt'";
|
||||
|
||||
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']));
|
||||
if (! in_array($db_vm['vmwVmVMID'], $libvirt_vmlist)) {
|
||||
dbDelete('vminfo', '`id` = ?', [$db_vm['id']]);
|
||||
echo '-';
|
||||
log_event('Virtual Machine removed: ' . $db_vm['vmwVmDisplayName'], $device, 'vm', 4, $db_vm['id']);
|
||||
}
|
||||
|
@ -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,11 +43,11 @@ 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);
|
||||
if (!is_null($gtmWideIPEntry)) {
|
||||
if (! is_null($gtmWideIPEntry)) {
|
||||
$gtmWideStatusEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.3.12.3.2.1', 0);
|
||||
$gtmPoolEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.3.6.2.3.1.1', 0);
|
||||
}
|
||||
@ -58,48 +58,48 @@ if ((snmp_get($device, 'sysModuleAllocationProvisionLevel.3.103.116.109', '-Ovqs
|
||||
* null == timeout or something else that caused an error, OID may exist but we couldn't get it.
|
||||
*/
|
||||
|
||||
if (!is_null($gtmWideIPEntry) || !is_null($gtmWideStatusEntry) || !is_null($gtmPoolEntry)) {
|
||||
if (! is_null($gtmWideIPEntry) || ! is_null($gtmWideStatusEntry) || ! is_null($gtmPoolEntry)) {
|
||||
// No Nulls, lets go....
|
||||
d_echo("Objects Found:\n");
|
||||
|
||||
// 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['UID'] = (string) $index;
|
||||
$result['label'] = $value;
|
||||
// The UID is far too long to have in a RRD filename, use a hash of it instead.
|
||||
$result['hash'] = hash('crc32', $result['UID']);
|
||||
|
||||
// Now that we have our UID we can pull all the other data we need.
|
||||
// 0 = None, 1 = Green, 2 = Yellow, 3 = Red, 4 = Blue
|
||||
$result['state'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.2.'.$index];
|
||||
$result['state'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.2.' . $index];
|
||||
if ($result['state'] == 2) {
|
||||
// Looks like one of the VS Pool members is down.
|
||||
$result['status'] = 1;
|
||||
$result['error'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.5.'.$index];
|
||||
$result['error'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.5.' . $index];
|
||||
} elseif ($result['state'] == 3) {
|
||||
// Looks like ALL of the VS Pool members is down.
|
||||
$result['status'] = 2;
|
||||
$result['error'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.5.'.$index];
|
||||
$result['error'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.5.' . $index];
|
||||
} else {
|
||||
// All is good.
|
||||
$result['status'] = 0;
|
||||
$result['error'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.5.'.$index];
|
||||
$result['error'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.5.' . $index];
|
||||
}
|
||||
}
|
||||
|
||||
// Do we have any results
|
||||
if (count($result) > 0) {
|
||||
// Let's log some debugging
|
||||
d_echo("\n\n".$result['type'].": ".$result['label']."\n");
|
||||
d_echo(" Status: ".$result['status']."\n");
|
||||
d_echo(" Message: ".$result['error']."\n");
|
||||
d_echo("\n\n" . $result['type'] . ": " . $result['label'] . "\n");
|
||||
d_echo(" Status: " . $result['status'] . "\n");
|
||||
d_echo(" Message: " . $result['error'] . "\n");
|
||||
|
||||
// Add this result to the master array.
|
||||
$tblBigIP[] = $result;
|
||||
@ -110,13 +110,13 @@ 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['UID'] = (string) $index;
|
||||
$result['label'] = $value;
|
||||
// The UID is far too long to have in a RRD filename, use a hash of it instead.
|
||||
$result['hash'] = hash('crc32', $result['UID']);
|
||||
@ -125,7 +125,7 @@ if (!is_null($gtmWideIPEntry) || !is_null($gtmWideStatusEntry) || !is_null($gtmP
|
||||
// Do we have any results
|
||||
if (count($result) > 0) {
|
||||
// Let's log some debugging
|
||||
d_echo("\n\n".$result['type'].": ".$result['label']."\n");
|
||||
d_echo("\n\n" . $result['type'] . ": " . $result['label'] . "\n");
|
||||
|
||||
// Add this result to the master array.
|
||||
$tblBigIP[] = $result;
|
||||
@ -148,7 +148,7 @@ if (!is_null($gtmWideIPEntry) || !is_null($gtmWideStatusEntry) || !is_null($gtmP
|
||||
}
|
||||
}
|
||||
|
||||
if (!$component_key) {
|
||||
if (! $component_key) {
|
||||
// The component doesn't exist, we need to ADD it - ADD.
|
||||
$new_component = $component->createComponent($device['device_id'], $array['type']);
|
||||
$component_key = key($new_component);
|
||||
|
@ -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,22 +42,22 @@ 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
|
||||
$ltmVirtualServEntry['name'] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.10.1.2.1.1', 0);
|
||||
//If no Virtual Servers are found don't look for statistics
|
||||
if (!empty($ltmVirtualServEntry['name'])) {
|
||||
if (! empty($ltmVirtualServEntry['name'])) {
|
||||
foreach ($ltmVirtualServOID as $key => $value) {
|
||||
$ltmVirtualServEntry[$key] = snmpwalk_array_num($device, $value, 0);
|
||||
}
|
||||
@ -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 = [];
|
||||
@ -93,14 +93,14 @@ $ltmPoolMemberEntry = [];
|
||||
$ltmPoolEntry['name'] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.1.2.1.1', 0);
|
||||
|
||||
//If no Pools are found don't look for statistics or pool members
|
||||
if (!empty($ltmPoolEntry['name'])) {
|
||||
if (! empty($ltmPoolEntry['name'])) {
|
||||
// If there are pools gather Pool Member Data
|
||||
foreach ($ltmPoolEntryOID as $key => $value) {
|
||||
$ltmPoolEntry[$key] = snmpwalk_array_num($device, $value, 0);
|
||||
}
|
||||
// Gather Pool Member Data if pool members found
|
||||
$ltmPoolMemberEntry['name'] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.3.2.1.1', 0);
|
||||
if (!empty($ltmPoolMemberEntry['name'])) {
|
||||
if (! empty($ltmPoolMemberEntry['name'])) {
|
||||
foreach ($ltmPoolMemberEntryOID as $key => $value) {
|
||||
$ltmPoolMemberEntry[$key] = snmpwalk_array_num($device, $value, 0);
|
||||
}
|
||||
@ -114,7 +114,7 @@ $ltmBwcEntry = [];
|
||||
//Check for Virtual Server Enries
|
||||
$ltmBwcEntry['name'] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.13.1.3.1.1', 0);
|
||||
//If no BWC are found don't look for statistics
|
||||
if (!empty($ltmBwcEntry['name'])) {
|
||||
if (! empty($ltmBwcEntry['name'])) {
|
||||
d_echo("#### Bandwidth Controller Found\n");
|
||||
} else {
|
||||
d_echo("No Bandwidth Controller Found\n");
|
||||
@ -124,44 +124,44 @@ if (!empty($ltmBwcEntry['name'])) {
|
||||
* False == no object found - this is not an error, OID doesn't exist.
|
||||
* null == timeout or something else that caused an error, OID may exist but we couldn't get it.
|
||||
*/
|
||||
if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry) || !empty($ltmPoolMemberEntry)) {
|
||||
if (! empty($ltmBwcEntry) || ! empty($ltmVirtualServEntry) || ! empty($ltmPoolEntry) || ! empty($ltmPoolMemberEntry)) {
|
||||
// No Nulls, lets go....
|
||||
d_echo("Objects Found:\n");
|
||||
|
||||
// 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['UID'] = (string) $index;
|
||||
$result['label'] = $value;
|
||||
// The UID is far too long to have in a RRD filename, use a hash of it instead.
|
||||
$result['hash'] = hash('crc32', $result['UID']);
|
||||
|
||||
// Trim IPv4 response to remove route domain ID
|
||||
if (strlen($ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index]) == 23) {
|
||||
$ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index] = substr($ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], 0, 11);
|
||||
if (strlen($ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.' . $index]) == 23) {
|
||||
$ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.' . $index] = substr($ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.' . $index], 0, 11);
|
||||
}
|
||||
|
||||
// Now that we have our UID we can pull all the other data we need.
|
||||
$result['IP'] = IP::fromHexString($ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], true);
|
||||
$result['port'] = $ltmVirtualServEntry['port']['1.3.6.1.4.1.3375.2.2.10.1.2.1.6.'.$index];
|
||||
$result['pool'] = $ltmVirtualServEntry['defaultpool']['1.3.6.1.4.1.3375.2.2.10.1.2.1.19.'.$index];
|
||||
$result['IP'] = IP::fromHexString($ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.' . $index], true);
|
||||
$result['port'] = $ltmVirtualServEntry['port']['1.3.6.1.4.1.3375.2.2.10.1.2.1.6.' . $index];
|
||||
$result['pool'] = $ltmVirtualServEntry['defaultpool']['1.3.6.1.4.1.3375.2.2.10.1.2.1.19.' . $index];
|
||||
|
||||
// 0 = None, 1 = Green, 2 = Yellow, 3 = Red, 4 = Blue
|
||||
$result['state'] = $ltmVirtualServEntry['state']['1.3.6.1.4.1.3375.2.2.10.13.2.1.2.'.$index];
|
||||
$result['state'] = $ltmVirtualServEntry['state']['1.3.6.1.4.1.3375.2.2.10.13.2.1.2.' . $index];
|
||||
if ($result['state'] == 2) {
|
||||
// Looks like one of the VS Pool members is down.
|
||||
$result['status'] = 1;
|
||||
$result['error'] = $ltmVirtualServEntry['errorcode']['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
|
||||
$result['error'] = $ltmVirtualServEntry['errorcode']['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.' . $index];
|
||||
} elseif ($result['state'] == 3) {
|
||||
// Looks like ALL of the VS Pool members is down.
|
||||
$result['status'] = 2;
|
||||
$result['error'] = $ltmVirtualServEntry['errorcode']['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
|
||||
$result['error'] = $ltmVirtualServEntry['errorcode']['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.' . $index];
|
||||
} else {
|
||||
// All is good.
|
||||
$result['status'] = 0;
|
||||
@ -172,9 +172,9 @@ if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry
|
||||
// Do we have any results
|
||||
if (count($result) > 0) {
|
||||
// Let's log some debugging
|
||||
d_echo("\n\n".$result['type'].": ".$result['label']."\n");
|
||||
d_echo(" Status: ".$result['status']."\n");
|
||||
d_echo(" Message: ".$result['error']."\n");
|
||||
d_echo("\n\n" . $result['type'] . ": " . $result['label'] . "\n");
|
||||
d_echo(" Status: " . $result['status'] . "\n");
|
||||
d_echo(" Message: " . $result['error'] . "\n");
|
||||
|
||||
// Add this result to the master array.
|
||||
$tblBigIP[] = $result;
|
||||
@ -182,16 +182,16 @@ if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry
|
||||
}
|
||||
}
|
||||
|
||||
// Process the BWC
|
||||
// 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['UID'] = (string) $index;
|
||||
$result['label'] = $value;
|
||||
// The UID is far too long to have in a RRD filename, use a hash of it instead.
|
||||
$result['hash'] = hash('crc32', $result['UID']);
|
||||
@ -208,30 +208,30 @@ 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['UID'] = (string) $index;
|
||||
$result['label'] = $value;
|
||||
// The UID is far too long to have in a RRD filename, use a hash of it instead.
|
||||
$result['hash'] = hash('crc32', $result['UID']);
|
||||
|
||||
// Now that we have our UID we can pull all the other data we need.
|
||||
$result['mode'] = $ltmPoolEntry['mode']['1.3.6.1.4.1.3375.2.2.5.1.2.1.2.'.$index];
|
||||
$result['minup'] = $ltmPoolEntry['minup']['1.3.6.1.4.1.3375.2.2.5.1.2.1.4.'.$index];
|
||||
$result['minupstatus'] = $ltmPoolEntry['minupstatus']['1.3.6.1.4.1.3375.2.2.5.1.2.1.5.'.$index];
|
||||
$result['currentup'] = $ltmPoolEntry['currentup']['1.3.6.1.4.1.3375.2.2.5.1.2.1.8.'.$index];
|
||||
$result['minupaction'] = $ltmPoolEntry['minupaction']['1.3.6.1.4.1.3375.2.2.5.1.2.1.6.'.$index];
|
||||
$result['monitor'] = $ltmPoolEntry['monitor']['1.3.6.1.4.1.3375.2.2.5.1.2.1.17.'.$index];
|
||||
$result['mode'] = $ltmPoolEntry['mode']['1.3.6.1.4.1.3375.2.2.5.1.2.1.2.' . $index];
|
||||
$result['minup'] = $ltmPoolEntry['minup']['1.3.6.1.4.1.3375.2.2.5.1.2.1.4.' . $index];
|
||||
$result['minupstatus'] = $ltmPoolEntry['minupstatus']['1.3.6.1.4.1.3375.2.2.5.1.2.1.5.' . $index];
|
||||
$result['currentup'] = $ltmPoolEntry['currentup']['1.3.6.1.4.1.3375.2.2.5.1.2.1.8.' . $index];
|
||||
$result['minupaction'] = $ltmPoolEntry['minupaction']['1.3.6.1.4.1.3375.2.2.5.1.2.1.6.' . $index];
|
||||
$result['monitor'] = $ltmPoolEntry['monitor']['1.3.6.1.4.1.3375.2.2.5.1.2.1.17.' . $index];
|
||||
|
||||
// If we have less pool members than the minimum, we should error.
|
||||
if ($result['currentup'] < $result['minup']) {
|
||||
// Danger Will Robinson... We dont have enough Pool Members!
|
||||
$result['status'] = 2;
|
||||
$result['error'] = "Minimum Pool Members not met. Action taken: ".$error_poolaction[$result['minupaction']];
|
||||
$result['error'] = "Minimum Pool Members not met. Action taken: " . $error_poolaction[$result['minupaction']];
|
||||
} else {
|
||||
// All is good.
|
||||
$result['status'] = 0;
|
||||
@ -242,9 +242,9 @@ if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry
|
||||
// Do we have any results
|
||||
if (count($result) > 0) {
|
||||
// Let's log some debugging
|
||||
d_echo("\n\n".$result['type'].": ".$result['label']."\n");
|
||||
d_echo(" Status: ".$result['status']."\n");
|
||||
d_echo(" Message: ".$result['error']."\n");
|
||||
d_echo("\n\n" . $result['type'] . ": " . $result['label'] . "\n");
|
||||
d_echo(" Status: " . $result['status'] . "\n");
|
||||
d_echo(" Message: " . $result['error'] . "\n");
|
||||
|
||||
// Add this result to the master array.
|
||||
$tblBigIP[] = $result;
|
||||
@ -255,37 +255,37 @@ 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['UID'] = (string) $index;
|
||||
$result['label'] = $value;
|
||||
// The UID is far too long to have in a RRD filename, use a hash of it instead.
|
||||
$result['hash'] = hash('crc32', $result['UID']);
|
||||
|
||||
//Remove route domain ID from v4 IPs
|
||||
if (strlen($ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index]) == 23) {
|
||||
$ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index] = substr($ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index], 0, 11);
|
||||
if (strlen($ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.' . $index]) == 23) {
|
||||
$ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.' . $index] = substr($ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.' . $index], 0, 11);
|
||||
}
|
||||
|
||||
// Now that we have our UID we can pull all the other data we need.
|
||||
$result['IP'] = IP::fromHexString($ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index], true);
|
||||
$result['port'] = $ltmPoolMemberEntry['port']['1.3.6.1.4.1.3375.2.2.5.3.2.1.4.'.$index];
|
||||
$result['ratio'] = $ltmPoolMemberEntry['ratio']['1.3.6.1.4.1.3375.2.2.5.3.2.1.6.'.$index];
|
||||
$result['weight'] = $ltmPoolMemberEntry['weight']['1.3.6.1.4.1.3375.2.2.5.3.2.1.7.'.$index];
|
||||
$result['priority'] = $ltmPoolMemberEntry['priority']['1.3.6.1.4.1.3375.2.2.5.3.2.1.8.'.$index];
|
||||
$result['state'] = $ltmPoolMemberEntry['state']['1.3.6.1.4.1.3375.2.2.5.6.2.1.5.'.$index];
|
||||
$result['available'] = $ltmPoolMemberEntry['available']['1.3.6.1.4.1.3375.2.2.5.6.2.1.6.'.$index];
|
||||
$result['IP'] = IP::fromHexString($ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.' . $index], true);
|
||||
$result['port'] = $ltmPoolMemberEntry['port']['1.3.6.1.4.1.3375.2.2.5.3.2.1.4.' . $index];
|
||||
$result['ratio'] = $ltmPoolMemberEntry['ratio']['1.3.6.1.4.1.3375.2.2.5.3.2.1.6.' . $index];
|
||||
$result['weight'] = $ltmPoolMemberEntry['weight']['1.3.6.1.4.1.3375.2.2.5.3.2.1.7.' . $index];
|
||||
$result['priority'] = $ltmPoolMemberEntry['priority']['1.3.6.1.4.1.3375.2.2.5.3.2.1.8.' . $index];
|
||||
$result['state'] = $ltmPoolMemberEntry['state']['1.3.6.1.4.1.3375.2.2.5.6.2.1.5.' . $index];
|
||||
$result['available'] = $ltmPoolMemberEntry['available']['1.3.6.1.4.1.3375.2.2.5.6.2.1.6.' . $index];
|
||||
|
||||
// If available and bad state
|
||||
// 0 = None, 1 = Green, 2 = Yellow, 3 = Red, 4 = Blue
|
||||
if (($result['available'] == 1) && ($result['state'] == 3)) {
|
||||
// Warning Alarm, the pool member is down.
|
||||
$result['status'] = 1;
|
||||
$result['error'] = "Pool Member is Down: ".$ltmPoolMemberEntry['errorcode']['1.3.6.1.4.1.3375.2.2.5.6.2.1.8.'.$index];
|
||||
$result['error'] = "Pool Member is Down: " . $ltmPoolMemberEntry['errorcode']['1.3.6.1.4.1.3375.2.2.5.6.2.1.8.' . $index];
|
||||
} else {
|
||||
// All is good.
|
||||
$result['status'] = 0;
|
||||
@ -296,9 +296,9 @@ if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry
|
||||
// Do we have any results
|
||||
if (count($result) > 0) {
|
||||
// Let's log some debugging
|
||||
d_echo("\n\n".$result['type'].": ".$result['label']."\n");
|
||||
d_echo(" Status: ".$result['status']."\n");
|
||||
d_echo(" Message: ".$result['error']."\n");
|
||||
d_echo("\n\n" . $result['type'] . ": " . $result['label'] . "\n");
|
||||
d_echo(" Status: " . $result['status'] . "\n");
|
||||
d_echo(" Message: " . $result['error'] . "\n");
|
||||
|
||||
// Add this result to the master array.
|
||||
$tblBigIP[] = $result;
|
||||
@ -322,7 +322,7 @@ if (!empty($ltmBwcEntry) || !empty($ltmVirtualServEntry) || !empty($ltmPoolEntry
|
||||
}
|
||||
}
|
||||
|
||||
if (!$component_key) {
|
||||
if (! $component_key) {
|
||||
// The component doesn't exist, we need to ADD it - ADD.
|
||||
$new_component = $component->createComponent($device['device_id'], $array['type']);
|
||||
$component_key = key($new_component);
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Variable to hold the discovered MEF Links.
|
||||
*/
|
||||
|
||||
$mef_list = array();
|
||||
$mef_list = [];
|
||||
|
||||
/*
|
||||
* Fetch information about MEF Links.
|
||||
@ -18,9 +18,9 @@ $oids = snmpwalk_cache_multi_oid($device, 'MefServiceEvcCfgEntry', $oids, 'MEF-U
|
||||
|
||||
echo "MEF : ";
|
||||
foreach ($oids as $index => $entry) {
|
||||
$mefIdent = $entry['mefServiceEvcCfgIdentifier'];
|
||||
$mefType = $entry['mefServiceEvcCfgServiceType'];
|
||||
$mefMtu = $entry['mefServiceEvcCfgMtuSize'];
|
||||
$mefIdent = $entry['mefServiceEvcCfgIdentifier'];
|
||||
$mefType = $entry['mefServiceEvcCfgServiceType'];
|
||||
$mefMtu = $entry['mefServiceEvcCfgMtuSize'];
|
||||
$mefAdmState = $entry['mefServiceEvcCfgAdminState'];
|
||||
$mefRowState = $entry['mefServiceEvcCfgRowStatus'];
|
||||
|
||||
@ -35,9 +35,9 @@ 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');
|
||||
log_event("MEF link: ". mres($mefIdent) . " (" . $index . ") Discovered", $device, 'system', 2);
|
||||
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 {
|
||||
echo '.';
|
||||
@ -52,14 +52,14 @@ foreach ($oids as $index => $entry) {
|
||||
* Get a list of all the known MEF Links for this host
|
||||
*/
|
||||
|
||||
$sql = "SELECT id, mefID, mefIdent FROM mefinfo WHERE device_id = '".$device['device_id']."'";
|
||||
$sql = "SELECT id, mefID, mefIdent FROM mefinfo WHERE device_id = '" . $device['device_id'] . "'";
|
||||
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']));
|
||||
log_event("MEF link: ".mres($db_mef['mefIdent']).' Removed', $device, 'system', 3);
|
||||
if (! in_array($db_mef['mefID'], $mef_list)) {
|
||||
dbDelete('mefinfo', '`id` = ?', [$db_mef['id']]);
|
||||
log_event("MEF link: " . mres($db_mef['mefIdent']) . ' Removed', $device, 'system', 3);
|
||||
echo '-';
|
||||
}
|
||||
}
|
||||
|
@ -5,18 +5,18 @@ $include_dir = 'includes/discovery/mempools';
|
||||
require 'includes/include-dir.inc.php';
|
||||
|
||||
// Remove memory pools which weren't redetected here
|
||||
$sql = "SELECT * FROM `mempools` WHERE `device_id` = '".$device['device_id']."'";
|
||||
$sql = "SELECT * FROM `mempools` WHERE `device_id` = '" . $device['device_id'] . "'";
|
||||
|
||||
d_echo($valid_mempool);
|
||||
|
||||
foreach (dbFetchRows($sql) as $test_mempool) {
|
||||
$mempool_index = $test_mempool['mempool_index'];
|
||||
$mempool_type = $test_mempool['mempool_type'];
|
||||
d_echo($mempool_index.' -> '.$mempool_type."\n");
|
||||
$mempool_type = $test_mempool['mempool_type'];
|
||||
d_echo($mempool_index . ' -> ' . $mempool_type . "\n");
|
||||
|
||||
if (!$valid_mempool[$mempool_type][$mempool_index]) {
|
||||
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);
|
||||
|
@ -22,7 +22,6 @@
|
||||
* @copyright 2017 Neil Lathwood
|
||||
* @author Neil Lathwood <neil@lathwood.co.uk>
|
||||
*/
|
||||
|
||||
if ($device['os'] === '3com') {
|
||||
echo '3COM:';
|
||||
|
||||
|
@ -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');
|
||||
|
@ -12,19 +12,17 @@
|
||||
* 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: ';
|
||||
|
||||
$used = snmp_get($device, 'adGenAOSHeapSize.0', '-OvQ', 'ADTRAN-AOSCPU');
|
||||
$total = snmp_get($device, 'adGenAOSMemPool.0', '-OvQ', 'ADTRAN-AOSCPU');
|
||||
$used = snmp_get($device, 'adGenAOSHeapSize.0', '-OvQ', 'ADTRAN-AOSCPU');
|
||||
$total = snmp_get($device, 'adGenAOSMemPool.0', '-OvQ', 'ADTRAN-AOSCPU');
|
||||
$percent = ($used / $total * 100);
|
||||
|
||||
if (is_numeric($total) && is_numeric($used)) {
|
||||
|
@ -3,10 +3,10 @@
|
||||
if ($device['os'] == 'aos6') {
|
||||
echo 'Alcatel-Lucent OS: ';
|
||||
if (strpos($device['sysObjectID'], '1.3.6.1.4.1.6486.800')) { // AOS 6
|
||||
$total = snmp_get($device, 'systemHardwareMemorySize.0', '-OvQ', 'ALCATEL-IND1-SYSTEM-MIB', 'aos6');
|
||||
$total = snmp_get($device, 'systemHardwareMemorySize.0', '-OvQ', 'ALCATEL-IND1-SYSTEM-MIB', 'aos6');
|
||||
$percent = snmp_get($device, 'healthDeviceMemoryLatest.0', '-OvQ', 'ALCATEL-IND1-HEALTH-MIB', 'aos6');
|
||||
$used = ($total / 100 * $perc_used);
|
||||
$free = ($total - $used);
|
||||
$used = ($total / 100 * $perc_used);
|
||||
$free = ($total - $used);
|
||||
|
||||
if (is_numeric($total) && is_numeric($used)) {
|
||||
discover_mempool($valid_mempool, $device, 0, 'aos6', 'Device Memory', '1', null, null);
|
||||
|
@ -3,10 +3,10 @@
|
||||
if ($device['os'] == 'aos7') {
|
||||
echo 'Alcatel-Lucent OS: ';
|
||||
if (strpos($device['sysObjectID'], '1.3.6.1.4.1.6486.801')) { // AOS 7
|
||||
$total = snmp_get($device, '.1.3.6.1.4.1.6486.801.1.1.1.2.1.1.3.4.0', '-OvQ', 'ALCATEL-IND1-SYSTEM-MIB', 'nokia/aos7'); // systemHardwareMemorySize
|
||||
$total = snmp_get($device, '.1.3.6.1.4.1.6486.801.1.1.1.2.1.1.3.4.0', '-OvQ', 'ALCATEL-IND1-SYSTEM-MIB', 'nokia/aos7'); // systemHardwareMemorySize
|
||||
$percent = snmp_get($device, '.1.3.6.1.4.1.6486.801.1.2.1.16.1.1.1.1.1.8.0', '-OvQ', 'ALCATEL-IND1-HEALTH-MIB', 'nokia/aos7'); // healthModuleMemory1MinAvg
|
||||
$used = $total / 100 * $percent;
|
||||
$free = ($total - $used);
|
||||
$used = $total / 100 * $percent;
|
||||
$free = ($total - $used);
|
||||
|
||||
if (is_numeric($total) && is_numeric($percent)) {
|
||||
$total *= 1024; // Memory in MB
|
||||
|
@ -30,11 +30,11 @@ if ($device['os'] === 'aruba-instant') {
|
||||
$mempool_data = snmpwalk_group($device, 'aiAPMemoryFree', 'AI-AP-MIB', 1, $mempool_data);
|
||||
$mempool_data = snmpwalk_group($device, 'aiAPName', 'AI-AP-MIB', 1, $mempool_data);
|
||||
|
||||
d_echo('$mempool_data:'.PHP_EOL);
|
||||
d_echo('$mempool_data:' . PHP_EOL);
|
||||
d_echo($mempool_data);
|
||||
|
||||
foreach ($mempool_data as $index => $entry) {
|
||||
d_echo($entry['aiAPSerialNum'].' '.$entry['aiAPTotalMemory'].' / '.$entry['aiAPMemoryFree'].PHP_EOL);
|
||||
d_echo($entry['aiAPSerialNum'] . ' ' . $entry['aiAPTotalMemory'] . ' / ' . $entry['aiAPMemoryFree'] . PHP_EOL);
|
||||
|
||||
$oid_index = implode('.', array_map('hexdec', explode(':', $index)));
|
||||
|
||||
@ -42,12 +42,12 @@ if ($device['os'] === 'aruba-instant') {
|
||||
|
||||
$usage_oid = snmp_translate($combined_oid, 'ALL', 'arubaos', '-On', null);
|
||||
|
||||
$index = $entry['aiAPSerialNum'];
|
||||
$descr = $entry['aiAPName'] . ' [' . $entry['aiAPSerialNum'] . ']';
|
||||
$total = $entry['aiAPTotalMemory'];
|
||||
$free = $entry['aiAPMemoryFree'];
|
||||
$used = $total - $free;
|
||||
$perc = ($used / $total * 100);
|
||||
$index = $entry['aiAPSerialNum'];
|
||||
$descr = $entry['aiAPName'] . ' [' . $entry['aiAPSerialNum'] . ']';
|
||||
$total = $entry['aiAPTotalMemory'];
|
||||
$free = $entry['aiAPMemoryFree'];
|
||||
$used = $total - $free;
|
||||
$perc = ($used / $total * 100);
|
||||
|
||||
discover_mempool($valid_mempool, $device, $index, 'aruba-instant', $descr, '1', null, null);
|
||||
} //end foreach
|
||||
|
@ -4,11 +4,11 @@ if ($device['os'] === 'arubaos') {
|
||||
echo 'ARUBAOS-MEMORY-POOL: ';
|
||||
|
||||
$memory_pool = snmp_get_multi_oid($device, ['sysXMemorySize.1', 'sysXMemoryUsed.1', 'sysXMemoryFree.1'], '-OQUs', 'WLSX-SWITCH-MIB');
|
||||
|
||||
|
||||
$total = $memory_pool['sysXMemorySize.1'];
|
||||
$used = $memory_pool['sysXMemoryUsed.1'];
|
||||
$free = $memory_pool['sysXMemoryFree.1'];
|
||||
$perc = ($mempool['used'] / $mempool['total'] * 100);
|
||||
$used = $memory_pool['sysXMemoryUsed.1'];
|
||||
$free = $memory_pool['sysXMemoryFree.1'];
|
||||
$perc = ($mempool['used'] / $mempool['total'] * 100);
|
||||
|
||||
if (is_numeric($total) && is_numeric($used)) {
|
||||
discover_mempool($valid_mempool, $device, 0, 'arubaos', 'Memory', '1', null, null);
|
||||
|
@ -3,10 +3,10 @@
|
||||
if ($device['os'] === 'benuos') {
|
||||
echo 'BENU-HOST-MIB: ';
|
||||
$memdata = snmp_get_multi($device, ['bSysTotalMem.0', 'bSysMemUsed.0', 'bSysMemFree.0'], '-OQUs', 'BENU-HOST-MIB');
|
||||
$total = $memdata[0]['bSysTotalMem'];
|
||||
$used = $memdata[0]['bSysMemUsed'];
|
||||
$free = $memdata[0]['bSysMemFree'];
|
||||
$percent = ($total / $used) * 100;
|
||||
$total = $memdata[0]['bSysTotalMem'];
|
||||
$used = $memdata[0]['bSysMemUsed'];
|
||||
$free = $memdata[0]['bSysMemFree'];
|
||||
$percent = ($total / $used) * 100;
|
||||
if (is_numeric($total) && is_numeric($used)) {
|
||||
discover_mempool($valid_mempool, $device, 0, 'benuos', 'Memory', '1', null, null);
|
||||
}
|
||||
|
@ -12,15 +12,13 @@
|
||||
* 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
|
||||
$total = ($free + $used);
|
||||
$percent = (($used / $total) * 100);
|
||||
$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
|
||||
$total = ($free + $used);
|
||||
$percent = (($used / $total) * 100);
|
||||
|
||||
if (is_numeric($used)) {
|
||||
discover_mempool($valid_mempool, $device, 0, "binos", "Memory", "1", null, null);
|
||||
|
@ -12,17 +12,15 @@
|
||||
* 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);
|
||||
$used = str_replace('"', '', $used);
|
||||
$total = "100";
|
||||
$free = ($total - $used);
|
||||
$percent = $used;
|
||||
$used = snmp_get($device, ".1.3.6.1.4.1.738.10.111.3.1.3.0", "-Ovq");
|
||||
$used = str_replace('%', '', $used);
|
||||
$used = str_replace('"', '', $used);
|
||||
$total = "100";
|
||||
$free = ($total - $used);
|
||||
$percent = $used;
|
||||
|
||||
if (is_numeric($used)) {
|
||||
discover_mempool($valid_mempool, $device, 0, "binox", "Memory", "1", null, null);
|
||||
|
@ -8,8 +8,8 @@ if ($device['os'] == 'boss') {
|
||||
echo "$mem\n";
|
||||
|
||||
foreach (explode("\n", $mem) as $i => $t) {
|
||||
$t = explode(' ', $t);
|
||||
$t = explode(' ', $t);
|
||||
$oid = str_replace($OID, '', $t[0]);
|
||||
discover_mempool($valid_mempool, $device, $oid, 'avaya-ers', 'Unit '.($i + 1).' memory', '1', null, null);
|
||||
discover_mempool($valid_mempool, $device, $oid, 'avaya-ers', 'Unit ' . ($i + 1) . ' memory', '1', null, null);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ if ($device['os'] == 'cdata') {
|
||||
echo 'CDATA-MEMORY-POOL: ';
|
||||
|
||||
$total = snmp_get($device, '.1.3.6.1.4.1.34592.1.3.100.1.8.2.0', '-OvQ');
|
||||
$free = snmp_get($device, '.1.3.6.1.4.1.34592.1.3.100.1.8.3.0', '-OvQ');
|
||||
$free = snmp_get($device, '.1.3.6.1.4.1.34592.1.3.100.1.8.3.0', '-OvQ');
|
||||
|
||||
if (is_numeric($total) && is_numeric($free)) {
|
||||
discover_mempool($valid_mempool, $device, 0, 'cdata', 'Memory', '1', null, null);
|
||||
|
@ -8,10 +8,10 @@ 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);
|
||||
$entPhysicalName = snmp_get($device, 'entPhysicalName.'.$entPhysicalIndex, '-Oqv', 'ENTITY-MIB');
|
||||
[$entPhysicalIndex] = explode('.', $index);
|
||||
$entPhysicalName = snmp_get($device, 'entPhysicalName.' . $entPhysicalIndex, '-Oqv', 'ENTITY-MIB');
|
||||
|
||||
$descr = $entPhysicalName.' - '.$entry['cempMemPoolName'];
|
||||
$descr = $entPhysicalName . ' - ' . $entry['cempMemPoolName'];
|
||||
|
||||
$descr = str_replace('Cisco ', '', $descr);
|
||||
$descr = str_replace('Network Processing Engine', '', $descr);
|
||||
|
@ -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: ';
|
||||
|
@ -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');
|
||||
|
@ -22,7 +22,6 @@
|
||||
* @copyright 2017 Neil Lathwood
|
||||
* @author Neil Lathwood <neil@lathwood.co.uk>
|
||||
*/
|
||||
|
||||
if ($device['os'] === 'cyberoam-utm') {
|
||||
echo 'Cyberoam UTM: ';
|
||||
|
||||
|
@ -22,13 +22,12 @@
|
||||
* @copyright 2016 Neil Lathwood
|
||||
* @author Neil Lathwood <neil@lathwood.co.uk>
|
||||
*/
|
||||
|
||||
if ($device['os'] === 'dasan-nos') {
|
||||
echo 'Dasan NOS: ';
|
||||
|
||||
$total = snmp_get($device, 'dsTotalMem.0', '-OvQU', 'DASAN-SWITCH-MIB', 'dasan');
|
||||
$used = snmp_get($device, 'dsUsedMem.0', '-OvQU', 'DASAN-SWITCH-MIB', 'dasan');
|
||||
$free = snmp_get($device, 'dsFreeMem.0', '-OvQU', 'DASAN-SWITCH-MIB', 'dasan');
|
||||
$used = snmp_get($device, 'dsUsedMem.0', '-OvQU', 'DASAN-SWITCH-MIB', 'dasan');
|
||||
$free = snmp_get($device, 'dsFreeMem.0', '-OvQU', 'DASAN-SWITCH-MIB', 'dasan');
|
||||
if (is_numeric($total) && is_numeric($used) && is_numeric($free)) {
|
||||
discover_mempool($valid_mempool, $device, 0, 'dasan-nos', 'Memory Utilization', '1', null, null);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
|
||||
if ($device['os'] == 'dcn-software') {
|
||||
$usage = snmp_get($device, 'switchMemoryUsage.0', '-OvQ', 'DCN-MIB');
|
||||
if (is_numeric($usage)) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
if ($device['os'] == 'dlink') {
|
||||
echo 'D-Link : ';
|
||||
|
||||
|
||||
$memory_oid = '.1.3.6.1.4.1.171.12.1.1.9.1.4.1';
|
||||
$usage = snmp_get($device, $memory_oid, '-Ovq');
|
||||
if (is_numeric($usage)) {
|
||||
@ -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);
|
||||
discover_mempool($valid_mempool, $device, $tmp_index, 'dlink', ucfirst($dlink_type). " Memory");
|
||||
[,$dlink_type] = explode('.', $tmp_index);
|
||||
discover_mempool($valid_mempool, $device, $tmp_index, 'dlink', ucfirst($dlink_type) . " Memory");
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
if ($device['os'] == 'dlinkap') {
|
||||
d_echo('Dlink AP');
|
||||
$memory_oid = $device['sysObjectID'].'.5.1.4.0';
|
||||
$memory_oid = $device['sysObjectID'] . '.5.1.4.0';
|
||||
$usage = snmp_get($device, $memory_oid, '-Ovq');
|
||||
if (is_numeric($usage)) {
|
||||
discover_mempool($valid_mempool, $device, '0', 'dlinkap', 'Memory', '1', null, null);
|
||||
|
@ -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');
|
||||
|
||||
|
@ -29,14 +29,14 @@ 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);
|
||||
$temp_data = snmp_get_multi_oid($device, ['memoryTotal.0', 'memoryFreed.0', 'memoryAllocated.0'], '-OUQs', $temp_mibs);
|
||||
$total = $temp_data['memoryTotal.0'];
|
||||
$avail = $temp_data['memoryFreed.0'];
|
||||
$used = $temp_data['memoryAllocated.0'] ?? ($total - $avail);
|
||||
|
||||
if ((is_numeric($total)) && (is_numeric($avail)) && (is_numeric($used) )) {
|
||||
if ((is_numeric($total)) && (is_numeric($avail)) && (is_numeric($used))) {
|
||||
discover_mempool($valid_mempool, $device, 0, 'edgecos', 'Memory', '1', null, null);
|
||||
}
|
||||
unset($temp_id, $temp_data, $tmep_mibs);
|
||||
|
@ -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'];
|
||||
|
@ -3,10 +3,10 @@
|
||||
if ($device['os'] == 'f5') {
|
||||
echo 'F5: ';
|
||||
|
||||
$total = snmp_get($device, 'sysGlobalStat.sysStatMemoryTotal.0', '-OvQ', 'F5-BIGIP-SYSTEM-MIB', 'f5');
|
||||
$total = snmp_get($device, 'sysGlobalStat.sysStatMemoryTotal.0', '-OvQ', 'F5-BIGIP-SYSTEM-MIB', 'f5');
|
||||
$used = snmp_get($device, 'sysGlobalStat.sysStatMemoryUsed.0', '-OvQ', 'F5-BIGIP-SYSTEM-MIB', 'f5');
|
||||
$percent = ($total / $used) * 100;
|
||||
$free = ($total - $used);
|
||||
$percent = ($total / $used) * 100;
|
||||
$free = ($total - $used);
|
||||
if (is_numeric($total) && is_numeric($used)) {
|
||||
discover_mempool($valid_mempool, $device, 0, 'f5', 'TMM Memory', '1', null, null);
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -21,11 +21,11 @@ if ($device['os'] === 'fiberhome-switch') {
|
||||
if (is_array($mempools_array)) {
|
||||
foreach ($mempools_array as $index => $entry) {
|
||||
if ($entry['memoryPoolTotalBytes'] != 0) {
|
||||
d_echo($index.' '.$entry['memoryPoolIndexDescr'].' -> '.$entry['memoryPoolAllocBytesNum']."\n");
|
||||
$usage_oid = '.1.3.6.1.4.1.3807.1.8012.1.5.4.1.7.'.$index;
|
||||
$descr = $entry['memoryPoolIndexDescr'];
|
||||
$usage = $entry['memoryPoolAllocBytesNum'];
|
||||
if (!strstr($descr, 'No') && !strstr($usage, 'No') && $descr != '') {
|
||||
d_echo($index . ' ' . $entry['memoryPoolIndexDescr'] . ' -> ' . $entry['memoryPoolAllocBytesNum'] . "\n");
|
||||
$usage_oid = '.1.3.6.1.4.1.3807.1.8012.1.5.4.1.7.' . $index;
|
||||
$descr = $entry['memoryPoolIndexDescr'];
|
||||
$usage = $entry['memoryPoolAllocBytesNum'];
|
||||
if (! strstr($descr, 'No') && ! strstr($usage, 'No') && $descr != '') {
|
||||
discover_mempool($valid_mempool, $device, $index, 'fiberhome-switch', $descr, '1', null, null);
|
||||
}
|
||||
} //end if
|
||||
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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'));
|
||||
|
@ -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)) {
|
||||
|
@ -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);
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
// Discovery for FS gbn devices.
|
||||
//
|
||||
@ -20,13 +21,13 @@ if ($device['os'] == 'fs-gbn') {
|
||||
// this would not change the complexity.
|
||||
//
|
||||
if ($entry['memorySize'] != 0) {
|
||||
d_echo($index.' '.$entry['memorySize'].' -> '.$entry['memoryIdle'].' ('.$entry['cpuDescription'].")\n");
|
||||
$descr = $entry['cpuDescription'];
|
||||
d_echo($index . ' ' . $entry['memorySize'] . ' -> ' . $entry['memoryIdle'] . ' (' . $entry['cpuDescription'] . ")\n");
|
||||
$descr = $entry['cpuDescription'];
|
||||
if (empty($descr)) {
|
||||
$descr = "Chassis CPU";
|
||||
}
|
||||
$descr .= " Memory";
|
||||
$usage = $entry['memoryIdle'];
|
||||
$descr .= " Memory";
|
||||
$usage = $entry['memoryIdle'];
|
||||
discover_mempool($valid_mempool, $device, $index, 'fs-gbn', $descr, '1', null, null);
|
||||
} //end if
|
||||
} //end foreach
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
// Discovery for FS-switch devices.
|
||||
//
|
||||
@ -11,10 +12,10 @@ if ($device['os'] == 'fs-switch') {
|
||||
d_echo($mempools_array);
|
||||
foreach ($mempools_array as $index => $entry) {
|
||||
if ($entry['memTotalReal'] > 0) {
|
||||
d_echo($index.' '.$entry['memTotalReal'].' -> '.$entry['memTotalFree']."\n");
|
||||
$descr = "Chassis";
|
||||
$descr .= " Memory";
|
||||
$usage = $entry['memTotalFree'];
|
||||
d_echo($index . ' ' . $entry['memTotalReal'] . ' -> ' . $entry['memTotalFree'] . "\n");
|
||||
$descr = "Chassis";
|
||||
$descr .= " Memory";
|
||||
$usage = $entry['memTotalFree'];
|
||||
discover_mempool($valid_mempool, $device, $index, 'fs-switch', $descr, '1', null, null);
|
||||
} //end if
|
||||
} //end foreach
|
||||
|
@ -22,7 +22,6 @@
|
||||
* @copyright 2019 Spencer Butler
|
||||
* @author Spencer Butler <github@crooked.app>
|
||||
*/
|
||||
|
||||
if ($device['os'] === 'hikvision-cam') {
|
||||
echo 'hikvision-cam:';
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
* @copyright 2019 Spencer Butler
|
||||
* @author Spencer Butler <github@crooked.app>
|
||||
*/
|
||||
|
||||
if ($device['os'] === 'hikvision-nvr') {
|
||||
echo 'hikvision-nvr:';
|
||||
|
||||
|
@ -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');
|
||||
|
@ -21,11 +21,11 @@ if (is_array($array)) {
|
||||
echo 'Procurve : ';
|
||||
foreach ($array as $index => $mempool) {
|
||||
if (is_numeric($index) && is_numeric($mempool['hpLocalMemTotalBytes'])) {
|
||||
discover_mempool($valid_mempool, $device, $index, 'hpLocal', 'Local Memory '.$index, null, null, null);
|
||||
discover_mempool($valid_mempool, $device, $index, 'hpLocal', 'Local Memory ' . $index, null, null, null);
|
||||
}
|
||||
|
||||
if (is_numeric($index) && is_numeric($mempool['hpGlobalMemTotalBytes'])) {
|
||||
discover_mempool($valid_mempool, $device, $index, 'hpGlobal', 'Global Memory '.$index, null, null, null);
|
||||
discover_mempool($valid_mempool, $device, $index, 'hpGlobal', 'Global Memory ' . $index, null, null, null);
|
||||
}
|
||||
|
||||
unset($deny, $fstype, $descr, $size, $used, $units);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -13,8 +13,8 @@
|
||||
if ($device['os'] === 'hpmsm') {
|
||||
echo 'HPE MSM : ';
|
||||
$total = snmp_get($device, 'coUsInfoRamTotal.0', '-OvQU', 'COLUBRIS-USAGE-INFORMATION-MIB', 'hpmsm');
|
||||
$used = $total - $free;
|
||||
$free = snmp_get($device, 'coUsInfoRamFree.0', '-OvQU', 'COLUBRIS-USAGE-INFORMATION-MIB', 'hpmsm');
|
||||
$used = $total - $free;
|
||||
$free = snmp_get($device, 'coUsInfoRamFree.0', '-OvQU', 'COLUBRIS-USAGE-INFORMATION-MIB', 'hpmsm');
|
||||
if (is_numeric($total) && is_numeric($used) && is_numeric($free)) {
|
||||
discover_mempool($valid_mempool, $device, 0, 'hpmsm', 'Memory Utilization', '1', null, null);
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ if (is_array($storage_array)) {
|
||||
echo 'hrStorage : ';
|
||||
foreach ($storage_array as $index => $storage) {
|
||||
$fstype = $storage['hrStorageType'];
|
||||
$descr = $storage['hrStorageDescr'];
|
||||
$size = ($storage['hrStorageSize'] * $storage['hrStorageAllocationUnits']);
|
||||
$used = ($storage['hrStorageUsed'] * $storage['hrStorageAllocationUnits']);
|
||||
$units = $storage['hrStorageAllocationUnits'];
|
||||
$deny = 1;
|
||||
$descr = $storage['hrStorageDescr'];
|
||||
$size = ($storage['hrStorageSize'] * $storage['hrStorageAllocationUnits']);
|
||||
$used = ($storage['hrStorageUsed'] * $storage['hrStorageAllocationUnits']);
|
||||
$units = $storage['hrStorageAllocationUnits'];
|
||||
$deny = 1;
|
||||
$perc_warn = 90;
|
||||
|
||||
switch ($fstype) {
|
||||
@ -52,7 +52,7 @@ if (is_array($storage_array)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$deny && is_numeric($index)) {
|
||||
if (! $deny && is_numeric($index)) {
|
||||
discover_mempool($valid_mempool, $device, $index, 'hrstorage', $descr, $units, null, null, $perc_warn);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ if ($device['os'] == 'ies52xxM') {
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_numeric($key) && is_numeric($value['memStatsCurrent'])) {
|
||||
$perc_warn = $value['memStatsHighThreshold'];
|
||||
discover_mempool($valid_mempool, $device, $key, 'ies52xxM-mem', 'Memory '.$key, null, null, null, $perc_warn);
|
||||
discover_mempool($valid_mempool, $device, $key, 'ies52xxM-mem', 'Memory ' . $key, null, null, null, $perc_warn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ if ($device['os'] == 'infinity') {
|
||||
echo 'INFINITY-MEMORY-POOL: ';
|
||||
|
||||
$total = snmp_get($device, '.1.3.6.1.4.1.10002.1.1.1.1.1.0', '-OvQ');
|
||||
$free = snmp_get($device, '.1.3.6.1.4.1.10002.1.1.1.1.2.0', '-OvQ');
|
||||
$free = snmp_get($device, '.1.3.6.1.4.1.10002.1.1.1.1.2.0', '-OvQ');
|
||||
|
||||
if (is_numeric($total) && is_numeric($free)) {
|
||||
discover_mempool($valid_mempool, $device, 0, 'infinity', 'Memory', '1', null, null);
|
||||
|
@ -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');
|
||||
@ -23,12 +23,12 @@ if ($device['os'] == 'ironware' || $device['os_type'] == 'ironware') {
|
||||
|
||||
if (is_array($ni_mempools_array)) {
|
||||
foreach ($ni_mempools_array as $index => $entry) {
|
||||
d_echo($index.' '.$entry['snAgentBrdMainBrdDescription'].' -> '.$entry['snAgentBrdMemoryUtil100thPercent']."\n");
|
||||
d_echo($index . ' ' . $entry['snAgentBrdMainBrdDescription'] . ' -> ' . $entry['snAgentBrdMemoryUtil100thPercent'] . "\n");
|
||||
|
||||
$usage_oid = '.1.3.6.1.4.1.1991.1.1.2.2.1.1.28.'.$index;
|
||||
$descr = $entry['snAgentBrdMainBrdDescription'];
|
||||
$usage = ($entry['snAgentBrdMemoryUtil100thPercent'] / 100);
|
||||
if (!strstr($descr, 'No') && !strstr($usage, 'No') && $descr != '') {
|
||||
$usage_oid = '.1.3.6.1.4.1.1991.1.1.2.2.1.1.28.' . $index;
|
||||
$descr = $entry['snAgentBrdMainBrdDescription'];
|
||||
$usage = ($entry['snAgentBrdMemoryUtil100thPercent'] / 100);
|
||||
if (! strstr($descr, 'No') && ! strstr($usage, 'No') && $descr != '') {
|
||||
discover_mempool($valid_mempool, $device, $index, 'ironware-dyn', $descr, '1', null, null);
|
||||
} //end_if
|
||||
} //end_foreach
|
||||
|
@ -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";
|
||||
|
@ -16,12 +16,12 @@ if ($device['os'] == 'junos') {
|
||||
continue;
|
||||
}
|
||||
|
||||
d_echo($index.' '.$entry['jnxOperatingDescr'].' -> '.$entry['jnxOperatingBuffer'].' -> '.$entry['jnxOperatingDRAMSize']."\n");
|
||||
d_echo($index . ' ' . $entry['jnxOperatingDescr'] . ' -> ' . $entry['jnxOperatingBuffer'] . ' -> ' . $entry['jnxOperatingDRAMSize'] . "\n");
|
||||
|
||||
$usage_oid = '.1.3.6.1.4.1.2636.3.1.13.1.8.'.$index;
|
||||
$descr = $entry['jnxOperatingDescr'];
|
||||
$usage = $entry['jnxOperatingBuffer'];
|
||||
if (!strstr($descr, 'No') && !strstr($usage, 'No') && $descr != '') {
|
||||
$usage_oid = '.1.3.6.1.4.1.2636.3.1.13.1.8.' . $index;
|
||||
$descr = $entry['jnxOperatingDescr'];
|
||||
$usage = $entry['jnxOperatingBuffer'];
|
||||
if (! strstr($descr, 'No') && ! strstr($usage, 'No') && $descr != '') {
|
||||
discover_mempool($valid_mempool, $device, $index, 'junos', $descr, '1', null, null);
|
||||
}
|
||||
} //end if
|
||||
@ -32,8 +32,8 @@ if ($device['os'] == 'junos') {
|
||||
if (is_array($srx_mempools_array)) {
|
||||
foreach ($srx_mempools_array as $index => $entry) {
|
||||
if ($index) {
|
||||
$usage_oid = '.1.3.6.1.4.1.2636.3.39.1.12.1.1.1.5.'.$index;
|
||||
$descr = 'Memory';
|
||||
$usage_oid = '.1.3.6.1.4.1.2636.3.39.1.12.1.1.1.5.' . $index;
|
||||
$descr = 'Memory';
|
||||
// No description in the table?
|
||||
$usage = $entry['jnxJsSPUMonitoringMemoryUsage'];
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
* @copyright 2016 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
if ($device['os'] == 'netonix') {
|
||||
echo 'NETONIX : ';
|
||||
|
||||
|
@ -14,18 +14,18 @@ if ($device['os'] == 'nokia-isam') {
|
||||
echo 'Nokia ISAM Memory: ';
|
||||
|
||||
$slotTable = [
|
||||
'4352' => 'acu:1/1/',
|
||||
'4353' => 'nt-a:',
|
||||
'4354' => 'nt-b:',
|
||||
'4355' => 'lt:1/1/1/',
|
||||
'4356' => 'lt:1/1/2/',
|
||||
'4357' => 'lt:1/1/3/',
|
||||
'4358' => 'lt:1/1/4/',
|
||||
'4359' => 'lt:1/1/5/',
|
||||
'4360' => 'lt:1/1/6/',
|
||||
'4361' => 'lt:1/1/7/',
|
||||
'4362' => 'lt:1/1/8/',
|
||||
'4481' => '4481' // FIXME define this
|
||||
'4352' => 'acu:1/1/',
|
||||
'4353' => 'nt-a:',
|
||||
'4354' => 'nt-b:',
|
||||
'4355' => 'lt:1/1/1/',
|
||||
'4356' => 'lt:1/1/2/',
|
||||
'4357' => 'lt:1/1/3/',
|
||||
'4358' => 'lt:1/1/4/',
|
||||
'4359' => 'lt:1/1/5/',
|
||||
'4360' => 'lt:1/1/6/',
|
||||
'4361' => 'lt:1/1/7/',
|
||||
'4362' => 'lt:1/1/8/',
|
||||
'4481' => '4481', // FIXME define this
|
||||
];
|
||||
|
||||
$array = snmpwalk_cache_multi_oid($device, 'mem', null, 'ASAM-SYSTEM-MIB');
|
||||
@ -33,10 +33,10 @@ 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);
|
||||
$entPhysicalName = $entPhysicalIndex;
|
||||
|
||||
$descr = $slotTable[$index].' Memory ('.$index.')';
|
||||
[$entPhysicalIndex] = explode('.', $index);
|
||||
$entPhysicalName = $entPhysicalIndex;
|
||||
|
||||
$descr = $slotTable[$index] . ' Memory (' . $index . ')';
|
||||
|
||||
discover_mempool($valid_mempool, $device, $index, 'nokia-isam', $descr, '1', $entPhysicalIndex, null, '98');
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user