2012-04-09 12:53:44 +00:00
|
|
|
<?php
|
|
|
|
|
2017-09-11 15:26:41 -05:00
|
|
|
use LibreNMS\Config;
|
2017-08-08 14:14:58 -05:00
|
|
|
use LibreNMS\Util\IP;
|
|
|
|
|
2017-09-11 15:26:41 -05:00
|
|
|
if (Config::get('enable_sla') && $device['os_group'] == 'cisco') {
|
2015-07-10 13:36:21 +02:00
|
|
|
$slas = snmp_walk($device, 'ciscoRttMonMIB.ciscoRttMonObjects.rttMonCtrl', '-Osq', '+CISCO-RTTMON-MIB');
|
2012-04-09 15:30:45 +00:00
|
|
|
|
2015-07-10 13:36:21 +02:00
|
|
|
$sla_table = array();
|
2015-07-13 20:10:26 +02:00
|
|
|
foreach (explode("\n", $slas) as $sla) {
|
2015-07-10 13:36:21 +02:00
|
|
|
$key_val = explode(' ', $sla, 2);
|
|
|
|
if (count($key_val) != 2) {
|
|
|
|
$key_val[] = '';
|
|
|
|
}
|
2012-04-09 15:30:45 +00:00
|
|
|
|
2015-07-10 13:36:21 +02:00
|
|
|
$key = $key_val[0];
|
|
|
|
$value = $key_val[1];
|
2012-04-09 15:30:45 +00:00
|
|
|
|
2015-07-10 13:36:21 +02:00
|
|
|
$prop_id = explode('.', $key);
|
|
|
|
if ((count($prop_id) != 2) || !ctype_digit($prop_id[1])) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-04-09 12:53:44 +00:00
|
|
|
|
2015-07-10 13:36:21 +02:00
|
|
|
$property = $prop_id[0];
|
|
|
|
$id = intval($prop_id[1]);
|
2012-04-09 12:53:44 +00:00
|
|
|
|
2015-07-10 13:36:21 +02:00
|
|
|
$sla_table[$id][$property] = trim($value);
|
2012-04-09 12:53:44 +00:00
|
|
|
}
|
2012-04-09 15:30:45 +00:00
|
|
|
|
2015-07-10 13:36:21 +02:00
|
|
|
// 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']));
|
2012-04-09 12:53:44 +00:00
|
|
|
|
2015-07-10 13:36:21 +02:00
|
|
|
foreach ($sla_table as $sla_nr => $sla_config) {
|
2016-08-28 12:32:58 -05:00
|
|
|
$query_data = array(
|
2015-07-10 13:36:21 +02:00
|
|
|
'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,
|
2016-08-08 16:59:29 +10:00
|
|
|
'opstatus' => ($sla_config['rttMonLatestRttOperSense'] == 'ok') ? 0 : 2,
|
2015-07-10 13:36:21 +02:00
|
|
|
'deleted' => 0,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Some fallbacks for when the tag is empty
|
|
|
|
if (!$data['tag']) {
|
2015-07-13 20:10:26 +02:00
|
|
|
switch ($data['rtt_type']) {
|
2015-07-10 13:36:21 +02:00
|
|
|
case 'http':
|
|
|
|
$data['tag'] = $sla_config['rttMonEchoAdminURL'];
|
2016-08-28 12:32:58 -05:00
|
|
|
break;
|
2015-07-10 13:36:21 +02:00
|
|
|
|
|
|
|
case 'dns':
|
|
|
|
$data['tag'] = $sla_config['rttMonEchoAdminTargetAddressString'];
|
2016-08-28 12:32:58 -05:00
|
|
|
break;
|
2015-07-10 13:36:21 +02:00
|
|
|
|
|
|
|
case 'echo':
|
2017-08-08 14:14:58 -05:00
|
|
|
$data['tag'] = IP::fromHexString($sla_config['rttMonEchoAdminTargetAddress'], true);
|
2016-08-28 12:32:58 -05:00
|
|
|
break;
|
2015-08-01 17:07:49 +10:00
|
|
|
|
|
|
|
case 'jitter':
|
2020-07-30 22:38:52 +02:00
|
|
|
if ($sla_config['rttMonEchoAdminCodecType'] != 'notApplicable') {
|
|
|
|
$codec_info = " (" . $sla_config['rttMonEchoAdminCodecType'] . " @ " . preg_replace('/milliseconds/', 'ms', $sla_config['rttMonEchoAdminCodecInterval']) . ")";
|
|
|
|
} else {
|
|
|
|
$codec_info = '';
|
|
|
|
}
|
|
|
|
$data['tag'] = IP::fromHexString($sla_config['rttMonEchoAdminTargetAddress'], true) . ":" . $sla_config['rttMonEchoAdminTargetPort'] . $codec_info;
|
2015-08-01 17:07:49 +10:00
|
|
|
break;
|
2015-07-10 13:36:21 +02:00
|
|
|
}//end switch
|
|
|
|
}//end if
|
|
|
|
|
|
|
|
if (!$sla_id) {
|
|
|
|
$sla_id = dbInsert($data, 'slas');
|
|
|
|
echo '+';
|
2016-08-28 12:32:58 -05:00
|
|
|
} else {
|
2015-07-10 13:36:21 +02:00
|
|
|
// Remove from the list
|
|
|
|
$existing_slas = array_diff($existing_slas, array($sla_id));
|
|
|
|
|
Fix mysql bug in cisco-sla module (#10357)
* Update cisco-sla.inc.php
Fix SQL error during discovery of cisco-sla.
This error points to /opt/librenms/includes/discovery/cisco-sla.inc.php(80).
LOG ERROR:
[2019-06-18 07:07:01] production.ERROR: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters (SQL: UPDATE slas set device_id=39,sla_nr=1,owner=,tag=xxx.xxx.xxx.xxx,rtt_type=echo,status=1,opstatus=0,deleted=0 WHERE sla_id = 5) (SQL: UPDATE slas set device_id=39,sla_nr=1,owner=,tag=xxx.xxx.xxx.xxx,rtt_type=echo,status=1,opstatus=0,deleted=0 WHERE sla_id = 5)#0 /opt/librenms/includes/discover
y/cisco-sla.inc.php(80): dbUpdate(Array, ‘slas’, ’sla_id = :sla…’, Array)
#1 /opt/librenms/includes/discovery/functions.inc.php(179): include(’/opt/librenms/i…’)
#2 /opt/librenms/discovery.php(120): discover_device(Array, false)
#3 {main}
I suggest to change this lines of code in cisco-sla.inc.php to avoid this error:
line 80: dbUpdate($data, ‘slas’, ’sla_id = :sla_id’, array(‘sla_id’ => $sla_id));
change to: dbUpdate($data, ‘slas’, ’sla_id = ?’, array($sla_id));
line 87: dbUpdate(array(‘deleted’ => 1), ‘slas’, ’sla_id = :sla_id’, array(‘sla_id’ => $existing_sla));
change to: dbUpdate(array(‘deleted’ => 1), ‘slas’, ’sla_id = ?’, array($existing_sla));
* Fix quotes
* Missed one
2019-06-21 14:16:19 +02:00
|
|
|
dbUpdate($data, 'slas', 'sla_id = ?', [$sla_id]);
|
2015-07-10 13:36:21 +02:00
|
|
|
echo '.';
|
|
|
|
}
|
|
|
|
}//end foreach
|
|
|
|
|
|
|
|
// Mark all remaining SLAs as deleted
|
|
|
|
foreach ($existing_slas as $existing_sla) {
|
Fix mysql bug in cisco-sla module (#10357)
* Update cisco-sla.inc.php
Fix SQL error during discovery of cisco-sla.
This error points to /opt/librenms/includes/discovery/cisco-sla.inc.php(80).
LOG ERROR:
[2019-06-18 07:07:01] production.ERROR: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters (SQL: UPDATE slas set device_id=39,sla_nr=1,owner=,tag=xxx.xxx.xxx.xxx,rtt_type=echo,status=1,opstatus=0,deleted=0 WHERE sla_id = 5) (SQL: UPDATE slas set device_id=39,sla_nr=1,owner=,tag=xxx.xxx.xxx.xxx,rtt_type=echo,status=1,opstatus=0,deleted=0 WHERE sla_id = 5)#0 /opt/librenms/includes/discover
y/cisco-sla.inc.php(80): dbUpdate(Array, ‘slas’, ’sla_id = :sla…’, Array)
#1 /opt/librenms/includes/discovery/functions.inc.php(179): include(’/opt/librenms/i…’)
#2 /opt/librenms/discovery.php(120): discover_device(Array, false)
#3 {main}
I suggest to change this lines of code in cisco-sla.inc.php to avoid this error:
line 80: dbUpdate($data, ‘slas’, ’sla_id = :sla_id’, array(‘sla_id’ => $sla_id));
change to: dbUpdate($data, ‘slas’, ’sla_id = ?’, array($sla_id));
line 87: dbUpdate(array(‘deleted’ => 1), ‘slas’, ’sla_id = :sla_id’, array(‘sla_id’ => $existing_sla));
change to: dbUpdate(array(‘deleted’ => 1), ‘slas’, ’sla_id = ?’, array($existing_sla));
* Fix quotes
* Missed one
2019-06-21 14:16:19 +02:00
|
|
|
dbUpdate(['deleted' => 1], 'slas', 'sla_id = ?', [$existing_sla]);
|
2015-07-10 13:36:21 +02:00
|
|
|
echo '-';
|
2012-04-09 12:53:44 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 13:36:21 +02:00
|
|
|
echo "\n";
|
|
|
|
}
|