commit version 22.12.12447

This commit is contained in:
2023-01-01 22:36:12 -05:00
parent af1b03d79f
commit b948283a96
744 changed files with 620715 additions and 27381 deletions

View File

@ -506,7 +506,7 @@ function update_alert_table($alert, $silent = TRUE) {
if (!$silent) {
if (is_cli()) {
print_cli("Alert Checker " . str_pad("'${alert['alert_name']}'", 30, ' ', STR_PAD_LEFT) . ": " . safe_count($existing_entities) . " existing, " . safe_count($entities) . " new entries (+" . safe_count($add) . "/-" . safe_count($remove) . ").\n");
print_cli("Alert Checker " . str_pad("'{$alert['alert_name']}'", 30, ' ', STR_PAD_LEFT) . ": " . safe_count($existing_entities) . " existing, " . safe_count($entities) . " new entries (+" . safe_count($add) . "/-" . safe_count($remove) . ").\n");
} else {
print_message(safe_count($existing_entities) . " existing entries.<br />" .
safe_count($entities) . " new entries.<br />" .
@ -945,6 +945,27 @@ function test_condition($value_a, $condition, $value_b) {
//$alert = !in_array($value_a, $value_b);
break;
case 'between':
case 'notbetween':
$alert = FALSE;
if (!is_array($value_b)) {
$value_b = array_map('trim', explode(',', $value_b));
} // perhaps extend to allow space-separated values
if(isset($value_b[0]) && is_numeric($value_b[0]) && isset($value_b[1]) && is_numeric($value_b[1]))
{
if($condition == "between") {
if ($value_a < $value_b[0] || $value_a > $value_b[1]) { $alert = TRUE; }
} else { // notbetween
if ($value_a > $value_b[0] && $value_a < $value_b[1]) { $alert = TRUE; }
}
} else {
print_debug("ERROR: Invalid values passed to 'between' operator in test_condition().");
}
break;
default:
print_debug("ERROR: Unknown condition '$condition' passed to test_condition().");
$alert = FALSE;
@ -1043,13 +1064,13 @@ function match_device($device, $attributes, $ignore = TRUE)
break;
case 'in':
case 'list':
$where .= generate_query_values(explode(',', $attrib['value']), 'd.' . $attrib['attrib']);
$where .= generate_query_values_and(explode(',', $attrib['value']), 'd.' . $attrib['attrib']);
break;
case '!in':
case '!list':
case 'notin':
case 'notlist':
$where .= generate_query_values(explode(',', $attrib['value']), 'd.' . $attrib['attrib'], '!=');
$where .= generate_query_values_and(explode(',', $attrib['value']), 'd.' . $attrib['attrib'], '!=');
break;
case 'include':
case 'includes':
@ -1190,13 +1211,13 @@ function match_device_entities($device_id, $entity_attribs, $entity_type)
break;
case 'in':
case 'list':
$sql .= generate_query_values(explode(',', $attrib['value']), $attrib['attrib'], NULL, OBS_DB_IFNULL);
$sql .= generate_query_values_and(explode(',', $attrib['value']), $attrib['attrib'], NULL, [ 'ifnull' ]);
break;
case '!in':
case '!list':
case 'notin':
case 'notlist':
$sql .= generate_query_values(explode(',', $attrib['value']), $attrib['attrib'], '!=', OBS_DB_IFNULL);
$sql .= generate_query_values_and(explode(',', $attrib['value']), $attrib['attrib'], '!=', [ 'ifnull' ]);
break;
case 'include':
case 'includes':
@ -1208,7 +1229,7 @@ function match_device_entities($device_id, $entity_attribs, $entity_type)
}
case 'group_id':
$values = get_group_entities($attrib['value']);
$sql .= generate_query_values($values, $entity_type['table_fields']['id']);
$sql .= generate_query_values_and($values, $entity_type['table_fields']['id']);
break;
}
}
@ -1545,19 +1566,18 @@ function alert_notifier($entry, $type = "alert", $log_id = NULL)
// DOCME needs phpdoc block
// TESTME needs unit testing
function alert_generate_subject($device, $prefix, $message_tags)
{
$subject = "$prefix: [" . $device['hostname'] . ']';
function alert_generate_subject($device, $prefix, $message_tags) {
$subject = "$prefix: [" . device_name($device) . ']';
if ($message_tags['ENTITY_TYPE']) {
$subject .= ' [' . $message_tags['ENTITY_TYPE'] . ']';
}
if ($message_tags['ENTITY_NAME'] && $message_tags['ENTITY_NAME'] != $device['hostname']) {
$subject .= ' [' . $message_tags['ENTITY_NAME'] . ']';
}
$subject .= ' ' . $message_tags['ALERT_MESSAGE'];
if ($message_tags['ENTITY_TYPE']) {
$subject .= ' [' . $message_tags['ENTITY_TYPE'] . ']';
}
if ($message_tags['ENTITY_NAME'] && $message_tags['ENTITY_NAME'] != $device['hostname']) {
$subject .= ' [' . $message_tags['ENTITY_NAME'] . ']';
}
$subject .= ' ' . $message_tags['ALERT_MESSAGE'];
return $subject;
return $subject;
}
function alert_generate_tags($entry, $type = "alert")
@ -1766,7 +1786,7 @@ function get_alert_contacts($device, $alert_id, $notification_type) {
$contacts = array();
if ($device['ignore']) {
print_error("Device '${device['hostname']}' set ignored in Device -> Edit -> Settings.");
print_error("Device '{$device['hostname']}' set ignored in Device -> Edit -> Settings.");
return $contacts;
}
if ($GLOBALS['config']['alerts']['disable']['all']) {
@ -1774,7 +1794,7 @@ function get_alert_contacts($device, $alert_id, $notification_type) {
return $contacts;
}
if (get_dev_attrib($device, 'disable_notify')) {
print_error("Alert notifications disabled for device '${device['hostname']}' in Device -> Edit -> Alerts.");
print_error("Alert notifications disabled for device '{$device['hostname']}' in Device -> Edit -> Alerts.");
return $contacts;
}
@ -1828,266 +1848,257 @@ function get_alert_contacts($device, $alert_id, $notification_type) {
return $contacts;
}
function process_notifications($vars = array())
{
global $config;
function process_notifications($vars = []) {
global $config;
$result = array();
$params = array();
$result = [];
$params = [];
$sql = 'SELECT * FROM `notifications_queue` WHERE 1';
$sql = 'SELECT * FROM `notifications_queue` WHERE 1';
foreach ($vars as $var => $value)
{
switch ($var)
{
case 'device_id':
case 'notification_id':
case 'aca_type':
$sql .= generate_query_values($value, $var);
//$sql .= ' AND `device_id` = ?';
//$params[] = $value;
break;
foreach ($vars as $var => $value) {
switch ($var) {
case 'device_id':
case 'notification_id':
case 'aca_type':
$sql .= generate_query_values_and($value, $var);
//$sql .= ' AND `device_id` = ?';
//$params[] = $value;
break;
}
}
/**
* switch ($notification_type)
* {
* case 'alert':
* case 'syslog':
* // Alerts/syslog required device_id
* $sql .= ' AND `device_id` = ?';
* $params[] = $device['device_id'];
* break;
* case 'web':
* // Currently not used
* break;
* }
**/
foreach (dbFetchRows($sql, $params) as $notification) {
print_debug_vars($notification);
// Recheck if current notification is locked
$locked = dbFetchCell('SELECT `notification_locked` FROM `notifications_queue` WHERE `notification_id` = ?', [ $notification['notification_id'] ]); //ALTER TABLE `notifications_queue` ADD `notification_locked` BOOLEAN NOT NULL DEFAULT FALSE AFTER `notification_entry`;
//if ($locked || $locked === NULL || $locked === FALSE) // If notification not exist or column 'notification_locked' not exist this query return NULL or (possible?) FALSE
if ($locked || $locked === FALSE) {
// Notification already processed by other alerter or has already been sent
print_debug('Notification ID ('.$notification['notification_id'].') locked or not exist anymore in table. Skipped.');
print_debug_vars($notification, 1);
continue;
}
// Lock current notification
dbUpdate([ 'notification_locked' => 1 ], 'notifications_queue', '`notification_id` = ?', [ $notification['notification_id'] ]);
$notification_count = 0;
$endpoint = safe_json_decode($notification['endpoints']);
// If this notification is older than lifetime, unset the endpoints so that it is removed.
if ((time() - $notification['notification_added']) > $notification['notification_lifetime']) {
$endpoint = [];
print_debug('Notification ID ('.$notification['notification_id'].') expired.');
print_debug_vars($notification, 1);
} else {
$notification_age = time() - $notification['notification_added'];
$notification_timeleft = $notification['notification_lifetime'] - $notification_age;
}
$message_tags = safe_json_decode($notification['message_tags']);
$message_graphs = safe_json_decode($notification['message_graphs']);
if (is_array($message_graphs) && count($message_graphs)) {
$message_tags['ENTITY_GRAPHS_ARRAY'] = $message_graphs;
}
if (isset($message_tags['ALERT_UNIXTIME']) && empty($message_tags['DURATION'])) {
$message_tags['DURATION'] = format_uptime(time() - $message_tags['ALERT_UNIXTIME']) . ' (' . $message_tags['ALERT_TIMESTAMP'] . ')';
}
if (isset($GLOBALS['config']['alerts']['disable'][$endpoint['contact_method']]) &&
$GLOBALS['config']['alerts']['disable'][$endpoint['contact_method']]) {
$result[$endpoint['contact_method']] = 'disabled';
unset($endpoint);
continue;
} // Skip if method disabled globally
$transport = $endpoint['contact_method']; // Just set transport name for use in includes
$method_include = $GLOBALS['config']['install_dir'] . '/includes/alerting/' . $transport . '.inc.php';
$is_transport_def = isset($config['transports'][$transport]['notification']); // Is definition for transport
$is_transport_file = is_file($method_include); // Is file based transport
if ($is_transport_def || $is_transport_file) {
//print_cli_data("Notifying", "[" . $endpoint['contact_method'] . "] " . $endpoint['contact_descr'] . ": " . $endpoint['contact_endpoint']);
print_cli_data_field("Notifying");
echo("[" . $endpoint['contact_method'] . "] " . $endpoint['contact_descr'] . ": " . $endpoint['contact_endpoint']);
// Split out endpoint data as stored JSON in the database into array for use in transport
// The original string also remains available as the contact_endpoint key
foreach (safe_json_decode($endpoint['contact_endpoint']) as $field => $value) {
$endpoint[$field] = $value;
}
// Clean data array for use with definition based processing
$data = [];
$message = [];
// File based transport
if ($is_transport_file) {
print_debug("\nUse file-based notification transport");
include($method_include);
}
// Definition based generate transport options, url and process request
if ($is_transport_def) {
print_debug("\nUse definition based notification transport");
$notification_def = $config['transports'][$transport]['notification'];
// Pass message tags to request as ARRAY (example in opsgenie)
if (isset($notification_def['message_tags']) && $notification_def['message_tags']) {
$data = array_merge($data, $message_tags);
unset($data['ENTITY_GRAPHS_ARRAY']);
//print_debug_vars(safe_json_encode($data));
} elseif (isset($notification_def['message_json'])) {
// Pass raw json as $data (example in webhook-json)
$json = array_tag_replace(generate_transport_tags($transport, $endpoint, [], [], array_map('json_escape', $message_tags)), $notification_def['message_json']);
//print_vars(generate_transport_tags($transport, $endpoint, [], [], array_map('json_escape', $message_tags)));
//print_vars($json);
$json_array = safe_json_decode($json);
//print_vars($json_array);
if (!safe_empty($json_array)) {
$data = array_merge($data, $json_array);
}
unset($json, $json_array);
} else {
// Or set common title tag
$message['title'] = $message_tags['TITLE'];
}
// Generate notification message from tags using mustache template system
if (isset($endpoint['contact_message_custom']) && $endpoint['contact_message_custom'] &&
empty(!$endpoint['contact_message_template'])) {
// Use user defined template
print_debug("User-defined message template is used.");
$message['text'] = simple_template($endpoint['contact_message_template'], $message_tags);
} elseif (isset($notification_def['message_template'])) {
print_debug("Definition message template file is used.");
// template can have tags (ie telegram)
if (str_contains($notification_def['message_template'], '%')) {
//print_vars($notification_def['message_template']);
$message_template = array_tag_replace(generate_transport_tags($transport, $endpoint), $notification_def['message_template']);
$message_template = strtolower($message_template);
//print_vars($message_template);
} else {
$message_template = $notification_def['message_template'];
}
// Template in file, see: includes/templates/notification/
$message['text'] = simple_template($message_template, $message_tags, [ 'is_file' => TRUE ]);
//$data['message'] = $message['text'];
} elseif (isset($notification_def['message_text'])) {
print_debug("Definition message template is used.");
// Template in definition
$message['text'] = simple_template($notification_def['message_text'], $message_tags);
//$data['message'] = $message['text'];
}
// Afterall message transform
if (isset($notification_def['message_transform']) && $message['text']) {
$message['text'] = string_transform($message['text'], $notification_def['message_transform']);
}
// Generate transport tags, used for rewrites in definition
$tags = generate_transport_tags($transport, $endpoint, $data, $message, $message_tags);
// Generate context/options with encoded data and transport specific api headers
$options = generate_http_context($transport, $tags, $data);
// Always get response also with bad status
$options['ignore_errors'] = TRUE;
// Retry count (default 1, max 10). See discord definition
$request_retry = 1;
$request_sleep = 0;
if (isset($notification_def['request_retry']) && is_intnum($notification_def['request_retry']) &&
$notification_def['request_retry'] > 1 && $notification_def['request_retry'] <= 10) {
$request_retry = $notification_def['request_retry'];
$request_sleep = 1;
}
// API URL to POST to
$url = generate_http_url($transport, $tags, $data);
// Send out API call and parse response
for ($retry = 1; $retry <= $request_retry; $retry++) {
print_debug("Request #$retry:");
if ($notify_status['success'] = test_http_request($transport, get_http_request($url, $options))) {
// stop for on success
break;
}
// wait little time
sleep($request_sleep);
}
// Clean after transport data and request generation
unset($message, $color, $url, $data, $options, $tags);
}
// FIXME check success
// FIXME log notification + success/failure!
if ($notify_status['success']) {
$result[$transport] = 'ok';
unset($endpoint);
$notification_count++;
print_message(" [%gOK%n]", 'color');
} else {
$result[$transport] = 'false';
print_message(" [%rFALSE%n]", 'color');
if ($notify_status['error']) {
print_cli_data_field('', 4);
print_message("[%y".$notify_status['error']."%n]", 'color');
}
}
} else {
$result[$transport] = 'missing';
unset($endpoint); // Remove it because it's dumb and doesn't exist. Don't retry it if it doesn't exist.
print_cli_data("Missing include", $method_include);
}
/**
* switch ($notification_type)
* {
* case 'alert':
* case 'syslog':
* // Alerts/syslog required device_id
* $sql .= ' AND `device_id` = ?';
* $params[] = $device['device_id'];
* break;
* case 'web':
* // Currently not used
* break;
* }
**/
foreach (dbFetchRows($sql, $params) as $notification) {
print_debug_vars($notification);
// Recheck if current notification is locked
$locked = dbFetchCell('SELECT `notification_locked` FROM `notifications_queue` WHERE `notification_id` = ?', array($notification['notification_id'])); //ALTER TABLE `notifications_queue` ADD `notification_locked` BOOLEAN NOT NULL DEFAULT FALSE AFTER `notification_entry`;
//if ($locked || $locked === NULL || $locked === FALSE) // If notification not exist or column 'notification_locked' not exist this query return NULL or (possible?) FALSE
if ($locked || $locked === FALSE)
{
// Notification already processed by other alerter or has already been sent
print_debug('Notification ID ('.$notification['notification_id'].') locked or not exist anymore in table. Skipped.');
print_debug_vars($notification, 1);
continue;
} else {
// Lock current notification
dbUpdate(array('notification_locked' => 1), 'notifications_queue', '`notification_id` = ?', array($notification['notification_id']));
// Remove notification from queue,
// currently in any case, lifetime, added time and result status is ignored!
switch ($notification['aca_type']) {
case 'alert':
if ($notification_count) {
dbUpdate([ 'notified' => 1 ], 'alert_log', '`event_id` = ?', [ $notification['log_id'] ]);
}
break;
$notification_count = 0;
$endpoint = safe_json_decode($notification['endpoints']);
// If this notification is older than lifetime, unset the endpoints so that it is removed.
if ((time() - $notification['notification_added']) > $notification['notification_lifetime']) {
$endpoint = array();
print_debug('Notification ID ('.$notification['notification_id'].') expired.');
print_debug_vars($notification, 1);
} else {
$notification_age = time() - $notification['notification_added'];
$notification_timeleft = $notification['notification_lifetime'] - $notification_age;
case 'syslog':
if ($notification_count) {
dbUpdate([ 'notified' => 1 ], 'syslog_alerts', '`lal_id` = ?', [ $notification['log_id'] ]);
}
break;
$message_tags = safe_json_decode($notification['message_tags']);
$message_graphs = safe_json_decode($notification['message_graphs']);
if (is_array($message_graphs) && count($message_graphs)) {
$message_tags['ENTITY_GRAPHS_ARRAY'] = $message_graphs;
}
if (isset($message_tags['ALERT_UNIXTIME']) && empty($message_tags['DURATION'])) {
$message_tags['DURATION'] = format_uptime(time() - $message_tags['ALERT_UNIXTIME']) . ' (' . $message_tags['ALERT_TIMESTAMP'] . ')';
}
if (isset($GLOBALS['config']['alerts']['disable'][$endpoint['contact_method']]) &&
$GLOBALS['config']['alerts']['disable'][$endpoint['contact_method']]) {
$result[$endpoint['contact_method']] = 'disabled';
unset($endpoint);
continue;
} // Skip if method disabled globally
$transport = $endpoint['contact_method']; // Just set transport name for use in includes
$method_include = $GLOBALS['config']['install_dir'] . '/includes/alerting/' . $transport . '.inc.php';
$is_transport_def = isset($config['transports'][$transport]['notification']); // Is definition for transport
$is_transport_file = is_file($method_include); // Is file based transport
if ($is_transport_def || $is_transport_file)
{
//print_cli_data("Notifying", "[" . $endpoint['contact_method'] . "] " . $endpoint['contact_descr'] . ": " . $endpoint['contact_endpoint']);
print_cli_data_field("Notifying");
echo("[" . $endpoint['contact_method'] . "] " . $endpoint['contact_descr'] . ": " . $endpoint['contact_endpoint']);
// Split out endpoint data as stored JSON in the database into array for use in transport
// The original string also remains available as the contact_endpoint key
foreach (safe_json_decode($endpoint['contact_endpoint']) as $field => $value) {
$endpoint[$field] = $value;
}
// Clean data array for use with definition based processing
$data = array();
$message = array();
// File based transport
if ($is_transport_file)
{
print_debug("\nUse file-based notification transport");
include($method_include);
}
// Definition based generate transport options, url and process request
if ($is_transport_def)
{
print_debug("\nUse definition based notification transport");
$notification_def = $config['transports'][$transport]['notification'];
// Pass message tags to request as ARRAY (example in opsgenie)
if (isset($notification_def['message_tags']) && $notification_def['message_tags']) {
$data = array_merge($data, $message_tags);
unset($data['ENTITY_GRAPHS_ARRAY']);
//print_debug_vars(safe_json_encode($data));
} elseif (isset($notification_def['message_json'])) {
// Pass raw json as $data (example in webhook-json)
$json = array_tag_replace(generate_transport_tags($transport, $endpoint, [], [], array_map('json_escape', $message_tags)), $notification_def['message_json']);
//print_vars(generate_transport_tags($transport, $endpoint, [], [], array_map('json_escape', $message_tags)));
//print_vars($json);
$json_array = safe_json_decode($json);
//print_vars($json_array);
if (!safe_empty($json_array)) {
$data = array_merge($data, $json_array);
}
unset($json, $json_array);
} else {
// Or set common title tag
$message['title'] = $message_tags['TITLE'];
}
// Generate notification message from tags using mustache template system
if (isset($endpoint['contact_message_custom']) && $endpoint['contact_message_custom'] &&
empty(!$endpoint['contact_message_template'])) {
// Use user defined template
print_debug("User-defined message template is used.");
$message['text'] = simple_template($endpoint['contact_message_template'], $message_tags);
} elseif (isset($notification_def['message_template'])) {
print_debug("Definition message template file is used.");
// template can have tags (ie telegram)
if (str_contains($notification_def['message_template'], '%')) {
//print_vars($notification_def['message_template']);
$message_template = array_tag_replace(generate_transport_tags($transport, $endpoint), $notification_def['message_template']);
$message_template = strtolower($message_template);
//print_vars($message_template);
} else {
$message_template = $notification_def['message_template'];
}
// Template in file, see: includes/templates/notification/
$message['text'] = simple_template($message_template, $message_tags, array('is_file' => TRUE));
//$data['message'] = $message['text'];
} elseif (isset($notification_def['message_text'])) {
print_debug("Definition message template is used.");
// Template in definition
$message['text'] = simple_template($notification_def['message_text'], $message_tags);
//$data['message'] = $message['text'];
}
// Afterall message transform
if (isset($notification_def['message_transform']) && $message['text']) {
$message['text'] = string_transform($message['text'], $notification_def['message_transform']);
}
// Generate transport tags, used for rewrites in definition
$tags = generate_transport_tags($transport, $endpoint, $data, $message, $message_tags);
// Generate context/options with encoded data and transport specific api headers
$options = generate_http_context($transport, $tags, $data);
// Always get response also with bad status
$options['ignore_errors'] = TRUE;
// Retry count (default 1, max 10). See discord definition
$request_retry = 1;
$request_sleep = 0;
if (isset($notification_def['request_retry']) && is_intnum($notification_def['request_retry']) &&
$notification_def['request_retry'] > 1 && $notification_def['request_retry'] <= 10) {
$request_retry = $notification_def['request_retry'];
$request_sleep = 1;
}
// API URL to POST to
$url = generate_http_url($transport, $tags, $data);
// Send out API call and parse response
for ($retry = 1; $retry <= $request_retry; $retry++) {
print_debug("Request #$retry:");
if ($notify_status['success'] = test_http_request($transport, get_http_request($url, $options))) {
// stop for on success
break;
}
// wait little time
sleep($request_sleep);
}
// Clean after transport data and request generation
unset($message, $color, $url, $data, $options, $tags);
}
// FIXME check success
// FIXME log notification + success/failure!
if ($notify_status['success'])
{
$result[$transport] = 'ok';
unset($endpoint);
$notification_count++;
print_message(" [%gOK%n]", 'color');
} else {
$result[$transport] = 'false';
print_message(" [%rFALSE%n]", 'color');
if ($notify_status['error'])
{
print_cli_data_field('', 4);
print_message("[%y".$notify_status['error']."%n]", 'color');
}
}
} else {
$result[$transport] = 'missing';
unset($endpoint); // Remove it because it's dumb and doesn't exist. Don't retry it if it doesn't exist.
print_cli_data("Missing include", $method_include);
}
// Remove notification from queue,
// currently in any case, lifetime, added time and result status is ignored!
switch ($notification['aca_type'])
{
case 'alert':
if ($notification_count) {
dbUpdate(array('notified' => 1), 'alert_log', '`event_id` = ?', array($notification['log_id']));
}
break;
case 'syslog':
if ($notification_count) {
dbUpdate(array('notified' => 1), 'syslog_alerts', '`lal_id` = ?', array($notification['log_id']));
}
break;
case 'web':
// Currently not used
break;
}
if (empty($endpoint))
{
dbDelete('notifications_queue', '`notification_id` = ?', array($notification['notification_id']));
} else {
// Set the endpoints to the remaining un-notified endpoints and unlock the queue entry.
dbUpdate(array('notification_locked' => 0, 'endpoints' => safe_json_encode($endpoint)), 'notifications_queue', '`notification_id` = ?', array($notification['notification_id']));
}
case 'web':
// Currently not used
break;
}
return $result;
if (empty($endpoint)) {
dbDelete('notifications_queue', '`notification_id` = ?', [ $notification['notification_id'] ]);
} else {
// Set the endpoints to the remaining un-notified endpoints and unlock the queue entry.
dbUpdate(array('notification_locked' => 0, 'endpoints' => safe_json_encode($endpoint)), 'notifications_queue', '`notification_id` = ?', [ $notification['notification_id'] ]);
}
}
return $result;
}
// Use this function to write to the alert_log table
@ -2193,12 +2204,10 @@ function check_thresholds($alert_low, $warn_low, $warn_high, $alert_high, $value
* @param array $message_tags (optional) Array with all message tags
* @return array HTTP Context which can used in get_http_request_test() or get_http_request()
*/
function generate_transport_tags($transport, $tags = array(), $params = array(), $message = array(), $message_tags = array())
{
function generate_transport_tags($transport, $tags = [], $params = [], $message = [], $message_tags = []) {
global $config;
if (!isset($message['message']))
{
if (!isset($message['message'])) {
// Just use text version of message (also possible in future html, etc
$message['message'] = $message['text'];
}
@ -2206,38 +2215,39 @@ function generate_transport_tags($transport, $tags = array(), $params = array(),
// If transport config options exist, merge it with tags array
// for use in replace/etc, ie: smsbox
if (isset($config[$transport]))
{
foreach ($config[$transport] as $param => $value)
{
if (!isset($tags[$param]) || $tags[$param] === '')
{
if (isset($config[$transport])) {
foreach ($config[$transport] as $param => $value) {
if (!isset($tags[$param]) || $tags[$param] === '') {
$tags[$param] = $value;
}
}
}
// Set defaults and transform params if required
$def_params = array();
$def_params = [];
// Merge required/global and optional parameters
foreach (array_keys($config['transports'][$transport]['parameters']) as $tmp)
{
foreach (array_keys($config['transports'][$transport]['parameters']) as $tmp) {
$def_params = array_merge($def_params, $config['transports'][$transport]['parameters'][$tmp]);
}
foreach ($def_params as $param => $entry)
{
foreach ($def_params as $param => $entry) {
// Set default if tag empty
if (isset($entry['default']) && strlen($tags[$param]) == 0)
{
if (isset($entry['default']) && safe_empty($tags[$param])) {
$tags[$param] = $entry['default'];
}
// Transform param if defined
if (isset($entry['transform']) && isset($tags[$param]))
{
if (isset($entry['transform'], $tags[$param])) {
$tags[$param] = string_transform($tags[$param], $entry['transform']);
}
}
//print_vars($tags);
// if ($config['transports'][$transport]['notification']['request_format'] === 'json') {
// // escape tags for json
// print_debug("Transport TAGs escaped for JSON.");
// if (OBS_DEBUG > 1) {
// print_debug_vars(array_map('json_escape', $tags));
// }
// return array_map('json_escape', $tags);
// }
return $tags;
}
@ -2349,13 +2359,13 @@ function get_alert_entities_from_assocs($alert)
break;
case 'in':
case 'list':
$where .= generate_query_values(get_var_csv($attrib['value']), '`devices`.' . $attrib['attrib'], NULL, OBS_DB_IFNULL);
$where .= generate_query_values_and(get_var_csv($attrib['value']), '`devices`.' . $attrib['attrib'], NULL, [ 'ifnull' ]);
break;
case '!in':
case '!list':
case 'notin':
case 'notlist':
$where .= generate_query_values(get_var_csv($attrib['value']), '`devices`.' . $attrib['attrib'], '!=', OBS_DB_IFNULL);
$where .= generate_query_values_and(get_var_csv($attrib['value']), '`devices`.' . $attrib['attrib'], '!=', [ 'ifnull' ]);
break;
case 'include':
case 'includes':
@ -2365,7 +2375,7 @@ function get_alert_entities_from_assocs($alert)
$attrib['value'] = group_id_by_name($attrib['value']);
case 'group_id':
$values = get_group_entities($attrib['value']);
$where .= generate_query_values($values, "`devices`.`device_id`");
$where .= generate_query_values_and($values, "`devices`.`device_id`");
break;
}
break;
@ -2444,13 +2454,13 @@ function get_alert_entities_from_assocs($alert)
break;
case 'in':
case 'list':
$where .= generate_query_values(get_var_csv($attrib['value']), $attrib['attrib'], NULL, OBS_DB_IFNULL);
$where .= generate_query_values_and(get_var_csv($attrib['value']), $attrib['attrib'], NULL, [ 'ifnull' ]);
break;
case '!in':
case '!list':
case 'notin':
case 'notlist':
$where .= generate_query_values(get_var_csv($attrib['value']), $attrib['attrib'], '!=', OBS_DB_IFNULL);
$where .= generate_query_values_and(get_var_csv($attrib['value']), $attrib['attrib'], '!=', [ 'ifnull' ]);
break;
case 'include':
case 'includes':
@ -2463,7 +2473,7 @@ function get_alert_entities_from_assocs($alert)
if($group['entity_type'] == $entity_type)
{
$values = get_group_entities($attrib['value']);
$where .= generate_query_values($values, $entity_type['table_fields']['id']);
$where .= generate_query_values_and($values, $entity_type['table_fields']['id']);
}
break;
}
@ -3133,7 +3143,7 @@ function parse_qb_rules($entity_type, $rules, $ignore = FALSE) {
//$group_ids = get_group_ids_by_name_match($rule['value_original'], $entity_type);
if ($values = get_group_entities($group_ids)) {
//$values = get_group_entities($group['group_id']);
$part = generate_query_values($values, ($table === "device" ? "devices.device_id" : $table_type_data['table'] . '.' . $entity_type_data['table_fields']['id']), NULL, FALSE);
$part = generate_query_values_ng($values, ($table === "device" ? "devices.device_id" : $table_type_data['table'] . '.' . $entity_type_data['table_fields']['id']));
}
break;
default:
@ -3152,7 +3162,7 @@ function parse_qb_rules($entity_type, $rules, $ignore = FALSE) {
//$group_ids = get_group_ids_by_name_match($rule['value_original'], $entity_type);
if ($values = get_group_entities($group_ids)) {
//$values = get_group_entities($group['group_id']);
$part = generate_query_values($values, ($table === "device" ? "devices.device_id" : $table_type_data['table'] . '.' . $entity_type_data['table_fields']['id']), '!=', FALSE);
$part = generate_query_values_ng($values, ($table === "device" ? "devices.device_id" : $table_type_data['table'] . '.' . $entity_type_data['table_fields']['id']), '!=');
}
break;
default:
@ -3181,7 +3191,7 @@ function parse_qb_rules($entity_type, $rules, $ignore = FALSE) {
switch ($field) {
case 'group_id':
$values = get_group_entities($rule['value_original']);
$part = generate_query_values($values, ($table === "device" ? "devices.device_id" : $table_type_data['table'].'.'.$entity_type_data['table_fields']['id']), NULL, FALSE);
$part = generate_query_values_ng($values, ($table === "device" ? "devices.device_id" : $table_type_data['table'].'.'.$entity_type_data['table_fields']['id']));
break;
default:
if (isset($entity_attribs[$field]['transformations'])) {
@ -3196,7 +3206,7 @@ function parse_qb_rules($entity_type, $rules, $ignore = FALSE) {
//r($values);
//logfile('alerts.log', $rule['field_quoted'] . ': ' . var_export($values, TRUE));
//logfile('alerts.log', var_export($rule, TRUE));
$part = generate_query_values($values, $rule['field_quoted'], NULL, OBS_DB_NO_LEADING_AND | OBS_DB_IFNULL);
$part = generate_query_values_ng($values, $rule['field_quoted'], NULL, [ 'ifnull' ]);
break;
}
//print_vars($parts);
@ -3206,7 +3216,7 @@ function parse_qb_rules($entity_type, $rules, $ignore = FALSE) {
switch ($field) {
case 'group_id':
$values = get_group_entities($rule['value_original']);
$part = generate_query_values($values, ($table === "device" ? "devices.device_id" : $table_type_data['table'].'.'.$entity_type_data['table_fields']['id']), '!=', FALSE);
$part = generate_query_values_ng($values, ($table === "device" ? "devices.device_id" : $table_type_data['table'].'.'.$entity_type_data['table_fields']['id']), '!=');
break;
default:
if (isset($entity_attribs[$field]['transformations'])) {
@ -3218,7 +3228,7 @@ function parse_qb_rules($entity_type, $rules, $ignore = FALSE) {
// When transformations not used, can use other value overrides, ie function calls
$values = get_var_csv($rule['value']);
}
$part = generate_query_values($values, $rule['field_quoted'], '!=', OBS_DB_NO_LEADING_AND | OBS_DB_IFNULL);
$part = generate_query_values_ng($values, $rule['field_quoted'], '!=', [ 'ifnull' ]);
break;
}
break;
@ -3253,41 +3263,35 @@ function parse_qb_rules($entity_type, $rules, $ignore = FALSE) {
}
function migrate_assoc_rules($entry)
{
function migrate_assoc_rules($entry) {
$entity_type = $entry['entity_type'];
$ruleset = array();
$ruleset = [];
$ruleset['condition'] = 'OR';
$ruleset['valid'] = 'true';
foreach ($entry['assocs'] as $assoc)
{
foreach ($entry['assocs'] as $assoc) {
$x = array();
$x = [];
$x['condition'] = 'AND';
$a = array('device' => $assoc['device_attribs'], 'entity' => $assoc['entity_attribs']);
$a = [ 'device' => $assoc['device_attribs'], 'entity' => $assoc['entity_attribs'] ];
foreach ($a as $type => $rules)
{
foreach ($a as $type => $rules) {
foreach ($rules as $rule)
{
foreach ($rules as $rule) {
if ($rule['attrib'] != '*')
{
if ($rule['attrib'] !== '*') {
if ($type == 'device' || $entity_type == 'device')
{
if ($type === 'device' || $entity_type === 'device') {
$def = $GLOBALS['config']['entities'][$type]['attribs'][$rule['attrib']];
} else {
$def = $GLOBALS['config']['entities'][$entity_type]['attribs'][$rule['attrib']];
}
$e = array();
$e['id'] = ($type == 'device' ? 'device.' : 'entity.') . $rule['attrib'];
$e = [];
$e['id'] = ($type === 'device' ? 'device.' : 'entity.') . $rule['attrib'];
$e['field'] = $e['id'];
$e['type'] = $def['type'];
$e['value'] = $rule['value'];
@ -3377,17 +3381,13 @@ function migrate_assoc_rules($entry)
}
if (isset($def['values']) &&
in_array($e['operator'], array("equals", "notequals", "match", "notmatch", "regexp", "notregexp")))
{
in_array($e['operator'], [ "equals", "notequals", "match", "notmatch", "regexp", "notregexp" ])) {
$e['id'] .= ".free";
}
if (in_array($e['operator'], array('in', 'notin')))
{
if (in_array($e['operator'], [ 'in', 'notin' ])) {
$e['input'] = 'select';
}
else if ($def['type'] == 'integer')
{
} elseif ($def['type'] === 'integer') {
$e['input'] = 'number';
} else {
$e['input'] = 'text';
@ -3404,14 +3404,11 @@ function migrate_assoc_rules($entry)
}
// Collapse group if there is only one entry.
if (count($ruleset['rules']) == 1)
{
$rules_count = count($ruleset['rules']);
if ($rules_count === 1) {
$ruleset['rules'] = $ruleset['rules'][0]['rules'];
$ruleset['condition'] = 'AND';
}
if (count($ruleset['rules']) < 1)
{
} elseif ($rules_count < 1) {
$ruleset['rules'][] = array('id' => 'device.hostname', 'field' => 'device.hostname', 'type' => 'string', 'value' => '*', 'operator' => 'match', 'input' => 'text');
}
@ -3419,52 +3416,47 @@ function migrate_assoc_rules($entry)
}
function render_qb_rules($entity_type, $rules)
{
function render_qb_rules($entity_type, $rules) {
$parts = array();
$parts = [];
$entity_type_data = entity_type_translate_array($entity_type);
foreach ($rules['rules'] as $rule)
{
if (is_array($rule['rules']))
{
foreach ($rules['rules'] as $rule) {
if (is_array($rule['rules'])) {
$parts[] = render_qb_rules($entity_type, $rule);
} else {
list($table, $field) = explode('.', $rule['field']);
if ($table == "device")
{
if ($table === "device") {
} elseif ($table == "entity") {
} elseif ($table === "entity") {
$table = $entity_type;
} elseif ($table == "parent") {
} elseif ($table === "parent") {
$table = $entity_type_data['parent_type'];
}
// Boolean stored as bool object, can not be displayed
if ($rule['type'] == 'boolean')
{
$rule['value'] = intval($rule['value']);
if ($rule['type'] === 'boolean') {
$rule['value'] = (int)$rule['value'];
}
$parts[] = "<code style='margin: 1px'>$table.$field " . $rule['operator'] . " " .
(is_array($rule['value']) ? implode('|', $rule['value']) : $rule['value']) . "</code>";
$values = is_array($rule['value']) ? implode('|', $rule['value']) : $rule['value'];
$parts[] = "<code style='margin: 1px'>" . escape_html("$table.$field " . $rule['operator']) . " " .
escape_html($values) . "</code>";
}
}
$part = implode('' . ($rules['condition'] == "AND" ? ' <span class="label label-primary">AND</span> ' : ' <span class="label label-info">OR</span> ') . '',$parts);
$part = implode(($rules['condition'] === "AND" ? ' <span class="label label-primary">AND</span> ' : ' <span class="label label-info">OR</span> '), $parts);
if(count($parts) > 1)
{
if (count($parts) > 1) {
$part = '<b style="font-size: 1.2em">(</b>'.$part.'<b>)</b>';
}

View File

@ -19,6 +19,7 @@
if (PHP_VERSION_ID < 50600) {
// Disable phpFastCache for PHP less than 5.6, since it unsupported
$config['cache']['enable'] = FALSE;
$config['cache']['enable_cli'] = FALSE;
}
/**
@ -445,22 +446,12 @@ function get_cache_stats() {
define('OBS_CACHE_DEBUG', isset($_SERVER['PATH_INFO']) && str_contains($_SERVER['PATH_INFO'], 'cache_info'));
// Do not load phpFastCache classes if caching mechanism not enabled or not supported
if (!$config['cache']['enable']) {
if (OBS_CACHE_DEBUG || (defined('OBS_DEBUG') && OBS_DEBUG)) {
if (PHP_VERSION_ID < 50600) {
print_error('<span class="text-danger">CACHE DISABLED.</span> You use too old php version, see <a href="' . OBSERVIUM_DOCS_URL . '/software_requirements/">minimum software requirements</a>.');
} else {
print_error('<span class="text-danger">CACHE DISABLED.</span> Disabled in config.');
}
}
return;
}
if (is_cli()) {
if (!$config['cache']['enable_cli'] || OBS_PROCESS_NAME === 'config_to_json') {
if (!$config['cache']['enable_cli'] ||
!in_array(OBS_PROCESS_NAME, [ 'poller', 'discovery', 'syslog' ], TRUE)) {
// FIXME. Do not enable caching in cli when process run as root?
if (OBS_CACHE_DEBUG || (defined('OBS_DEBUG') && OBS_DEBUG)) {
print_cli('%RCACHE DISABLED.%n Disabled in config.');
print_cli('%RCACHE DISABLED.%n Disabled in config or not allowed for '.OBS_PROCESS_NAME.' process.');
}
return;
}
@ -468,6 +459,18 @@ if (is_cli()) {
// Syslog have different dir permissions
$cache_key = OBS_PROCESS_NAME === 'syslog' ? 'syslog' : 'cli';
} else {
// Do not load phpFastCache classes if caching mechanism not enabled or not supported
if (!$config['cache']['enable']) {
if (OBS_CACHE_DEBUG || (defined('OBS_DEBUG') && OBS_DEBUG)) {
if (PHP_VERSION_ID < 50600) {
print_error('<span class="text-danger">CACHE DISABLED.</span> You use too old php version, see <a href="' . OBSERVIUM_DOCS_URL . '/software_requirements/">minimum software requirements</a>.');
} else {
print_error('<span class="text-danger">CACHE DISABLED.</span> Disabled in config.');
}
}
return;
}
$cache_key = 'wui'; // do not use $_SERVER['hostname'] as key
}
@ -586,10 +589,14 @@ switch($cache_driver) {
$GLOBALS[OBS_CACHE_LINK] = CacheManager::getInstance($cache_driver);
} catch (Exception $e) {
print_debug('Cache driver '.ucfirst($cache_driver).' not functional. Caching disabled!');
print_debug_vars($cache_config);
//logfile('debug.log', 'Cache driver '.ucfirst($cache_driver).' not functional. Caching disabled in '.OBS_PROCESS_NAME);
//CacheManager::setDefaultConfig(new \Phpfastcache\Drivers\Devfalse\Config());
//$GLOBALS[OBS_CACHE_LINK] = CacheManager::getInstance('Devfalse'); // disable caching
CacheManager::setDefaultConfig(new \Phpfastcache\Drivers\Devnull\Config());
if (PHP_VERSION_ID >= 70300) {
// Derp compatibility with old
CacheManager::setDefaultConfig(new \Phpfastcache\Drivers\Devnull\Config());
}
$GLOBALS[OBS_CACHE_LINK] = CacheManager::getInstance('Devnull'); // disable caching
}
break;

View File

@ -46,7 +46,12 @@ function observium_autoload($class_name) {
case 'Flight':
$class_file = array_pop($class_array) . '.php';
$class_file = 'flight/' . $class_file;
if (PHP_VERSION_ID >= 70400) {
$class_file = 'flight2/' . $class_file;
} else {
// Old compat version
$class_file = 'flight/' . $class_file;
}
break;
case 'Ramsey':
@ -407,13 +412,25 @@ function get_localhost() {
global $cache;
if (!isset($cache['localhost'])) {
$cache['localhost'] = php_uname('n');
if (!str_contains($cache['localhost'], '.')) {
// try use hostname -f for get FQDN hostname
$localhost_t = external_exec('/bin/hostname -f');
if (str_contains($localhost_t, '.')) {
$cache['localhost'] = $localhost_t;
// FastCache for less system exec
$cache_item = get_cache_item('own_hostname');
if (!ishit_cache_item($cache_item)) {
$cache['localhost'] = php_uname('n');
if (!str_contains($cache['localhost'], '.')) {
// try use hostname -f for get FQDN hostname
$localhost_t = external_exec('/bin/hostname -f');
if (str_contains($localhost_t, '.')) {
$cache['localhost'] = $localhost_t;
}
}
// Store in fast caching (this value very rare changed (mostly - never)
set_cache_item($cache_item, $cache['localhost'], [ 'ttl' => 3600 ]); // set valid for 1 hour
} else {
// Cached item
$cache['localhost'] = get_cache_data($cache_item);
}
}
@ -673,6 +690,11 @@ function list_to_range($str, $separator = ',', $sort = TRUE) {
function logfile($filename, $string = NULL) {
global $config, $argv;
if (defined('__PHPUNIT_PHAR__')) {
print_debug("Skip logging to '$filename' when run phpunit tests.");
return FALSE;
}
// Use default logfile if none specified
if (safe_empty($string)) {
$string = $filename;
@ -893,7 +915,7 @@ function get_versions($program = NULL) {
}
$versions['rrdtool_old'] = version_compare($versions['rrdtool_version'], OBS_MIN_RRD_VERSION, '<');
if (strlen($GLOBALS['config']['rrdcached'])) {
if (!safe_empty($GLOBALS['config']['rrdcached'])) {
if (OBS_RRD_NOLOCAL) {
// Remote rrdcached daemon (unknown version)
$rrdtool_version .= ' (rrdcached remote: ' . $GLOBALS['config']['rrdcached'] . ')';
@ -948,7 +970,7 @@ function get_versions($program = NULL) {
case 'http':
// Apache (or any http used?)
if (is_cli()) {
foreach (array('apache2', 'httpd') as $http_cmd) {
foreach ([ 'apache2', 'httpd' ] as $http_cmd) {
if (is_executable('/usr/sbin/'.$http_cmd)) {
$http_cmd = '/usr/sbin/'.$http_cmd;
} else {
@ -1041,8 +1063,9 @@ function print_versions() {
print_cli_data("PHP", ($php_memory_limit >= 0 && $php_memory_limit < 268435456 ? '%r' : '') . $php_memory_limit_text, 3);
echo(PHP_EOL);
print_cli_heading("$mysql_name mode", 3);
print_cli_data($mysql_name, $mysql_mode, 3);
print_cli_heading("DB info", 3);
print_cli_data("DB schema", get_db_version(), 3);
print_cli_data("$mysql_name mode", $mysql_mode, 3);
echo(PHP_EOL);
print_cli_heading("Charset info", 3);
@ -1118,7 +1141,7 @@ function print_versions() {
$rrdtool_version = escape_html($rrdtool_version);
}
echo generate_box_open(array('title' => 'Version Information'));
echo generate_box_open([ 'title' => 'Version Information' ]);
echo('
<table class="table table-striped table-condensed-more">
<tbody>
@ -1346,15 +1369,12 @@ function timeticks_to_sec($timetick, $float = FALSE)
*
* @return integer Unixtime
*/
function datetime_to_unixtime($datetime, $use_gmt = FALSE)
{
function datetime_to_unixtime($datetime, $use_gmt = FALSE) {
$timezone = get_timezone();
$datetime = trim($datetime);
if (preg_match('/(?<year>\d+)-(?<mon>\d+)-(?<day>\d+)(?:,(?<hour>\d+):(?<min>\d+):(?<sec>\d+)(?<millisec>\.\d+)?(?:,(?<tzs>[+\-]?)(?<tzh>\d+):(?<tzm>\d+))?)/', $datetime, $matches))
{
if (isset($matches['tzh']))
{
if (preg_match('/(?<year>\d+)-(?<mon>\d+)-(?<day>\d+)(?:,(?<hour>\d+):(?<min>\d+):(?<sec>\d+)(?<millisec>\.\d+)?(?:,(?<tzs>[+\-]?)(?<tzh>\d+):(?<tzm>\d+))?)/', $datetime, $matches)) {
if (isset($matches['tzh'])) {
// Use TZ offset from datetime string
$offset = $matches['tzs'] . ($matches['tzh'] * 3600 + $matches['tzm'] * 60); // Offset from GMT in seconds
} else {
@ -1370,19 +1390,17 @@ function datetime_to_unixtime($datetime, $use_gmt = FALSE)
$time_gmt = $time_local - $timezone['php_offset']; // Current unixtime in GMT
}
if (OBS_DEBUG > 1)
{
if (OBS_DEBUG > 1) {
$debug_msg = 'UNIXTIME from DATETIME "' . ($time_tmp ? $datetime : 'time()') . '": ';
$debug_msg .= 'LOCAL (' . format_unixtime($time_local) . '), GMT (' . format_unixtime($time_gmt) . '), TZ (' . $timezone['php'] . ')';
print_message($debug_msg);
}
if ($use_gmt)
{
if ($use_gmt) {
return ($time_gmt);
} else {
return ($time_local);
}
return ($time_local);
}
/**
@ -1471,7 +1489,7 @@ function format_uptime($uptime, $format = "long") {
/**
* Get current timezones for mysql and php.
* Use this function when need display timedate from mysql
* for fix diffs betwen this timezones
* for fix diffs between this timezones
*
* Example:
* Array
@ -1488,30 +1506,29 @@ function format_uptime($uptime, $format = "long") {
*
* @return array Timezones info
*/
function get_timezone($refresh = FALSE)
{
function get_timezone($refresh = FALSE) {
global $cache;
if ($refresh || !isset($cache['timezone']))
{
$timezone = array();
$timezone['system'] = external_exec('date "+%:z"'); // return '+03:00'
if (!OBS_DB_SKIP)
{
if ($refresh || !isset($cache['timezone'])) {
$timezone = [];
if ($refresh) {
// Call to external exec only when refresh (basically it's not required)
$timezone['system'] = external_exec('date "+%:z"'); // return '+03:00'
}
if (!OBS_DB_SKIP) {
$timezone['mysql'] = dbFetchCell('SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP);'); // return '03:00:00'
if ($timezone['mysql'][0] != '-')
{
if ($timezone['mysql'][0] !== '-') {
$timezone['mysql'] = '+'.$timezone['mysql'];
}
$timezone['mysql'] = preg_replace('/:00$/', '', $timezone['mysql']); // convert to '+03:00'
}
$timezone['php'] = date('P'); // return '+03:00'
$timezone['php_abbr'] = date('T'); // return 'MSK'
$timezone['php_name'] = date('e'); // return 'Europe/Moscow'
$timezone['php_daylight'] = date('I'); // return '0'
list($timezone['php'], $timezone['php_abbr'], $timezone['php_name'], $timezone['php_daylight']) = explode('|', date('P|T|e|I'));
//$timezone['php'] = date('P'); // return '+03:00'
//$timezone['php_abbr'] = date('T'); // return 'MSK'
//$timezone['php_name'] = date('e'); // return 'Europe/Moscow'
//$timezone['php_daylight'] = date('I'); // return '0'
foreach (array('php', 'mysql') as $entry)
{
foreach ([ 'php', 'mysql' ] as $entry) {
if (!isset($timezone[$entry])) { continue; } // skip mysql if OBS_DB_SKIP
$sign = $timezone[$entry][0];
@ -1519,13 +1536,12 @@ function get_timezone($refresh = FALSE)
$timezone[$entry . '_offset'] = $sign . (abs($hours) * 3600 + $minutes * 60); // Offset from GMT in seconds
}
if (OBS_DB_SKIP)
{
if (OBS_DB_SKIP) {
// If mysql skipped, just return system/php timezones without caching
return $timezone;
}
// Get get the difference in sec between mysql and php timezones
// Get the difference in sec between mysql and php timezones
$timezone['diff'] = (int)$timezone['mysql_offset'] - (int)$timezone['php_offset'];
$cache['timezone'] = $timezone;
}
@ -1533,16 +1549,6 @@ function get_timezone($refresh = FALSE)
return $cache['timezone'];
}
// DOCME needs phpdoc block
function humanspeed($speed)
{
if ($speed == '')
{
return '-';
} else {
return formatRates($speed);
}
}
/**
* Convert common MAC strings to fixed 12 char string
@ -1733,7 +1739,7 @@ function pipe_read($command, &$pipes, $fullread = TRUE) {
$stdout = '';
while (strlen($line) < 1 && $iter < 1000) {
// wait for 10 milliseconds to loosen loop (max 1s)
usleep(10000);
usleep(1000);
$line = fgets($pipes[1], 1024);
$stdout .= $line;
$iter++;
@ -1944,24 +1950,20 @@ function external_exec($command, $timeout = NULL) {
* @param boolean $stats If true, additionally show cpu/memory stats
* @return array|false Array with information about process, If process not found, return FALSE
*/
function get_pid_info($pid, $stats = FALSE)
{
function get_pid_info($pid, $stats = FALSE) {
$pid = (int)$pid;
if ($pid < 1)
{
if ($pid < 1) {
print_debug("Incorrect PID passed");
//trigger_error("PID ".$pid." doesn't exists", E_USER_WARNING);
return FALSE;
}
if (!$stats && stripos(PHP_OS, 'Linux') === 0)
{
if (!$stats && stripos(PHP_OS, 'Linux') === 0) {
// Do not use call to ps on Linux and extended stat not required
// FIXME. Need something same on BSD and other Unix platforms
if ($pid_stat = lstat("/proc/$pid"))
{
$pid_info = array('PID' => "$pid");
if ($pid_stat = lstat("/proc/$pid")) {
$pid_info = [ 'PID' => (string)$pid ];
$ps_stat = explode(" ", file_get_contents("/proc/$pid/stat"));
//echo PHP_EOL; print_vars($ps_stat); echo PHP_EOL;
//echo PHP_EOL; print_vars($pid_stat); echo PHP_EOL;
@ -1979,15 +1981,14 @@ function get_pid_info($pid, $stats = FALSE)
} else {
// Use ps call, have troubles on high load systems!
if ($stats)
{
if ($stats) {
// Add CPU/Mem stats
$options = 'pid,ppid,uid,gid,pcpu,pmem,vsz,rss,tty,stat,time,lstart,args';
} else {
$options = 'pid,ppid,uid,gid,tty,stat,time,lstart,args';
}
$timezone = get_timezone(); // Get system timezone info, for correct started time conversion
//$timezone = get_timezone(); // Get system timezone info, for correct started time conversion
$ps = external_exec('/bin/ps -ww -o '.$options.' -p '.$pid, 1); // Set timeout 1sec for exec
$ps = explode("\n", rtrim($ps));
@ -2015,7 +2016,8 @@ function get_pid_info($pid, $stats = FALSE)
$started = preg_split("/\s+/", array_pop($entries), 6, PREG_SPLIT_NO_EMPTY);
$command = array_pop($started);
$started[] = str_replace(':', '', $timezone['system']); // Add system TZ to started time
//$started[] = str_replace(':', '', $timezone['system']); // Add system TZ to started time
$started[] = external_exec('date "+%z"'); // Add system TZ to started time
$started_rfc = array_shift($started) . ','; // Sun
// Reimplode and convert to RFC2822 started date 'Sun, 20 Mar 2016 18:01:53 +0300'
$started_rfc .= ' ' . $started[1]; // 20
@ -2030,9 +2032,8 @@ function get_pid_info($pid, $stats = FALSE)
//print_vars($entries);
//print_vars($started);
$pid_info = array();
foreach ($keys as $i => $key)
{
$pid_info = [];
foreach ($keys as $i => $key) {
$pid_info[$key] = $entries[$i];
}
$pid_info['STARTED_UNIX'] = strtotime($pid_info['STARTED']);
@ -2478,7 +2479,7 @@ function str_compress($string, $encode = 'base64') {
if (OBS_DEBUG > 1) {
$compressed = $encode === 'hex' ? bin2hex($compressed) : safe_base64_encode($compressed);
print_cli("String '$string' [".strlen($string)."] compressed to '".$compressed."' [".strlen($compressed)."].");
print_cli("DEBUG: String '$string' [".strlen($string)."] compressed to '".$compressed."' [".strlen($compressed)."].");
return $compressed;
}
@ -2511,7 +2512,7 @@ function str_decompress($compressed) {
}
if (OBS_DEBUG > 1) {
print_cli("String '$compressed' [".strlen($compressed)."] decompressed to '".$string."' [".strlen($string)."].");
print_cli("DEBUG: String '$compressed' [".strlen($compressed)."] decompressed to '".$string."' [".strlen($string)."].");
}
return $string;
}
@ -2525,6 +2526,9 @@ function is_cli() {
}
if (!defined('OBS_CLI')) {
define('OBS_CLI', PHP_SAPI === 'cli' && empty($_SERVER['REMOTE_ADDR']));
if (OBS_DEBUG > 1) {
print_cli("DEBUG: is_cli() == " . (OBS_CLI ? 'TRUE' : 'FALSE') . ", PHP_SAPI: '" . PHP_SAPI . "', REMOTE_ADDR: '" . $_SERVER['REMOTE_ADDR'] . "'");
}
}
return OBS_CLI;
@ -2947,7 +2951,7 @@ function is_module_enabled($device, $module, $process = NULL, $settings = TRUE)
} elseif ($module === 'wifi' && !in_array($device['type'], [ 'network', 'firewall', 'wireless' ], TRUE)) {
// WiFi by default allowed only for network/wireless/firewall types
$ok = FALSE;
$debug_reason = "disabled for device type '${device['type']}'.";
$debug_reason = "disabled for device type '{$device['type']}'.";
} /* else {
$model = get_model_array($device);
if (isset($model[$module_name])) {
@ -3093,69 +3097,20 @@ function check_extension_exists($extension, $text = FALSE, $fatal = FALSE)
return $exist;
}
// TESTME needs unit testing
/**
* Sign function
*
* This function extracts the sign of the number.
* Returns -1 (negative), 0 (zero), 1 (positive)
*
* @param integer $int
* @param integer|float $int
* @return integer
*/
function sgn($int)
{
if ($int < 0)
{
function sgn($int) {
if ($int < 0) {
return -1;
} elseif ($int == 0) {
return 0;
} else {
return 1;
}
}
// DOCME needs phpdoc block
// TESTME needs unit testing
// MOVEME to includes/functions.inc.php
function get_bill_by_id($bill_id)
{
$bill = dbFetchRow("SELECT * FROM `bills` WHERE `bill_id` = ?", array($bill_id));
if (is_array($bill))
{
return $bill;
} else {
return FALSE;
}
}
// DOCME needs phpdoc block
// TESTME needs unit testing
// MOVEME to includes/functions.inc.php
function get_application_by_id($application_id)
{
if (is_numeric($application_id))
{
$application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", array($application_id));
}
if (is_array($application))
{
return $application;
} else {
return FALSE;
}
}
// DOCME needs phpdoc block
// TESTME needs unit testing
// MOVEME to includes/functions.inc.php
function accesspoint_by_id($ap_id, $refresh = '0')
{
$ap = dbFetchRow("SELECT * FROM `accesspoints` WHERE `accesspoint_id` = ?", array($ap_id));
return $ap;
return $int > 0 ? 1 : 0;
}
// DOCME needs phpdoc block
@ -3169,13 +3124,15 @@ function truncate($substring, $max = 50, $rep = '...') {
} else {
$rep_len = strlen($rep);
}
if (strlen($substring) < 1) {
$string = $rep;
} else {
$string = $substring;
if (safe_empty($substring)) {
//$string = $rep;
return $rep;
}
$leave = $max - $rep_len;
$string = (string)$substring;
if (strlen($string) > $max) {
$leave = $max - $rep_len;
return substr_replace($string, $rep, $leave);
}
return $string;
@ -3256,13 +3213,6 @@ function zeropad($num, $length = 2)
return str_pad($num, $length, '0', STR_PAD_LEFT);
}
// OBSOLETE, remove when all function calls will be deleted
function get_dev_attrib($device, $attrib_type)
{
// Call to new function
return get_entity_attrib('device', $device, $attrib_type);
}
/**
* Return model array from definitions, based on device sysObjectID
*
@ -3578,11 +3528,15 @@ function is_valid_param($string, $type = '') {
switch (strtolower($type)) {
case 'asset_tag':
case 'hardware':
case 'vendor':
case 'serial':
case 'version':
case 'revision':
$valid = ctype_print($string) &&
!(str_istarts($string, [ 'Not Avail', 'Not Specified', 'To be filled by O.E.M.' ]) ||
str_contains_array($string, [ 'denied' ]) || preg_match($poor_default_pattern, $string) ||
in_array($string, [ '<EMPTY>', 'empty', 'n/a', 'N/A', '1234567890', '0123456789',
str_contains_array($string, [ 'denied', 'No Such' ]) || preg_match($poor_default_pattern, $string) ||
in_array($string, [ '<EMPTY>', 'empty', 'n/a', 'N/A', 'na', 'NA', '1234567890', '0123456789',
'No Asset Tag', 'Tag 12345', 'sim', 'Unknown' ], TRUE));
break;
@ -3632,7 +3586,8 @@ function is_valid_param($string, $type = '') {
// posix 32 chars
// windows/ldap 20 chars
// pre-windows2000 256 chars
$valid = strlen($string) <= 256 && preg_match('/^\w[\w\-\\\\]+\$?$/u', $string); // allow utf8 usernames
//$valid = strlen($string) <= 256 && preg_match('/^\w[\w\-\\\\]+\$?$/u', $string); // allow utf8 usernames
$valid = preg_match('/^[\w!][\w@!#^~+\$\-\.\ \\\\]{0,254}[\w\$]$/u', $string); // allow utf8 usernames
break;
case 'password':
@ -3640,7 +3595,8 @@ function is_valid_param($string, $type = '') {
break;
case 'snmp_community':
$valid = preg_match('/^[\w#@=:\(\)\ \-\.\/]{1,32}$/', $string);
// allow all common latin and special chars
$valid = preg_match('/^[\w\ %!@#\$%\^&\*\(\)_\-\+~`\[\]\{\}\|\\\\<>,\.\/\?;:]{1,32}$/', $string);
break;
case 'snmp_timeout':
@ -3670,7 +3626,7 @@ function is_valid_param($string, $type = '') {
print_debug("Detected invalid value '$string' for param '$type'.");
}
return $valid;
return (bool) $valid;
}
/**
@ -3867,17 +3823,6 @@ function gethostbyaddr6($ip) {
return $ptr;
}
// DOCME needs phpdoc block
// TESTME needs unit testing
// CLEANME DEPRECATED
function add_service($device, $service, $descr)
{
$insert = array('device_id' => $device['device_id'], 'service_ip' => $device['hostname'], 'service_type' => $service,
'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $descr, 'service_param' => "", 'service_ignore' => "0");
echo dbInsert($insert, 'services');
}
/**
* Request an http(s) url.
* Note. If first runtime request exit with timeout,
@ -3963,11 +3908,10 @@ function get_http_request($request, $context = [], $rate_limit = FALSE) {
$response = '';
// Add common http context
$opts = array('http' => generate_http_context_defaults($context));
$opts = [ 'http' => generate_http_context_defaults($context) ];
// Force IPv4 or IPv6
if (isset($config['http_ip_version']))
{
if (isset($config['http_ip_version'])) {
$bindto = str_contains($config['http_ip_version'], '6') ? '[::]:0' : '0:0';
$opts['socket'] = [ 'bindto' => $bindto ];
//$opts['socket'] = [ 'bindto' => '0:0' ]; // IPv4
@ -3996,13 +3940,12 @@ function get_http_request($request, $context = [], $rate_limit = FALSE) {
if (isset($opts['http']['timeout'])) {
$curl_cmd .= ' --connect-timeout '.$opts['http']['timeout'];
}
if (isset($opts['http']['method']))
{
if (isset($opts['http']['method'])) {
$curl_cmd .= ' -X '.$opts['http']['method'];
}
if (isset($opts['http']['header'])) {
foreach (explode("\r\n", $opts['http']['header']) as $curl_header) {
if (!strlen($curl_header)) { continue; }
if (safe_empty($curl_header)) { continue; }
$curl_cmd .= ' -H \'' . $curl_header . '\'';
}
}
@ -4059,7 +4002,7 @@ function get_http_request($request, $context = [], $rate_limit = FALSE) {
$GLOBALS['request_status'] = FALSE;
} elseif ($response === FALSE) {
// An error in get response
$GLOBALS['response_headers'] = array('code' => 408, 'descr' => 'Request Timeout');
$GLOBALS['response_headers'] = [ 'code' => 408, 'descr' => 'Request Timeout' ];
$GLOBALS['request_status'] = FALSE;
} else {
// Valid statuses: 2xx Success, 3xx Redirection or head code not set (ie response not correctly parsed)
@ -4073,14 +4016,14 @@ function get_http_request($request, $context = [], $rate_limit = FALSE) {
if ($runtime < 1 &&
isset($config['http_proxy']) && $config['http_proxy'] &&
!(isset($config['proxy_user']) || isset($config['proxy_password']))) {
$GLOBALS['response_headers'] = array('code' => 407, 'descr' => 'Proxy Authentication Required');
$GLOBALS['response_headers'] = [ 'code' => 407, 'descr' => 'Proxy Authentication Required' ];
} else {
$GLOBALS['response_headers'] = array('code' => 408, 'descr' => 'Request Timeout');
$GLOBALS['response_headers'] = [ 'code' => 408, 'descr' => 'Request Timeout' ];
}
$GLOBALS['request_status'] = FALSE;
// Validate host from request and check if it timeout request
if (gethostbyname6(parse_url($request, PHP_URL_HOST))) {
if (OBS_PROCESS_NAME === 'poller' && gethostbyname6(parse_url($request, PHP_URL_HOST))) {
// Timeout error, only if not received response headers
define('OBS_HTTP_REQUEST', FALSE);
print_debug(__FUNCTION__.'() exit with timeout. Access to outside localnet is blocked by firewall or network problems. Check proxy settings.');

File diff suppressed because it is too large Load Diff

View File

@ -781,6 +781,35 @@ function dbPlaceHolders($values)
return $data;
}
/**
* This function generates WHERE condition string from array with values
* NOTE, value should be exploded by comma before use generate_query_values(), for example in get_vars().
*
* NOTE, WHERE condition always preceded with leading AND!
*
* @param mixed $value Values
* @param string $column Table column name
* @param string $condition Compare condition, known: =, !=, NOT, NULL, NOT NULL, LIKE (and variants %LIKE%, %LIKE, LIKE%)
* @param array $options ifnull - add IFNULL(column, '')
*
* @return string Generated query
*/
function generate_query_values_and($value, $column, $condition = NULL, $options = []) {
$options[] = 'leading_and';
return generate_query_values_ng($value, $column, $condition, $options);
}
// DEPRECATED
function generate_query_values($value, $column, $condition = NULL, $options = []) {
if (is_bool($options) && !$options) {
$options = [];
} elseif (!in_array('no_leading_and', (array)$options)) {
// Compat with old
$options[] = 'leading_and';
}
return generate_query_values_ng($value, $column, $condition, $options);
}
/**
* This function generates WHERE condition string from array with values
* NOTE, value should be exploded by comma before use generate_query_values(), for example in get_vars()
@ -788,35 +817,30 @@ function dbPlaceHolders($values)
* @param mixed $value Values
* @param string $column Table column name
* @param string $condition Compare condition, known: =, !=, NOT, NULL, NOT NULL, LIKE (and variants %LIKE%, %LIKE, LIKE%)
* @param bool|int $flags OBS_DB_NO_LEADING_AND - Do not add leading AND to result query,
* OBS_DB_IFNULL - add IFNULL(column, '')
* @param array $options leading_and - Add leading AND to result query,
* ifnull - add IFNULL(column, '')
* @return string Generated query
*/
function generate_query_values($value, $column, $condition = NULL, $flags = 0) {
function generate_query_values_ng($value, $column, $condition = NULL, $options = []) {
//if (!is_array($value)) { $value = explode(',', $value); }
if (!is_array($value)) { $value = array((string)$value); }
$column = '`' . str_replace(array('`', '.'), array('', '`.`'), $column) . '`'; // I.column -> `I`.`column`
$column = '`' . str_replace([ '`', '.' ], [ '', '`.`' ], $column) . '`'; // I.column -> `I`.`column`
$condition = ($condition === TRUE ? 'LIKE' : strtoupper(trim($condition)));
if (str_contains_array($condition, [ 'NOT', '!=' ])) {
$negative = TRUE;
$condition = str_replace(array('NOT', '!=', ' '), '', $condition);
$condition = str_replace([ 'NOT', '!=', ' ' ], '', $condition);
} else {
$negative = FALSE;
}
// Flags
if (is_bool($flags)) {
// Compat with old param style
$leading_and = $flags;
$ifnull = FALSE;
} else {
$leading_and = !is_flag_set(OBS_DB_NO_LEADING_AND, $flags);
$ifnull = is_flag_set(OBS_DB_IFNULL, $flags);
}
// Options
//$leading_and = !in_array('no_leading_and', (array)$options);
$leading_and = in_array('leading_and', (array)$options, TRUE);
$ifnull = in_array('ifnull', (array)$options, TRUE);
$search = array('%', '_');
$replace = array('\%', '\_');
$values = array();
$search = [ '%', '_' ];
$replace = [ '\%', '\_' ];
$values = [];
switch ($condition) {
// Use LIKE condition
case 'LIKE':
@ -828,41 +852,74 @@ function generate_query_values($value, $column, $condition = NULL, $flags = 0) {
case '%LIKE%':
case '%LIKE':
case 'LIKE%':
if ($negative) { $implode = ' AND '; $like = ' NOT LIKE '; }
else { $implode = ' OR '; $like = ' LIKE '; }
if ($negative) {
$implode = ' AND ';
$cond = ' NOT LIKE ';
} else {
$implode = ' OR ';
$cond = ' LIKE ';
}
foreach ($value as $v) {
if ($v === '*') {
$values = array("ISNULL($column, 1)" . $like . "'%'");
$values = [ "ISNULL($column, 1)" . $cond . "'%'" ];
break;
} elseif ($v === '') {
$values[] = "COALESCE($column, '')" . $like . "''";
}
if ($v === '') {
$values[] = "COALESCE($column, '')" . $cond . "''";
} else {
$v = dbEscape($v); // Escape BEFORE replace!
$v = str_replace($search, $replace, $v);
$v = str_replace('LIKE', $v, $condition);
$values[] = $column . $like . "'" . $v . "'";
$values[] = $column . $cond . "'" . $v . "'";
}
}
$values = array_unique($values); // Removes duplicate values
if (count($values)) {
$where = ' AND (' . implode($implode, $values) . ')';
$where = '(' . implode($implode, $values) . ')';
} else {
// Empty values
$where = ' AND ';
$where .= $negative ? '1' : '0';
$where = $negative ? '1' : '0';
}
//$where = ($leading_and ? ' AND ' : ' ') . $where;
break;
// Use REGEXP condition
case 'REGEX':
case 'REGEXP':
if ($negative) {
$implode = ' AND ';
$cond = ' NOT REGEXP ';
} else {
$implode = ' OR ';
$cond = ' REGEXP ';
}
foreach ($value as $v) {
$values[] = $column . $cond . "'" . dbEscape($v) . "'"; // FIXME. not sure about escape, but need fixate!
}
$values = array_unique($values); // Removes duplicate values
if (count($values)) {
$where = '(' . implode($implode, $values) . ')';
} else {
// Empty values
$where = $negative ? '1' : '0';
}
//$where = ($leading_and ? ' AND ' : ' ') . $where;
break;
// Use NULL condition
case 'NULL':
$value = array_shift($value);
$value = ($negative) ? !$value : (bool)$value; // When required negative null condition (NOT NULL), reverse $value sign
//r($value);
if ($value) {
$where = ' AND ' . $column . ' IS NULL';
$where = $column . ' IS NULL';
} else {
$where = ' AND ' . $column . ' IS NOT NULL';
$where = $column . ' IS NOT NULL';
}
//$where = ($leading_and ? ' AND ' : ' ') . $where;
break;
// Use IN condition
default:
$where = '';
@ -896,13 +953,17 @@ function generate_query_values($value, $column, $condition = NULL, $flags = 0) {
// }
// $where = " AND ($where)";
// } else {
$where = " AND " . $where;
//$where = " AND " . $where;
//$where = ($leading_and ? ' AND ' : ' ') . $where;
// }
break;
}
if (!$leading_and) { $where = preg_replace('/^(\ )+AND/', '', $where); }
return $where;
//if (!$leading_and) { $where = preg_replace('/^(\ )+AND/', '', $where); }
if ($leading_and) {
// Append leading AND
return ' AND ' . $where;
}
return ' ' . $where;
}
/**

View File

@ -63,7 +63,7 @@ $config['db_ssl_verify'] = TRUE; // disables SSL certificate validatio
#$config['db_ssl_ca_path'] = ''; // path to ca files
#$config['db_ssl_ciphers'] = ''; // allowed ciphers to use for ssl connection
$config['db']['debug'] = TRUE; // If TRUE store errors in DB queries into logs/db.log
$config['db']['debug'] = FALSE; // If TRUE store errors in DB queries into logs/db.log
#$config['db_host'] = 'localhost'; // DB hostname (default: localhost)
#$config['db_user'] = 'USERNAME';
@ -225,6 +225,7 @@ $config['graphs']['ports_scale_force'] = 1; // Force scale also if re
$config['graphs']['ports_scale_default'] = "auto"; // Possible values: auto, speed, scales from $config['graphs']['ports_scale_list']
$config['graphs']['ports_scale_list'] = [ '100Gbit', '50Gbit', '40Gbit', '25Gbit', '10Gbit', '5Gbit', '2.5Gbit', '1Gbit', '100Mbit', '10Mbit' ];
$config['graphs']['stacked_processors'] = TRUE;
$config['graphs']['dynamic_labels'] = TRUE; // Draw different color markers for labels (instead square marker).
$config['graphs']['always_draw_max'] = FALSE; // Allow suppression of MAX region for aesthetic reasons on graphs < 1 week long
$config['int_customers'] = 1; // Enable Customer Port Parsing
@ -233,7 +234,7 @@ $config['int_transit'] = 1; // Enable Transit Types
$config['int_peering'] = 1; // Enable Peering Types
$config['int_core'] = 1; // Enable Core Port Types
$config['int_l2tp'] = 0; // Enable L2TP Port Types
$config['int_groups'] = array(); // Custom Interface Types
$config['int_groups'] = []; // Custom Interface Types
$config['show_locations'] = 1; // Enable Locations on menu
$config['ports_page_default'] = "details"; // eg "details" or "basic"
@ -253,7 +254,7 @@ $config['snmp']['community'][0] = "public"; // Communities to try during adding
// SNMPv3 default settings
// The array can be expanded to give another set of parameters
$config['snmp']['v3'] = array();
$config['snmp']['v3'] = [];
// $config['snmp']['v3'][0]['authlevel'] = "noAuthNoPriv"; // noAuthNoPriv | authNoPriv | authPriv
// $config['snmp']['v3'][0]['authname'] = "observium"; // User Name (required even for noAuthNoPriv)
// $config['snmp']['v3'][0]['authpass'] = ""; // Auth Passphrase
@ -261,13 +262,17 @@ $config['snmp']['v3'] = array();
// $config['snmp']['v3'][0]['cryptopass'] = ""; // Privacy (Encryption) Passphrase
// $config['snmp']['v3'][0]['cryptoalgo'] = "AES"; // DES | AES | AES-192 | AES-192-C | AES-256 | AES-256-C
// SNMP virtual contexts ignore
$config['snmp']['virtual_ignore'][] = '/^vpls_\S+$/'; // IOS XR incorrect snmp contexts, ie: cContextMappingVrfName."vpls_XXXX11192" = XXXX11192
$config['snmp']['virtual_ignore'][] = '/^vlan\-(\d{1,4})$/'; // Common Cisco vlan contexts
// Autodiscovery Settings
$config['autodiscovery']['xdp'] = TRUE; // Autodiscover hosts via discovery protocols (CDP, LLDP, FDP, AMAP and other)
$config['autodiscovery']['ospf'] = TRUE; // Autodiscover hosts via OSPF
$config['autodiscovery']['bgp'] = TRUE; // Autodiscover hosts via iBGP
$config['autodiscovery']['bgp_as_private'] = FALSE; //Autodiscovery hosts via eBGP a Private AS (64512 - 65535)
$config['autodiscovery']['bgp_as_whitelist'] = array(); // Array of ASNs we will try to auto-discover hosts for. (eg for confederations).
$config['autodiscovery']['bgp_as_private'] = FALSE; // Autodiscovery hosts via eBGP a Private AS (64512 - 65535)
$config['autodiscovery']['bgp_as_whitelist'] = []; // Array of ASNs we will try to auto-discover hosts for. (eg for confederations).
$config['autodiscovery']['snmp_scan'] = TRUE; // Autodiscover hosts via SNMP scanning - currently not implemented. (FIXME)
$config['autodiscovery']['libvirt'] = TRUE; // Autodiscover hosts found via libvirt
$config['autodiscovery']['vmware'] = TRUE; // Autodiscover hosts found via vmware
@ -308,7 +313,7 @@ $config['smsbox']['from'] = ''; // Phone number of sende
// Alerting Settings
$config['alerts']['bgp']['whitelist'] = NULL; // Populate as an array() with ASNs to alert on.
$config['alerts']['bgp']['whitelist'] = NULL; // Populate as an array with ASNs to alert on.
$config['alerts']['interval'] = 86400; // How frequently to re-send a notification for a continuing alert condition
// In seconds. Default is 1 day.
@ -320,7 +325,10 @@ $config['alerts']['disable']['all'] = FALSE; // Disable all notificat
#$config['poller-wrapper']['threads'] = 0; // The number of poller threads that should run simultaneously. Default: CPU count x 2
$config['poller-wrapper']['max_running'] = 4; // The number of maximum allowed simultaneously running wrapper processes. This prevents race and too high LA on server
$config['poller-wrapper']['max_la'] = 10; // Maximum allowed server Load Average for run wrapper processes. This prevents race and too high LA on server
$config['poller-wrapper']['poller_timeout'] = 3600; // Hard poller Timeout (seconds) for run poller per each device (note: poller will stopped working as undone by timeout)
$config['poller-wrapper']['discovery_timeout'] = 10800; // Hard discovery Timeout (seconds) for run poller per each device
$config['poller-wrapper']['alerter'] = TRUE; // Execute alerter.php after poller.php
$config['poller-wrapper']['notifications'] = TRUE; // Execute notifications inside alerter.php (when FALSE, need to add separate notifications cron)
$config['poller-wrapper']['stats'] = TRUE; // Enable poller wrapper statistics in RRD (can be seen at page http://your_observium/pollerlog/)
$config['uptime_warning'] = "86400"; // Time in seconds to display a "Device Rebooted" Alert. 0 to disable warnings.
@ -496,14 +504,14 @@ $config['frontpage']['map']['alertmarkersize'] = 32; // Set t
// Device status settings
// Show the status messages you want
$config['frontpage']['device_status']['max']['interval'] = 24; // Maximal interval for which to display devices status (in hours)
$config['frontpage']['device_status']['max']['count'] = 200; // Maximal count for which to display devices status (in items)
$config['frontpage']['device_status']['devices'] = true; // Show the down devices
$config['frontpage']['device_status']['ports'] = true; // Show the down ports
$config['frontpage']['device_status']['neighbours'] = true; // Show the down inter-device neighbours (with CDP/LLDP linked devices)
$config['frontpage']['device_status']['errors'] = true; // Show the ports with interface errors
$config['frontpage']['device_status']['services'] = false; // Show the down services
$config['frontpage']['device_status']['bgp'] = true; // Show the bgp status
$config['frontpage']['device_status']['uptime'] = true; // Show the uptime status
$config['frontpage']['device_status']['max']['count'] = 200; // Maximal count for which to display devices status (in items)
$config['frontpage']['device_status']['devices'] = true; // Show the down devices
$config['frontpage']['device_status']['ports'] = true; // Show the down ports
$config['frontpage']['device_status']['neighbours'] = true; // Show the down inter-device neighbours (with CDP/LLDP linked devices)
$config['frontpage']['device_status']['errors'] = true; // Show the ports with interface errors
$config['frontpage']['device_status']['services'] = false; // Show the down services
$config['frontpage']['device_status']['bgp'] = true; // Show the bgp status
$config['frontpage']['device_status']['uptime'] = true; // Show the uptime status
// Custom traffic graphs
$config['frontpage']['custom_traffic']['ids'] = ""; // COMMA SEPARATED PORT ID FOR EXAMPLE: "1,2,3,4,5"
@ -622,6 +630,7 @@ $config['devices']['ignore_sysname'][] = 'zywall';
$config['sensors']['port']['power_to_dbm'] = FALSE; // Convert power Port DOM sensors to dBm
$config['sensors']['port']['ignore_shutdown'] = TRUE; // Set ignore sensor state instead alert for entities in shutdown state (admin down)
$config['sensors']['limits_events'] = FALSE; // Store sensors limit changes in eventlog
$config['sensors']['web_measured_compact'] = FALSE; // Show sensors for measured entities in compact view style
// Ignores & Allows
// Has to be lowercase
@ -656,6 +665,7 @@ $config['bad_if_regexp'][] = "/^sl[0-9]/i";
$config['bad_if_regexp'][] = "/^<(none|invalid)>$/i"; // calix: <none>, <invalid>
$config['bad_if_regexp'][] = "/^<(invalid|ethportany):[\d-]+>$/i"; // calix: <INVALID:0-0-0-1-0-0-0-4-91-219>, <EthPortAny:0-0-0-0-0-0-0-0-0-0>
$config['bad_if_regexp'][] = "/^(ZTPCONFIG|TopoNode|SYSLOG)=/i"; // iqnos: ZTPCONFIG=ZTPCFG, TopoNode=1.1.1.1, SYSLOG=SYSLOG-1
$config['bad_if_regexp'][] = "/^\s*CPU Interface for Unit/"; // Dell NOS: CPU Interface for Unit: 0 Slot: 3 Port: 1
// Ignore ports based on ifType. Case-sensitive.
// FIXME. Rename to $config['ports']['ignore_type']
@ -680,9 +690,9 @@ $config['bad_iftype'][] = "usb"; // Ignore USB pseudo interface (BSD)
// Ignore ports based on ifAlias
// FIXME. Rename to $config['ports']['ignore_alias_regexp']
$config['bad_ifalias_regexp'] = array();
$config['bad_ifalias_regexp'] = [];
$config['ports']['ignore_errors_iftype'] = ['ieee80211'];
$config['ports']['ignore_errors_iftype'] = [ 'ieee80211' ];
// Neighbour discovery/autodiscovery options
// Ignore discover remote devices via discovery protocols (CDP, LLDP, FDP, AMAP and other)
@ -833,7 +843,7 @@ $config['irc_ssl'] = FALSE;
// Authentication
$config['allow_unauth_graphs'] = 0; // Allow graphs to be viewed by anyone
$config['allow_unauth_graphs_cidr'] = array(); // Allow graphs to be viewed without authorisation from certain IP ranges
$config['allow_unauth_graphs_cidr'] = []; // Allow graphs to be viewed without authorisation from certain IP ranges
$config['auth_mechanism'] = "mysql"; // Available mechanisms: mysql (default), ldap, radius, http-auth
$config['auth']['remote_user'] = FALSE; // Trust Apache server to authenticate user, READ DOCUMENTATION FIRST!!
@ -967,7 +977,7 @@ $config['wmi']['modules']['storage'] = 1;
$config['wmi']['modules']['winservices'] = 1;
$config['wmi']['modules']['exchange'] = 0;
$config['wmi']['modules']['mssql'] = 0;
$config['wmi']['service_permit'] = array();
$config['wmi']['service_permit'] = [];
// Hardcoded ASN descriptions
$config['astext'][65332] = "Cymru FullBogon Feed";

View File

@ -70,9 +70,6 @@ define('OBS_PERMIT_EDIT', 8); // Can edit
define('OBS_PERMIT_ADMIN', 16); // Can add/remove
define('OBS_PERMIT_ALL', OBS_PERMIT_ACCESS | OBS_PERMIT_READ | OBS_PERMIT_SECURE | OBS_PERMIT_EDIT | OBS_PERMIT_ADMIN); // Permit all
const OBS_DB_NO_LEADING_AND = 1; // Do not add leading AND to result query (default add)
const OBS_DB_IFNULL = 2; // Add IFNULL() for column compare
// Configuration view levels
define('OBS_CONFIG_BASIC', 1); // 0001: Basic view, 0001
define('OBS_CONFIG_ADVANCED', 3); // 0011: Advanced view, includes basic
@ -147,6 +144,7 @@ const OBS_PATTERN_ALPHA = '/^[\w\.\-]+$/';
const OBS_PATTERN_NOPRINT = '/[^\p{L}\p{N}\p{P}\p{S} ]/u'; // Non-printable UTF8 chars
const OBS_PATTERN_NOLATIN = '/[^\p{Common}\p{Latin}]/u'; // Non Latin (UTF8?) chars
const OBS_PATTERN_VAR_NAME = '/^\w[\w\s\.\-+]*(\[[\w\.\-+]*\])*$/';
const OBS_PATTERN_REGEXP = '/^\s*(?<delimiter>[//!#@%+])(?<pattern>.+)(\1)(?<modifiers>[imsxu])?\s*$/s'; // Detect string is common pattern
// Json flags
define('OBS_JSON_BIGINT_AS_STRING', PHP_VERSION_ID >= 50400 && PHP_INT_SIZE > 4 && !(defined('JSON_C_VERSION'))); // Check if BIGINT supported
@ -204,9 +202,10 @@ const OBS_MIN_PHP_VERSION = '5.6.26'; // PHP (15 Sep 2016, https://www.php.net/r
//define('OBS_MIN_PYTHON2_VERSION', '2.7.12'); // Python 2 (26 June 2016, https://www.python.org/doc/versions/)
const OBS_MIN_PYTHON2_VERSION = '2.7.5'; // last in RHEL/CentOS 7 (and Ubuntu LTS 14.04)
const OBS_MIN_PYTHON3_VERSION = '3.5.2'; // Python 3 (27 June 2016, https://www.python.org/doc/versions/)
const OBS_MIN_MYSQL_VERSION = '5.6.5'; // https://stackoverflow.com/questions/4489548/why-there-can-be-only-one-timestamp-column-with-current-timestamp-in-default-cla
//define('OBS_MIN_MARIADB_VERSION', '10.0'); // MySQL 5.6 mostly equals with MariaDB 10.0: https://mariadb.com/kb/en/timestamp/
const OBS_MIN_MARIADB_VERSION = '5.5.68'; // 5.5.68 last in RHEL/CentOS 7 and 5.5.63 in Ubuntu LTS 14.04
//const OBS_MIN_MYSQL_VERSION = '5.6.5'; // https://stackoverflow.com/questions/4489548/why-there-can-be-only-one-timestamp-column-with-current-timestamp-in-default-cla
const OBS_MIN_MYSQL_VERSION = '5.7.0'; // JSON data type was added in 5.7
//const OBS_MIN_MARIADB_VERSION = '5.5.68'; // 5.5.68 last in RHEL/CentOS 7 and 5.5.63 in Ubuntu LTS 14.04
const OBS_MIN_MARIADB_VERSION = '10.2.7'; // JSON data type was added in 10.2.7: https://mariadb.com/kb/en/json-data-type/
const OBS_MIN_RRD_VERSION = '1.4.8'; // last in RHEL/CentOS 7
//define('OBS_MIN_RRD_VERSION', '1.5.5'); // RRDTool (10 Nov 2015, https://github.com/oetiker/rrdtool-1.x/tags)
@ -337,8 +336,8 @@ else { $config['cache_dir'] = rtrim($config[
// Load random_compat (for PHP 5.x)
require_once("random_compat/random.php");
// Load hash-compat (for < PHP 5.6)
require_once("hash-compat/hash_equals.php");
// CLEANME. Load hash-compat (for < PHP 5.6)
//require_once("hash-compat/hash_equals.php");
// Collect php errors mostly for catch php8 errors
if ($config['php_debug'] && !defined('__PHPUNIT_PHAR__')) {
@ -389,6 +388,8 @@ $definition_files = [
'apps', // Apps system definitions
];
//echo "definitions was last modified: " . date ("F d Y H:i:s.", filemtime('/opt/observium/includes/definitions/')) . "\n";
foreach ($definition_files as $file) {
$file = $config['install_dir'].'/includes/definitions/'.$file.'.inc.php';
if (is_file($file)) {
@ -398,132 +399,147 @@ foreach ($definition_files as $file) {
unset($definition_files, $file); // Clean
// Alert Graphs
## FIXME - this is ugly
## Merge it in to entities, since that's what it is!
$config['alert_graphs']['port']['ifInOctets_rate'] = array('type' => 'port_bits', 'id' => '@port_id');
$config['alert_graphs']['port']['ifOutOctets_rate'] = array('type' => 'port_bits', 'id' => '@port_id');
$config['alert_graphs']['port']['ifInOctets_perc'] = array('type' => 'port_percent', 'id' => '@port_id');
$config['alert_graphs']['port']['ifOutOctets_perc'] = array('type' => 'port_percent', 'id' => '@port_id');
$config['alert_graphs']['mempool']['mempool_perc'] = array('type' => 'mempool_usage', 'id' => '@mempool_id');
$config['alert_graphs']['sensor']['sensor_value'] = array('type' => 'sensor_graph', 'id' => '@sensor_id');
$config['alert_graphs']['sensor']['sensor_event'] = array('type' => 'sensor_graph', 'id' => '@sensor_id');
$config['alert_graphs']['status']['status_event'] = array('type' => 'status_graph', 'id' => '@status_id');
$config['alert_graphs']['status']['status_state'] = array('type' => 'status_graph', 'id' => '@status_id');
$config['alert_graphs']['processor']['processor_usage'] = array('type' => 'processor_usage', 'id' => '@processor_id');
$config['alert_graphs']['storage']['storage_perc'] = array('type' => 'storage_usage', 'id' => '@storage_id');
// IP types
// https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
$config['ip_types']['unspecified'] = array('networks' => array('0.0.0.0', '::/128'),
'name' => 'Unspecified', 'subtext' => 'Example: ::/128, 0.0.0.0',
'label-class' => 'error',
'descr' => 'This address may only be used as a source address by an initialising host before it has learned its own address. Example: ::/128, 0.0.0.0');
$config['ip_types']['loopback'] = array('networks' => array('127.0.0.0/8', '::1/128'),
'name' => 'Loopback', 'subtext' => 'Example: ::1/128, 127.0.0.1',
'label-class' => 'info',
'descr' => 'This address is used when a host talks to itself. Example: ::1/128, 127.0.0.1');
$config['ip_types']['private'] = array('networks' => array('10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', 'fc00::/7'),
'name' => 'Private Local Addresses', 'subtext' => 'Example: fdf8:f53b:82e4::53, 192.168.0.1',
'label-class' => 'warning',
'descr' => 'These addresses are reserved for local use in home and enterprise environments and are not public address space. Example: fdf8:f53b:82e4::53, 192.168.0.1');
$config['ip_types']['multicast'] = array('networks' => array('224.0.0.0/4', 'ff00::/8'),
'name' => 'Multicast', 'subtext' => 'Example: ff01:0:0:0:0:0:0:2, 224.0.0.1',
'label-class' => 'inverse',
'descr' => 'These addresses are used to identify multicast groups. Example: ff01:0:0:0:0:0:0:2, 224.0.0.1');
$config['ip_types']['link-local'] = array('networks' => array('169.254.0.0/16', 'fe80::/10'),
'name' => 'Link-Local Addresses', 'subtext' => 'Example: fe80::200:5aee:feaa:20a2, 169.254.3.1',
'label-class' => 'suppressed',
'descr' => 'These addresses are used on a single link or a non-routed common access network, such as an Ethernet LAN. Example: fe80::200:5aee:feaa:20a2, 169.254.3.1');
$config['ip_types']['ipv4mapped'] = array('networks' => array('::ffff/96'),
'name' => 'IPv6 IPv4-Mapped', 'subtext' => 'Example: ::ffff:192.0.2.47',
'label-class' => 'primary',
'descr' => 'These addresses are used to embed IPv4 addresses in an IPv6 address. Example: 64:ff9b::192.0.2.33');
$config['ip_types']['ipv4embedded'] = array('networks' => array('64:ff9b::/96'),
'name' => 'IPv6 IPv4-Embedded', 'subtext' => 'Example: ::ffff:192.0.2.47',
'label-class' => 'primary',
'descr' => 'IPv4-converted IPv6 addresses and IPv4-translatable IPv6 addresses. Example: 64:ff9b::192.0.2.33');
$config['ip_types']['6to4'] = array('networks' => array('192.88.99.0/24', '2002::/16'),
'name' => 'IPv6 6to4', 'subtext' => 'Example: 2002:cb0a:3cdd:1::1, 192.88.99.1',
'label-class' => 'primary',
'descr' => 'A 6to4 gateway adds its IPv4 address to this 2002::/16, creating a unique /48 prefix. Example: 2002:cb0a:3cdd:1::1, 192.88.99.1');
$config['ip_types']['documentation'] = array('networks' => array('192.0.2.0/24', '198.51.100.0/24', '203.0.113.0/24', '2001:db8::/32'),
'name' => 'Documentation', 'subtext' => 'Example: 2001:db8:8:4::2, 203.0.113.1',
'label-class' => 'primary',
'descr' => 'These addresses are used in examples and documentation. Example: 2001:db8:8:4::2, 203.0.113.1');
$config['ip_types']['teredo'] = array('networks' => array('2001:0000::/32'),
'name' => 'IPv6 Teredo', 'subtext' => 'Example: 2001:0000:4136:e378:8000:63bf:3fff:fdd2',
'label-class' => 'primary',
'descr' => 'This is a mapped address allowing IPv6 tunneling through IPv4 NATs. The address is formed using the Teredo prefix, the servers unique IPv4 address, flags describing the type of NAT, the obfuscated client port and the client IPv4 address, which is probably a private address. Example: 2001:0000:4136:e378:8000:63bf:3fff:fdd2');
$config['ip_types']['benchmark'] = array('networks' => array('198.18.0.0/15', '2001:0002::/48'),
'name' => 'Benchmarking', 'subtext' => 'Example: 2001:0002:6c::430, 198.18.0.1',
'label-class' => 'error',
'descr' => 'These addresses are reserved for use in documentation. Example: 2001:0002:6c::430, 198.18.0.1');
$config['ip_types']['orchid'] = array('networks' => array('2001:0010::/28', '2001:0020::/28'),
'name' => 'IPv6 Orchid', 'subtext' => 'Example: 2001:10:240:ab::a',
'label-class' => 'primary',
'descr' => 'These addresses are used for a fixed-term experiment. Example: 2001:10:240:ab::a');
$config['ip_types']['reserved'] = array(//'networks' => array(),
'name' => 'Reserved', 'subtext' => 'Address in reserved address space',
'label-class' => 'error',
'descr' => 'Reserved address space');
$config['ip_types']['broadcast'] = array(//'networks' => array(),
'name' => 'IPv4 Broadcast', 'subtext' => 'Example: 255.255.255.255',
'label-class' => 'disabled',
'descr' => 'IPv4 broadcast address. Example: 255.255.255.255');
$config['ip_types']['anycast'] = array(//'networks' => array(),
'name' => 'Anycast',
'label-class' => 'primary',
'descr' => 'Anycast is a network addressing and routing methodology in which a single destination address has multiple routing paths to two or more endpoint destinations.');
$config['ip_types']['unspecified'] = [
'networks' => [ '0.0.0.0', '::/128' ],
'name' => 'Unspecified', 'subtext' => 'Example: ::/128, 0.0.0.0',
'label-class' => 'error',
'descr' => 'This address may only be used as a source address by an initialising host before it has learned its own address. Example: ::/128, 0.0.0.0'
];
$config['ip_types']['loopback'] = [
'networks' => [ '127.0.0.0/8', '::1/128' ],
'name' => 'Loopback', 'subtext' => 'Example: ::1/128, 127.0.0.1',
'label-class' => 'info',
'descr' => 'This address is used when a host talks to itself. Example: ::1/128, 127.0.0.1'
];
$config['ip_types']['private'] = [
'networks' => [ '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', 'fc00::/7' ],
'name' => 'Private Local Addresses', 'subtext' => 'Example: fdf8:f53b:82e4::53, 192.168.0.1',
'label-class' => 'warning',
'descr' => 'These addresses are reserved for local use in home and enterprise environments and are not public address space. Example: fdf8:f53b:82e4::53, 192.168.0.1'
];
$config['ip_types']['multicast'] = [
'networks' => [ '224.0.0.0/4', 'ff00::/8' ],
'name' => 'Multicast', 'subtext' => 'Example: ff01:0:0:0:0:0:0:2, 224.0.0.1',
'label-class' => 'inverse',
'descr' => 'These addresses are used to identify multicast groups. Example: ff01:0:0:0:0:0:0:2, 224.0.0.1'
];
$config['ip_types']['link-local'] = [
'networks' => [ '169.254.0.0/16', 'fe80::/10' ],
'name' => 'Link-Local Addresses', 'subtext' => 'Example: fe80::200:5aee:feaa:20a2, 169.254.3.1',
'label-class' => 'suppressed',
'descr' => 'These addresses are used on a single link or a non-routed common access network, such as an Ethernet LAN. Example: fe80::200:5aee:feaa:20a2, 169.254.3.1'
];
$config['ip_types']['ipv4mapped'] = [
'networks' => [ '::ffff/96' ],
'name' => 'IPv6 IPv4-Mapped', 'subtext' => 'Example: ::ffff:192.0.2.47',
'label-class' => 'primary',
'descr' => 'These addresses are used to embed IPv4 addresses in an IPv6 address. Example: 64:ff9b::192.0.2.33'
];
$config['ip_types']['ipv4embedded'] = [
'networks' => [ '64:ff9b::/96' ],
'name' => 'IPv6 IPv4-Embedded', 'subtext' => 'Example: ::ffff:192.0.2.47',
'label-class' => 'primary',
'descr' => 'IPv4-converted IPv6 addresses and IPv4-translatable IPv6 addresses. Example: 64:ff9b::192.0.2.33'
];
$config['ip_types']['6to4'] = [
'networks' => [ '192.88.99.0/24', '2002::/16' ],
'name' => 'IPv6 6to4', 'subtext' => 'Example: 2002:cb0a:3cdd:1::1, 192.88.99.1',
'label-class' => 'primary',
'descr' => 'A 6to4 gateway adds its IPv4 address to this 2002::/16, creating a unique /48 prefix. Example: 2002:cb0a:3cdd:1::1, 192.88.99.1'
];
$config['ip_types']['documentation'] = [
'networks' => [ '192.0.2.0/24', '198.51.100.0/24', '203.0.113.0/24', '2001:db8::/32' ],
'name' => 'Documentation', 'subtext' => 'Example: 2001:db8:8:4::2, 203.0.113.1',
'label-class' => 'primary',
'descr' => 'These addresses are used in examples and documentation. Example: 2001:db8:8:4::2, 203.0.113.1'
];
$config['ip_types']['teredo'] = [
'networks' => [ '2001:0000::/32' ],
'name' => 'IPv6 Teredo', 'subtext' => 'Example: 2001:0000:4136:e378:8000:63bf:3fff:fdd2',
'label-class' => 'primary',
'descr' => 'This is a mapped address allowing IPv6 tunneling through IPv4 NATs. The address is formed using the Teredo prefix, the servers unique IPv4 address, flags describing the type of NAT, the obfuscated client port and the client IPv4 address, which is probably a private address. Example: 2001:0000:4136:e378:8000:63bf:3fff:fdd2'
];
$config['ip_types']['benchmark'] = [
'networks' => [ '198.18.0.0/15', '2001:0002::/48' ],
'name' => 'Benchmarking', 'subtext' => 'Example: 2001:0002:6c::430, 198.18.0.1',
'label-class' => 'error',
'descr' => 'These addresses are reserved for use in documentation. Example: 2001:0002:6c::430, 198.18.0.1'
];
$config['ip_types']['orchid'] = [
'networks' => [ '2001:0010::/28', '2001:0020::/28' ],
'name' => 'IPv6 Orchid', 'subtext' => 'Example: 2001:10:240:ab::a',
'label-class' => 'primary',
'descr' => 'These addresses are used for a fixed-term experiment. Example: 2001:10:240:ab::a'
];
$config['ip_types']['reserved'] = [
//'networks' => [],
'name' => 'Reserved', 'subtext' => 'Address in reserved address space',
'label-class' => 'error',
'descr' => 'Reserved address space'
];
$config['ip_types']['broadcast'] = [
//'networks' => [],
'name' => 'IPv4 Broadcast', 'subtext' => 'Example: 255.255.255.255',
'label-class' => 'disabled',
'descr' => 'IPv4 broadcast address. Example: 255.255.255.255'
];
$config['ip_types']['anycast'] = [
//'networks' => [],
'name' => 'Anycast',
'label-class' => 'primary',
'descr' => 'Anycast is a network addressing and routing methodology in which a single destination address has multiple routing paths to two or more endpoint destinations.'
];
// Keep this at last!
$config['ip_types']['unicast'] = array('networks' => array('2000::/3'), // 'networks' => array('0.0.0.0/0', '2000::/3'),'
'name' => 'Global Unicast', 'subtext' => 'Example: 2a02:408:7722::, 80.94.60.2', 'disabled' => 1,
'label-class' => 'success',
'descr' => 'Global Unicast addresses. Example: 2a02:408:7722::, 80.94.60.2');
$config['ip_types']['unicast'] = [
'networks' => [ '2000::/3' ], // 'networks' => [ '0.0.0.0/0', '2000::/3' ],'
'name' => 'Global Unicast', 'subtext' => 'Example: 2a02:408:7722::, 80.94.60.2', 'disabled' => 1,
'label-class' => 'success',
'descr' => 'Global Unicast addresses. Example: 2a02:408:7722::, 80.94.60.2'
];
// Syslog colour and name translation
$config['syslog']['priorities'][0] = array('name' => 'emergency', 'color' => '#D94640', 'label-class' => 'inverse', 'row-class' => 'error', 'emoji' => 'red_circle');
$config['syslog']['priorities'][1] = array('name' => 'alert', 'color' => '#D94640', 'label-class' => 'delayed', 'row-class' => 'error', 'emoji' => 'red_circle');
$config['syslog']['priorities'][2] = array('name' => 'critical', 'color' => '#D94640', 'label-class' => 'error', 'row-class' => 'error', 'emoji' => 'red_circle');
$config['syslog']['priorities'][3] = array('name' => 'error', 'color' => '#E88126', 'label-class' => 'error', 'row-class' => 'error', 'emoji' => 'red_circle');
$config['syslog']['priorities'][4] = array('name' => 'warning', 'color' => '#F2CA3F', 'label-class' => 'warning', 'row-class' => 'warning', 'emoji' => 'large_yellow_circle');
$config['syslog']['priorities'][5] = array('name' => 'notification', 'color' => '#107373', 'label-class' => 'success', 'row-class' => 'recovery', 'emoji' => 'large_orange_circle'); // large_green_circle
$config['syslog']['priorities'][6] = array('name' => 'informational', 'color' => '#499CA6', 'label-class' => 'primary', 'row-class' => '', 'emoji' => 'large_blue_circle'); //'row-class' => 'info');
$config['syslog']['priorities'][7] = array('name' => 'debugging', 'color' => '#5AA637', 'label-class' => 'suppressed', 'row-class' => 'suppressed', 'emoji' => 'large_purple_circle');
$config['syslog']['priorities'][0] = [ 'name' => 'emergency', 'color' => '#D94640', 'label-class' => 'inverse', 'row-class' => 'error', 'emoji' => 'red_circle' ];
$config['syslog']['priorities'][1] = [ 'name' => 'alert', 'color' => '#D94640', 'label-class' => 'delayed', 'row-class' => 'error', 'emoji' => 'red_circle' ];
$config['syslog']['priorities'][2] = [ 'name' => 'critical', 'color' => '#D94640', 'label-class' => 'error', 'row-class' => 'error', 'emoji' => 'red_circle' ];
$config['syslog']['priorities'][3] = [ 'name' => 'error', 'color' => '#E88126', 'label-class' => 'error', 'row-class' => 'error', 'emoji' => 'red_circle' ];
$config['syslog']['priorities'][4] = [ 'name' => 'warning', 'color' => '#F2CA3F', 'label-class' => 'warning', 'row-class' => 'warning', 'emoji' => 'large_yellow_circle' ];
$config['syslog']['priorities'][5] = [ 'name' => 'notification', 'color' => '#107373', 'label-class' => 'success', 'row-class' => 'recovery', 'emoji' => 'large_orange_circle' ]; // large_green_circle
$config['syslog']['priorities'][6] = [ 'name' => 'informational', 'color' => '#499CA6', 'label-class' => 'primary', 'row-class' => '', 'emoji' => 'large_blue_circle' ]; //'row-class' => 'info');
$config['syslog']['priorities'][7] = [ 'name' => 'debugging', 'color' => '#5AA637', 'label-class' => 'suppressed', 'row-class' => 'suppressed', 'emoji' => 'large_purple_circle' ];
for ($i = 8; $i < 16; $i++)
{
$config['syslog']['priorities'][$i] = array('name' => 'other', 'color' => '#D2D8F9', 'label-class' => 'disabled', 'row-class' => 'disabled', 'emoji' => 'large_orange_circle');
$config['syslog']['priorities'][$i] = [ 'name' => 'other', 'color' => '#D2D8F9', 'label-class' => 'disabled', 'row-class' => 'disabled', 'emoji' => 'large_orange_circle' ];
}
// https://tools.ietf.org/html/draft-ietf-netmod-syslog-model-14
$config['syslog']['facilities'][0] = array('name' => 'kern', 'descr' => 'kernel messages');
$config['syslog']['facilities'][1] = array('name' => 'user', 'descr' => 'user-level messages');
$config['syslog']['facilities'][2] = array('name' => 'mail', 'descr' => 'mail system');
$config['syslog']['facilities'][3] = array('name' => 'daemon', 'descr' => 'system daemons');
$config['syslog']['facilities'][4] = array('name' => 'auth', 'descr' => 'security/authorization messages');
$config['syslog']['facilities'][5] = array('name' => 'syslog', 'descr' => 'messages generated internally by syslogd');
$config['syslog']['facilities'][6] = array('name' => 'lpr', 'descr' => 'line printer subsystem');
$config['syslog']['facilities'][7] = array('name' => 'news', 'descr' => 'network news subsystem');
$config['syslog']['facilities'][8] = array('name' => 'uucp', 'descr' => 'UUCP subsystem');
$config['syslog']['facilities'][9] = array('name' => 'cron', 'descr' => 'clock daemon');
$config['syslog']['facilities'][10] = array('name' => 'authpriv', 'descr' => 'security/authorization messages');
$config['syslog']['facilities'][11] = array('name' => 'ftp', 'descr' => 'FTP daemon');
$config['syslog']['facilities'][12] = array('name' => 'ntp', 'descr' => 'NTP subsystem');
$config['syslog']['facilities'][13] = array('name' => 'audit', 'descr' => 'log audit');
$config['syslog']['facilities'][14] = array('name' => 'console', 'descr' => 'log alert');
$config['syslog']['facilities'][15] = array('name' => 'cron2', 'descr' => 'clock daemon');
$config['syslog']['facilities'][16] = array('name' => 'local0', 'descr' => 'local use 0 (local0)');
$config['syslog']['facilities'][17] = array('name' => 'local1', 'descr' => 'local use 1 (local1)');
$config['syslog']['facilities'][18] = array('name' => 'local2', 'descr' => 'local use 2 (local2)');
$config['syslog']['facilities'][19] = array('name' => 'local3', 'descr' => 'local use 3 (local3)');
$config['syslog']['facilities'][20] = array('name' => 'local4', 'descr' => 'local use 4 (local4)');
$config['syslog']['facilities'][21] = array('name' => 'local5', 'descr' => 'local use 5 (local5)');
$config['syslog']['facilities'][22] = array('name' => 'local6', 'descr' => 'local use 6 (local6)');
$config['syslog']['facilities'][23] = array('name' => 'local7', 'descr' => 'local use 7 (local7)');
$config['syslog']['facilities'][0] = [ 'name' => 'kern', 'descr' => 'kernel messages' ];
$config['syslog']['facilities'][1] = [ 'name' => 'user', 'descr' => 'user-level messages' ];
$config['syslog']['facilities'][2] = [ 'name' => 'mail', 'descr' => 'mail system' ];
$config['syslog']['facilities'][3] = [ 'name' => 'daemon', 'descr' => 'system daemons' ];
$config['syslog']['facilities'][4] = [ 'name' => 'auth', 'descr' => 'security/authorization messages' ];
$config['syslog']['facilities'][5] = [ 'name' => 'syslog', 'descr' => 'messages generated internally by syslogd' ];
$config['syslog']['facilities'][6] = [ 'name' => 'lpr', 'descr' => 'line printer subsystem' ];
$config['syslog']['facilities'][7] = [ 'name' => 'news', 'descr' => 'network news subsystem' ];
$config['syslog']['facilities'][8] = [ 'name' => 'uucp', 'descr' => 'UUCP subsystem' ];
$config['syslog']['facilities'][9] = [ 'name' => 'cron', 'descr' => 'clock daemon' ];
$config['syslog']['facilities'][10] = [ 'name' => 'authpriv', 'descr' => 'security/authorization messages' ];
$config['syslog']['facilities'][11] = [ 'name' => 'ftp', 'descr' => 'FTP daemon' ];
$config['syslog']['facilities'][12] = [ 'name' => 'ntp', 'descr' => 'NTP subsystem' ];
$config['syslog']['facilities'][13] = [ 'name' => 'audit', 'descr' => 'log audit' ];
$config['syslog']['facilities'][14] = [ 'name' => 'console', 'descr' => 'log alert' ];
$config['syslog']['facilities'][15] = [ 'name' => 'cron2', 'descr' => 'clock daemon' ];
$config['syslog']['facilities'][16] = [ 'name' => 'local0', 'descr' => 'local use 0 (local0)' ];
$config['syslog']['facilities'][17] = [ 'name' => 'local1', 'descr' => 'local use 1 (local1)' ];
$config['syslog']['facilities'][18] = [ 'name' => 'local2', 'descr' => 'local use 2 (local2)' ];
$config['syslog']['facilities'][19] = [ 'name' => 'local3', 'descr' => 'local use 3 (local3)' ];
$config['syslog']['facilities'][20] = [ 'name' => 'local4', 'descr' => 'local use 4 (local4)' ];
$config['syslog']['facilities'][21] = [ 'name' => 'local5', 'descr' => 'local use 5 (local5)' ];
$config['syslog']['facilities'][22] = [ 'name' => 'local6', 'descr' => 'local use 6 (local6)' ];
$config['syslog']['facilities'][23] = [ 'name' => 'local7', 'descr' => 'local use 7 (local7)' ];
// Alert severities (emoji used _only_ as notification icon)
// Recover emoji is white_check_mark
@ -532,7 +548,7 @@ $config['alert']['severity']['warn'] = [ 'name' => 'Warning', 'color' => '
//$config['alert']['severity']['info'] = [ 'name' => 'Informational', 'color' => '#499CA6', 'label-class' => 'primary', 'row-class' => 'info', 'icon' => $config['icon']['informational'], 'emoji' => 'information_source' ];
// Possible transports for net-snmp, used for enumeration in several functions
$config['snmp']['transports'] = array('udp', 'udp6', 'tcp', 'tcp6');
$config['snmp']['transports'] = [ 'udp', 'udp6', 'tcp', 'tcp6' ];
// 'count' is min total errors count, after which autodisable this MIB/oid pair
// 'rate' is min total rate (per poll), after which autodisable this MIB/oid pair
@ -645,10 +661,10 @@ $config['snmp']['errorcodes'][1000] = [
'name' => 'OBS_SNMP_ERROR_FAILED_RESPONSE',
'msg' => ''
];
//$config['snmp']['errorcodes'][1001] = array('reason' => 'Authentication failure', // Snmp auth errors
//$config['snmp']['errorcodes'][1001] = ['reason' => 'Authentication failure', // Snmp auth errors
// 'count' => 25, // errors in every poll run, disable after ~ 1.5 hour
// 'rate' => 0.9,
// 'msg' => '');
// 'msg' => ''];
$config['snmp']['errorcodes'][1002] = [
'reason' => 'Request timeout', // Cmd exit by timeout
'count' => 25, // errors in every poll run, disable after ~ 1.5 hour
@ -699,17 +715,17 @@ unset($errorname, $errorcode, $tmp);
// IPMI user levels (used in GUI, first entry = default if unset)
$config['ipmi']['userlevels']['USER'] = array('text' => 'User');
$config['ipmi']['userlevels']['OPERATOR'] = array('text' => 'Operator');
$config['ipmi']['userlevels']['ADMINISTRATOR'] = array('text' => 'Administrator');
$config['ipmi']['userlevels']['CALLBACK'] = array('text' => 'Callback');
$config['ipmi']['userlevels']['USER'] = [ 'text' => 'User' ];
$config['ipmi']['userlevels']['OPERATOR'] = [ 'text' => 'Operator' ];
$config['ipmi']['userlevels']['ADMINISTRATOR'] = [ 'text' => 'Administrator' ];
$config['ipmi']['userlevels']['CALLBACK'] = [ 'text' => 'Callback' ];
// IPMI interfaces (used in GUI, first entry = default if unset)
$config['ipmi']['interfaces']['lan'] = array('text' => 'IPMI v1.5 LAN Interface');
$config['ipmi']['interfaces']['lanplus'] = array('text' => 'IPMI v2.0 RMCP+ LAN Interface');
$config['ipmi']['interfaces']['imb'] = array('text' => 'Intel IMB Interface');
$config['ipmi']['interfaces']['open'] = array('text' => 'Linux OpenIPMI Interface');
$config['ipmi']['interfaces']['lan'] = [ 'text' => 'IPMI v1.5 LAN Interface' ];
$config['ipmi']['interfaces']['lanplus'] = [ 'text' => 'IPMI v2.0 RMCP+ LAN Interface' ];
$config['ipmi']['interfaces']['imb'] = [ 'text' => 'Intel IMB Interface' ];
$config['ipmi']['interfaces']['open'] = [ 'text' => 'Linux OpenIPMI Interface' ];
// CLEANME. RANCID OS map (for config generation script)
/* MOVED to os definitions as $config['os'][$os]['rancid']
@ -811,52 +827,70 @@ if (OBS_DB_SKIP !== TRUE) {
// Base user levels
$config['user_level'] = array(); // Init this array, for do not allow override over config.inc.php!
$config['user_level'][0] = array('permission' => 0,
'name' => 'Disabled',
'subtext' => 'This user disabled',
'notes' => 'User complete can\'t login and use any services. Use it to block access for specific users, but not delete from DB.',
'row_class' => 'disabled',
'icon' => $config['icon']['user-delete']);
$config['user_level'][1] = array('permission' => OBS_PERMIT_ACCESS,
'name' => 'Normal User',
'subtext' => 'This user has read access to individual entities',
'notes' => 'User can\'t see or edit anything by default. Can only see devices and entities specifically permitted.',
'row_class' => 'default',
'icon' => $config['icon']['users']);
$config['user_level'][5] = array('permission' => OBS_PERMIT_ACCESS | OBS_PERMIT_READ,
'name' => 'Global Read',
'subtext' => 'This user has global read access',
'notes' => 'User can see all devices and entities with some security and configuration data masked, such as passwords.',
'row_class' => 'suppressed',
'icon' => $config['icon']['user-self']);
$config['user_level'][7] = array('permission' => OBS_PERMIT_ACCESS | OBS_PERMIT_READ | OBS_PERMIT_SECURE,
'name' => 'Global Secure Read',
'subtext' => 'This user has global read access with secured info',
'notes' => 'User can see all devices and entities without any information being masked, including device configuration (supplied by e.g. RANCID).',
'row_class' => 'warning',
'icon' => $config['icon']['user-self']);
$config['user_level'][8] = array('permission' => OBS_PERMIT_ACCESS | OBS_PERMIT_READ | OBS_PERMIT_SECURE | OBS_PERMIT_EDIT,
'name' => 'Global Secure Read / Limited Write',
'subtext' => 'This user has secure global read access with scheduled maintenence read/write.',
'notes' => 'User can see all devices and entities without any information being masked, including device configuration (supplied by e.g. RANCID). User can also add, edit and remove scheduled maintenance, group, contacts.',
'row_class' => 'warning',
'icon' => $config['icon']['user-self']);
$config['user_level'][10] = array('permission' => OBS_PERMIT_ALL,
'name' => 'Administrator',
'subtext' => 'This user has full administrative access',
'notes' => 'User can see and edit all devices and entities. This includes adding and removing devices, bills and users.',
'row_class' => 'success',
'icon' => $config['icon']['user-log']);
$config['user_level'] = []; // Init this array, for do not allow override over config.inc.php!
$config['user_level'][0] = [
'permission' => 0, // CLEANME, remove this entry when converted to roles
'roles' => [],
'name' => 'Disabled',
'subtext' => 'This user disabled',
'notes' => 'User complete can\'t login and use any services. Use it to block access for specific users, but not delete from DB.',
'row_class' => 'disabled',
'icon' => $config['icon']['user-delete']
];
$config['user_level'][1] = [
'permission' => OBS_PERMIT_ACCESS, // CLEANME, remove this entry when converted to roles
'roles' => [ 'LOGIN' ],
'name' => 'Normal User',
'subtext' => 'This user has read access to individual entities',
'notes' => 'User can\'t see or edit anything by default. Can only see devices and entities specifically permitted.',
'row_class' => 'default',
'icon' => $config['icon']['users']
];
$config['user_level'][5] = [
'permission' => OBS_PERMIT_ACCESS | OBS_PERMIT_READ, // CLEANME, remove this entry when converted to roles
'roles' => [ 'GLOBAL_READ' ],
'name' => 'Global Read',
'subtext' => 'This user has global read access',
'notes' => 'User can see all devices and entities with some security and configuration data masked, such as passwords.',
'row_class' => 'suppressed',
'icon' => $config['icon']['user-self']
];
$config['user_level'][7] = [
'permission' => OBS_PERMIT_ACCESS | OBS_PERMIT_READ | OBS_PERMIT_SECURE, // CLEANME, remove this entry when converted to roles
'roles' => [ 'SECURE_READ' ],
'name' => 'Global Secure Read',
'subtext' => 'This user has global read access with secured info',
'notes' => 'User can see all devices and entities without any information being masked, including device configuration (supplied by e.g. RANCID).',
'row_class' => 'warning',
'icon' => $config['icon']['user-self']
];
$config['user_level'][8] = [
'permission' => OBS_PERMIT_ACCESS | OBS_PERMIT_READ | OBS_PERMIT_SECURE | OBS_PERMIT_EDIT, // CLEANME, remove this entry when converted to roles
'roles' => [ 'EDIT' ],
'name' => 'Global Secure Read / Limited Write',
'subtext' => 'This user has secure global read access with scheduled maintenence read/write.',
'notes' => 'User can see all devices and entities without any information being masked, including device configuration (supplied by e.g. RANCID). User can also add, edit and remove scheduled maintenance, group, contacts.',
'row_class' => 'warning',
'icon' => $config['icon']['user-self']
];
$config['user_level'][10] = [
'permission' => OBS_PERMIT_ALL, // CLEANME, remove this entry when converted to roles
'roles' => [ 'ADMIN' ],
'name' => 'Administrator',
'subtext' => 'This user has full administrative access',
'notes' => 'User can see and edit all devices and entities. This includes adding and removing devices, bills and users.',
'row_class' => 'success',
'icon' => $config['icon']['user-log']
];
$config['remote_access']['ssh'] = array('name' => "SSH", 'port' => '22', 'icon' => 'oicon-application-terminal');
$config['remote_access']['telnet'] = array('name' => "Telnet", 'port' => '23', 'icon' => 'oicon-application-list');
$config['remote_access']['scp'] = array('name' => "SFTP", 'port' => '22', 'icon' => 'oicon-disk-black');
$config['remote_access']['ftp'] = array('name' => "FTP", 'port' => '21', 'icon' => 'oicon-disk');
$config['remote_access']['http'] = array('name' => "HTTP", 'port' => '80', 'icon' => 'oicon-application-icon-large');
$config['remote_access']['https'] = array('name' => "HTTPS", 'port' => '443', 'icon' => 'oicon-shield');
$config['remote_access']['rdp'] = array('name' => "RDP", 'port' => '3389', 'icon' => 'oicon-connect');
$config['remote_access']['vnc'] = array('name' => "VNC", 'port' => '5901', 'icon' => 'oicon-computer');
$config['remote_access']['ssh'] = [ 'name' => "SSH", 'port' => '22', 'icon' => 'oicon-application-terminal' ];
$config['remote_access']['telnet'] = [ 'name' => "Telnet", 'port' => '23', 'icon' => 'oicon-application-list' ];
$config['remote_access']['scp'] = [ 'name' => "SFTP", 'port' => '22', 'icon' => 'oicon-disk-black' ];
$config['remote_access']['ftp'] = [ 'name' => "FTP", 'port' => '21', 'icon' => 'oicon-disk' ];
$config['remote_access']['http'] = [ 'name' => "HTTP", 'port' => '80', 'icon' => 'oicon-application-icon-large' ];
$config['remote_access']['https'] = [ 'name' => "HTTPS", 'port' => '443', 'icon' => 'oicon-shield' ];
$config['remote_access']['rdp'] = [ 'name' => "RDP", 'port' => '3389', 'icon' => 'oicon-connect' ];
$config['remote_access']['vnc'] = [ 'name' => "VNC", 'port' => '5901', 'icon' => 'oicon-computer' ];
// Set some times needed by loads of scripts (it's dynamic, so we do it here!)
$config['time']['now'] = time();
@ -880,34 +914,34 @@ $config['time']['threeyear'] = $config['time']['now'] - 94608000; //time() - (3
// Obsolete config variables
// Note, for multiarray config options use conversion with '->'
// example: $config['email']['default'] --> 'email->default'
$config['obsolete_config'] = array(); // NOT CONFIGURABLE, init
$config['obsolete_config'][] = array('old' => 'warn->ifdown', 'new' => 'frontpage->device_status->ports');
$config['obsolete_config'][] = array('old' => 'alerts->email->enable', 'new' => 'email->enable', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'alerts->email->default', 'new' => 'email->default', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'alerts->email->default_only', 'new' => 'email->default_only', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'alerts->email->graphs', 'new' => 'email->graphs', 'info' => 'changed since r6976');
$config['obsolete_config'][] = array('old' => 'email_backend', 'new' => 'email->backend', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'email_from', 'new' => 'email->from', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'email_sendmail_path', 'new' => 'email->sendmail_path', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'email_smtp_host', 'new' => 'email->smtp_host', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'email_smtp_port', 'new' => 'email->smtp_port', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'email_smtp_timeout', 'new' => 'email->smtp_timeout', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'email_smtp_secure', 'new' => 'email->smtp_secure', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'email_smtp_auth', 'new' => 'email->smtp_auth', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'email_smtp_username', 'new' => 'email->smtp_username', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'email_smtp_password', 'new' => 'email->smtp_password', 'info' => 'changed since r5787');
$config['obsolete_config'][] = array('old' => 'discovery_modules->cisco-pw', 'new' => 'discovery_modules->pseudowires', 'info' => 'changed since r6205');
$config['obsolete_config'][] = array('old' => 'discovery_modules->discovery-protocols', 'new' => 'discovery_modules->neighbours', 'info' => 'changed since r6744');
$config['obsolete_config'][] = array('old' => 'search_modules', 'new' => 'wui->search_modules', 'info' => 'changed since r7463');
$config['obsolete_config'][] = array('old' => 'discovery_modules->ipv4-addresses', 'new' => 'discovery_modules->ip-addresses', 'info' => 'changed since r7565');
$config['obsolete_config'][] = array('old' => 'discovery_modules->ipv6-addresses', 'new' => 'discovery_modules->ip-addresses', 'info' => 'changed since r7565');
$config['obsolete_config'][] = array('old' => 'location_map', 'new' => 'location->map', 'info' => 'changed since r8021');
$config['obsolete_config'][] = array('old' => 'geocoding->api_key', 'new' => 'geo_api->google->key', 'info' => 'DEPRECATED since 19.8.10000');
$config['obsolete_config'][] = array('old' => 'snmp->snmp_sysorid', 'new' => 'discovery_modules->mibs', 'info' => 'Migrated to separate module since 19.10.10091');
$config['obsolete_config'] = []; // NOT CONFIGURABLE, init
$config['obsolete_config'][] = [ 'old' => 'warn->ifdown', 'new' => 'frontpage->device_status->ports' ];
$config['obsolete_config'][] = [ 'old' => 'alerts->email->enable', 'new' => 'email->enable', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'alerts->email->default', 'new' => 'email->default', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'alerts->email->default_only', 'new' => 'email->default_only', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'alerts->email->graphs', 'new' => 'email->graphs', 'info' => 'changed since r6976' ];
$config['obsolete_config'][] = [ 'old' => 'email_backend', 'new' => 'email->backend', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'email_from', 'new' => 'email->from', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'email_sendmail_path', 'new' => 'email->sendmail_path', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'email_smtp_host', 'new' => 'email->smtp_host', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'email_smtp_port', 'new' => 'email->smtp_port', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'email_smtp_timeout', 'new' => 'email->smtp_timeout', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'email_smtp_secure', 'new' => 'email->smtp_secure', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'email_smtp_auth', 'new' => 'email->smtp_auth', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'email_smtp_username', 'new' => 'email->smtp_username', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'email_smtp_password', 'new' => 'email->smtp_password', 'info' => 'changed since r5787' ];
$config['obsolete_config'][] = [ 'old' => 'discovery_modules->cisco-pw', 'new' => 'discovery_modules->pseudowires', 'info' => 'changed since r6205' ];
$config['obsolete_config'][] = [ 'old' => 'discovery_modules->discovery-protocols', 'new' => 'discovery_modules->neighbours', 'info' => 'changed since r6744' ];
$config['obsolete_config'][] = [ 'old' => 'search_modules', 'new' => 'wui->search_modules', 'info' => 'changed since r7463' ];
$config['obsolete_config'][] = [ 'old' => 'discovery_modules->ipv4-addresses', 'new' => 'discovery_modules->ip-addresses', 'info' => 'changed since r7565' ];
$config['obsolete_config'][] = [ 'old' => 'discovery_modules->ipv6-addresses', 'new' => 'discovery_modules->ip-addresses', 'info' => 'changed since r7565' ];
$config['obsolete_config'][] = [ 'old' => 'location_map', 'new' => 'location->map', 'info' => 'changed since r8021' ];
$config['obsolete_config'][] = [ 'old' => 'geocoding->api_key', 'new' => 'geo_api->google->key', 'info' => 'DEPRECATED since 19.8.10000' ];
$config['obsolete_config'][] = [ 'old' => 'snmp->snmp_sysorid', 'new' => 'discovery_modules->mibs', 'info' => 'Migrated to separate module since 19.10.10091' ];
$config['obsolete_config'][] = array('old' => 'bad_xdp', 'new' => 'xdp->ignore_hostname', 'info' => 'changed since 20.6.10520');
$config['obsolete_config'][] = array('old' => 'bad_xdp_regexp', 'new' => 'xdp->ignore_hostname_regex', 'info' => 'changed since 20.6.10520');
$config['obsolete_config'][] = array('old' => 'bad_xdp_platform', 'new' => 'xdp->ignore_platform', 'info' => 'changed since 20.6.10520');
$config['obsolete_config'][] = [ 'old' => 'bad_xdp', 'new' => 'xdp->ignore_hostname', 'info' => 'changed since 20.6.10520' ];
$config['obsolete_config'][] = [ 'old' => 'bad_xdp_regexp', 'new' => 'xdp->ignore_hostname_regex', 'info' => 'changed since 20.6.10520' ];
$config['obsolete_config'][] = [ 'old' => 'bad_xdp_platform', 'new' => 'xdp->ignore_platform', 'info' => 'changed since 20.6.10520' ];
$config['obsolete_config'][] = [ 'old' => 'discovery_modules->cisco-vrf', 'new' => 'discovery_modules->vrf', 'info' => 'changed since 20.10.10792' ];
@ -925,6 +959,6 @@ $config['hide_config'] = [
// Here whitelist of base definitions keys which can be overridden by config.php file
// Note, this required only for override already exist definitions, for additions not required
$config['definitions_whitelist'] = array('os', 'mibs', 'device_types', 'rancid', 'geo_api', 'search_modules', 'rewrites', 'nicecase', 'wui');
$config['definitions_whitelist'] = [ 'os', 'mibs', 'device_types', 'rancid', 'geo_api', 'search_modules', 'rewrites', 'nicecase', 'wui' ];
// End of includes/definitions.inc.php

Binary file not shown.

View File

@ -4,9 +4,9 @@ define('OBSERVIUM_EDITION', 'community');
define('OBSERVIUM_PRODUCT', 'Observium CE');
define('OBSERVIUM_PRODUCT_LONG', 'Observium Community Edition');
define('OBSERVIUM_TRAIN', 'ce');
define('OBSERVIUM_REV', '12042');
define('OBSERVIUM_DATE', '2022-05-24');
define('OBSERVIUM_VERSION', '22.5.12042');
define('OBSERVIUM_VERSION_LONG', '22.5.12042');
define('OBSERVIUM_REV', '12447');
define('OBSERVIUM_DATE', '2022-12-30');
define('OBSERVIUM_VERSION', '22.12.12447');
define('OBSERVIUM_VERSION_LONG', '22.12.12447');
//EOF

View File

@ -64,6 +64,7 @@ $config['escape_html']['entities'][] = '#8203'; // &#x200B; U+200B ZERO WI
$config['pages']['gridstack']['no_panel'] = TRUE;
$config['pages']['dashboard']['no_panel'] = TRUE;
$config['pages']['map']['no_panel'] = TRUE;
$config['pages']['map-traffic']['no_panel'] = TRUE;
// Refresh pages definitions
$config['wui']['refresh_times'] = array(0, 60, 120, 300, 900, 1800); // Allowed refresh times in seconds
@ -194,6 +195,7 @@ $config['icon']['pollers'] = "sprite-module";
$config['icon']['processes'] = "sprite-processes";
$config['icon']['netmap'] = "sprite-netmap";
$config['icon']['map'] = "sprite-map";
$config['icon']['contacts'] = "sprite-mail";
$config['icon']['contact-add'] = $config['icon']['plus'];
@ -349,6 +351,8 @@ $config['icon']['database'] = "sprite-database";
$config['icon']['mibs'] = "sprite-map-2";
$config['icon']['notes'] = "sprite-note";
// Font icons

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -62,7 +62,7 @@ if ($ipNetToPhysicalPhysAddress_oid)
}
}
}
if (!strstr($oid_data, 'ipv4'))
if (!str_contains($oid_data, 'ipv4'))
{
// Check IP-MIB::ipNetToMediaPhysAddress (IPv4 only)
//ipNetToMediaPhysAddress[213][10.0.0.162] 70:81:5:ec:f9:bf
@ -179,7 +179,7 @@ foreach ($cache_arp as $entry)
}
if (count($remove_mac_ids))
{
dbDelete('ip_mac', '1' . generate_query_values($remove_mac_ids, 'mac_id'));
dbDelete('ip_mac', generate_query_values_ng($remove_mac_ids, 'mac_id'));
}
echo(PHP_EOL);

View File

@ -208,7 +208,7 @@ if (safe_count($peerlist)) {
echo(PHP_EOL);
// Filter IP search by BGP enabled devices (without self)
$bgp_device_ids = dbFetchColumn('SELECT `device_id` FROM `devices` WHERE `device_id` != ? AND `bgpLocalAs` > 0 AND `disabled` = 0 AND `status` = 1', [ $device['device_id'] ]);
$peer_as_where = generate_query_values($bgp_device_ids, 'device_id');
$peer_as_where = generate_query_values_and($bgp_device_ids, 'device_id');
$peer_devices = [];
$peer_devices_ids = [];
@ -218,7 +218,7 @@ if (safe_count($peerlist)) {
}
print_debug_vars($peer_devices);
$peer_ip_where = generate_query_values($peer_devices_ids, 'device_id') . generate_query_values('up', 'ifOperStatus');
$peer_ip_where = generate_query_values_and($peer_devices_ids, 'device_id') . generate_query_values_and('up', 'ifOperStatus');
foreach ($peerlist as $peer) {
@ -371,7 +371,7 @@ if (safe_count($peerlist)) {
} # AF list
if (safe_count($cbgp_delete)) {
// Multi-delete
dbDelete('bgpPeers_cbgp', generate_query_values($cbgp_delete, 'cbgp_id', NULL, FALSE));
dbDelete('bgpPeers_cbgp', generate_query_values_ng($cbgp_delete, 'cbgp_id'));
}
unset($af_list, $cbgp_delete);
} # end peerlist
@ -395,8 +395,8 @@ foreach (dbFetchRows($query, [ $device['device_id'] ]) as $entry) {
}
if (count($peers_delete)) {
// Multi-delete
dbDelete('bgpPeers', generate_query_values($peers_delete, 'bgpPeer_id', NULL, FALSE));
dbDelete('bgpPeers_cbgp', generate_query_values($peers_delete, 'bgpPeer_id', NULL, FALSE));
dbDelete('bgpPeers', generate_query_values_ng($peers_delete, 'bgpPeer_id'));
dbDelete('bgpPeers_cbgp', generate_query_values_ng($peers_delete, 'bgpPeer_id'));
}
$table_headers = array('%WLocal: AS (VRF)%n', '%WIP%n', '%WPeer: AS%n', '%WIP%n', '%WFamily%n', '%WrDNS%n', '%WRemote Device%n');

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -28,20 +27,22 @@ $mib = 'Printer-MIB';
//Printer-MIB::prtMarkerEastMargin.1.1 = INTEGER: 1968
//Printer-MIB::prtMarkerStatus.1.1 = INTEGER: 2
$oids = snmpwalk_cache_oid($device, "prtMarkerEntry", array(), $mib);
$prt_supplies = snmpwalk_cache_oid($device, 'prtMarkerSuppliesDescription', array(), $mib, NULL, OBS_SNMP_ALL_ASCII);
$oids = snmpwalk_cache_oid($device, "prtMarkerEntry", [], $mib);
$prt_supplies = snmpwalk_cache_oid($device, 'prtMarkerSuppliesDescription', [], $mib, NULL, OBS_SNMP_ALL_ASCII);
//print_vars($oids);
$count = count($oids);
$total_printed_allow = TRUE;
//$count = count($oids);
//$total_printed_allow = TRUE;
$total_printed_allow = !discovery_check_if_type_exist([ 'printersupply->KYOCERA-MIB->kcprtMarkerServiceCount' ], 'counter');
foreach ($oids as $index => $entry)
{
$printer_supply = dbFetchRow("SELECT * FROM `printersupplies` WHERE `device_id` = ? AND `supply_mib` = ? AND `supply_index` = ?", array($device['device_id'], 'jetdirect', $index));
foreach ($oids as $index => $entry) {
$printer_supply = dbFetchRow("SELECT * FROM `printersupplies` WHERE `device_id` = ? AND `supply_mib` = ? AND `supply_index` = ?", [ $device['device_id'], 'jetdirect', $index ]);
$marker_descr = "Printed ".nicecase($entry['prtMarkerCounterUnit']);
list($hrDeviceIndex, $prtMarkerIndex) = explode('.', $index);
$options = array('measured_class' => 'printersupply',
'measured_entity' => $printer_supply['supply_id'],
'counter_unit' => $entry['prtMarkerCounterUnit']);
$options = [
'measured_class' => 'printersupply',
'measured_entity' => $printer_supply['supply_id'],
'counter_unit' => $entry['prtMarkerCounterUnit']
];
// Lifetime counter (should be always single)
$descr = "Total $marker_descr";
@ -49,16 +50,14 @@ foreach ($oids as $index => $entry)
$oid = '.1.3.6.1.2.1.43.10.2.1.4.' . $index;
$value = $entry[$oid_name];
if (isset($entry[$oid_name]) && $total_printed_allow)
{
if (isset($entry[$oid_name]) && $total_printed_allow) {
discover_counter($device, 'printersupply', $mib, $oid_name, $oid, $index, $descr, 1, $value, $options);
$total_printed_allow = FALSE; // Discover only first "Total Printed", all other always same
}
// PowerOn counter
$descr = "PowerOn $marker_descr";
if ($prt_supplies[$index]['prtMarkerSuppliesDescription'])
{
if ($prt_supplies[$index]['prtMarkerSuppliesDescription']) {
$descr .= ' - ' . rewrite_entity_name(snmp_hexstring($prt_supplies[$index]['prtMarkerSuppliesDescription']));
}
$oid_name = 'prtMarkerPowerOnCount';

View File

@ -753,7 +753,7 @@ function get_autodiscovery_device_id($device, $hostname, $ip = NULL, $mac = NULL
if (!$remote_device_id && $ip_type && !in_array($ip_type, [ 'unspecified', 'loopback' ])) { // 'link-local' ?
//$remote_device_id = dbFetchCell("SELECT `device_id` FROM `ports` LEFT JOIN `ipv4_addresses` on `ports`.`port_id`=`ipv4_addresses`.`port_id` WHERE `deleted` = '0' AND `ipv4_address` = ? LIMIT 1;", array($entry['mtxrNeighborIpAddress']));
$peer_where = generate_query_values($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
$peer_where = generate_query_values_and($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('device', $ip, $peer_where)) {
$remote_device_id = $ids[0];
@ -1385,7 +1385,13 @@ function discover_neighbour($port, $protocol, $neighbour)
$neighbour['protocol'] = $protocol;
$neighbour['active'] = '1';
$params = array('protocol', 'remote_port_id', 'remote_hostname', 'remote_port', 'remote_platform', 'remote_version', 'remote_address', 'autodiscovery_id', 'active');
// Get the remote device id if we've not been told it
if(isset($neighbour['remote_port_id']) && !isset($neighbour['remote_device_id'])) {
$neighbour['remote_device_id'] = get_device_id_by_port_id($neighbour['remote_port_id']);
}
$params = array('protocol', 'remote_device_id', 'remote_port_id', 'remote_hostname', 'remote_port', 'remote_platform', 'remote_version', 'remote_address', 'autodiscovery_id', 'active');
$neighbour_db = dbFetchRow("SELECT `neighbours`.*, UNIX_TIMESTAMP(`last_change`) AS `last_change_unixtime` FROM `neighbours` WHERE `port_id` = ? AND `protocol` = ? AND `remote_hostname` = ? AND `remote_port` = ?", array($port['port_id'], $protocol, $neighbour['remote_hostname'], $neighbour['remote_port']));
if (!isset($neighbour_db['neighbour_id']))
{

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -51,26 +51,35 @@ if (is_device_mib($device, 'ELTEX-MES-PHYSICAL-DESCRIPTION-MIB')) {
$vendor_oids = snmpwalk_cache_oid($device, "swL2PortSfpInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'DGS-3420-28SC-L2MGMT-MIB')) {
$vendor_mib = 'DGS-3420-28SC-L2MGMT-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "swL2PortSfpInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'DGS-3420-26SC-L2MGMT-MIB')) {
$vendor_mib = 'DGS-3420-26SC-L2MGMT-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "swL2PortSfpInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'DGS-3620-28SC-L2MGMT-MIB')) {
$vendor_mib = 'DGS-3620-28SC-L2MGMT-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "swL2PortSfpInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'DGS-3620-26SC-L2MGMT-MIB')) {
$vendor_mib = 'DGS-3620-26SC-L2MGMT-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "swL2PortSfpInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'DGS-3420-28SC-L2MGMT-MIB')) {
$vendor_mib = 'DGS-3420-28SC-L2MGMT-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "swL2PortSfpInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'DGS-3420-26SC-L2MGMT-MIB')) {
$vendor_mib = 'DGS-3420-26SC-L2MGMT-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "swL2PortSfpInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'DGS-3620-28SC-L2MGMT-MIB')) {
$vendor_mib = 'DGS-3620-28SC-L2MGMT-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "swL2PortSfpInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'DGS-3620-26SC-L2MGMT-MIB')) {
$vendor_mib = 'DGS-3620-26SC-L2MGMT-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "swL2PortSfpInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'HUAWEI-ENTITY-EXTENT-MIB') &&
$vendor_oids = snmpwalk_cache_oid($device, "hwEntityOpticalVendorSn", $vendor_oids, 'HUAWEI-ENTITY-EXTENT-MIB', NULL, $snmp_flags)) {
$vendor_mib = 'HUAWEI-ENTITY-EXTENT-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "hwEntityOpticalType", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
$vendor_oids = snmpwalk_cache_oid($device, "hwEntityOpticalVenderName", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
$vendor_oids = snmpwalk_cache_oid($device, "hwEntityOpticalVenderPn", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
$vendor_oids = snmpwalk_cache_oid($device, "hwEntityOpticalTransType", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
}
foreach ($entity_array as $entPhysicalIndex => $entry) {
@ -198,6 +207,27 @@ foreach ($entity_array as $entPhysicalIndex => $entry) {
$entry['entPhysicalSerialNum'] = trim($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoVendorSN']);
$entry['entPhysicalMfgName'] = trim($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoVendorName']);
$entry['entPhysicalModelName'] = trim($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoFiberType']);
} elseif ($vendor_mib === 'HUAWEI-ENTITY-EXTENT-MIB' && isset($vendor_oids[$entPhysicalIndex]) &&
$vendor_oids[$entPhysicalIndex]['hwEntityOpticalType'] !== 'unknown') {
//$entry = array_merge($entry, $vendor_oids[$entry['ifIndex']]);
print_debug_vars($vendor_oids[$entPhysicalIndex]);
// entPhysicalVendorType -> hwEntityOpticalType
// entPhysicalHardwareRev -> ??
// entPhysicalFirmwareRev -> ??
// entPhysicalSoftwareRev -> ??
// entPhysicalSerialNum -> hwEntityOpticalVendorSn
// entPhysicalMfgName -> hwEntityOpticalVenderName
// entPhysicalModelName -> hwEntityOpticalVenderPn
// entPhysicalAlias -> hwEntityOpticalTransType
// entPhysicalAssetID -> ??
$entry['entPhysicalVendorType'] = trim($vendor_oids[$entPhysicalIndex]['hwEntityOpticalType']);
//$entry['entPhysicalHardwareRev'] = trim($vendor_oids[$entPhysicalIndex]['']);
//$entry['entPhysicalFirmwareRev'] = trim($vendor_oids[$entPhysicalIndex]['']);
$entry['entPhysicalSerialNum'] = trim($vendor_oids[$entPhysicalIndex]['hwEntityOpticalVendorSn']);
$entry['entPhysicalMfgName'] = trim($vendor_oids[$entPhysicalIndex]['hwEntityOpticalVenderName']);
$entry['entPhysicalModelName'] = trim($vendor_oids[$entPhysicalIndex]['hwEntityOpticalVenderPn']);
$entry['entPhysicalAlias'] = trim($vendor_oids[$entPhysicalIndex]['hwEntityOpticalTransType']);
}
if ($entry['entPhysicalDescr'] || $entry['entPhysicalName']) {

View File

@ -33,21 +33,23 @@ if (is_array($hrDevices)) {
print_debug_vars($hrDevice, 1);
continue;
}
if (!is_numeric($hrDevice['hrDeviceErrors'])) {
$hrDevice['hrDeviceErrors'] = 0;
}
//if (dbFetchCell("SELECT COUNT(*) FROM `hrDevice` WHERE device_id = ? AND hrDeviceIndex = ?",array($device['device_id'], $hrDevice['hrDeviceIndex'])))
if (dbExist('hrDevice', '`device_id` = ? AND `hrDeviceIndex` = ?', array($device['device_id'], $hrDevice['hrDeviceIndex'])))
{
if (($hrDevice['hrDeviceType'] === "hrDeviceProcessor") && empty($hrDevice['hrDeviceDescr']))
{
if (dbExist('hrDevice', '`device_id` = ? AND `hrDeviceIndex` = ?', array($device['device_id'], $hrDevice['hrDeviceIndex']))) {
if (($hrDevice['hrDeviceType'] === "hrDeviceProcessor") && empty($hrDevice['hrDeviceDescr'])) {
$hrDevice['hrDeviceDescr'] = "Processor";
}
$update_array = array('hrDeviceType' => $hrDevice['hrDeviceType'],
'hrDeviceDescr' => $hrDevice['hrDeviceDescr'],
'hrDeviceStatus' => $hrDevice['hrDeviceStatus'],
'hrDeviceErrors' => $hrDevice['hrDeviceErrors']);
$update_array = [
'hrDeviceType' => $hrDevice['hrDeviceType'],
'hrDeviceDescr' => $hrDevice['hrDeviceDescr'],
'hrDeviceStatus' => $hrDevice['hrDeviceStatus'],
'hrDeviceErrors' => $hrDevice['hrDeviceErrors']
];
if ($hrDevice['hrDeviceType'] === "hrDeviceProcessor")
{
if ($hrDevice['hrDeviceType'] === "hrDeviceProcessor") {
$update_array['hrProcessorLoad'] = $hrDevice['hrProcessorLoad'];
} else {
$update_array['hrProcessorLoad'] = array('NULL');

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -96,7 +96,7 @@ if ($amap_array)
$remote_port_id = get_port_id_by_mac($remote_device_id, $remote_mac);
} else {
// Try by IP
$peer_where = generate_query_values($remote_device_id, 'device_id'); // Additional filter for include self IPs
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where))
{

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -151,6 +151,12 @@ if ($cdp_array) {
if (!is_null($if)) {
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($if, $if, $if, $remote_device_id, 0));
// Aruba devices can report ifAlias instead ifDescr
if (!$remote_port_id && !isHexString($if)) {
$query = 'SELECT `port_id` FROM `ports` WHERE `ifAlias` = ? AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [ $if, $remote_device_id, 0 ]);
}
}
if (!$remote_port_id) {
if (!is_null($remote_mac)) {
@ -164,7 +170,7 @@ if ($cdp_array) {
if (!$remote_port_id) {
// Try by IP
$peer_where = generate_query_values($remote_device_id, 'device_id'); // Additional filter for include self IPs
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where))
{

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -45,7 +45,7 @@ if ($fdp_array)
if (!$remote_port_id)
{
// Try by IP
$peer_where = generate_query_values($remote_device_id, 'device_id'); // Additional filter for include self IPs
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where))
{

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -66,7 +66,7 @@ if ($isdp_array) {
if (!$remote_port_id)
{
// Try by IP
$peer_where = generate_query_values($remote_device_id, 'device_id'); // Additional filter for include self IPs
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where))
{

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -206,7 +206,7 @@ if ($lldp_array) {
}
unset($id, $ip);
*/
$peer_where = generate_query_values($device['device_id'], 'device_id'); // Additional filter for include self IPs
$peer_where = generate_query_values_and($device['device_id'], 'device_id'); // Additional filter for include self IPs
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $ip, $peer_where)) {
$port = get_port_by_id_cache($ids[0]);
@ -344,8 +344,7 @@ if ($lldp_array) {
// Try lldpRemPortId
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($id, $id, $id, $remote_device_id, 0));
if (!$remote_port_id && strlen($if))
{
if (!$remote_port_id && !safe_empty($if)) {
// Try same by lldpRemPortDesc
$remote_port_id = dbFetchCell($query, array($if, $if, $if, $remote_device_id, 0));
}
@ -353,6 +352,11 @@ if ($lldp_array) {
case 'macAddress':
$remote_port_id = get_port_id_by_mac($remote_device_id, $id);
if (!$remote_port_id && !safe_empty($if)) {
// Try same by lldpRemPortDesc
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [ $if, $if, $if, $remote_device_id, 0 ]);
}
break;
case 'networkAddress':
@ -360,7 +364,7 @@ if ($lldp_array) {
if ($ip_version)
{
// Try by IP
$peer_where = generate_query_values($remote_device_id, 'device_id'); // Additional filter for include self IPs
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $id, $peer_where))
{

View File

@ -6,12 +6,11 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
if (!$config['autodiscovery']['ospf'])
{
if (!$config['autodiscovery']['ospf']) {
print_debug("Autodiscovery for OSPF disabled.");
return;
}
@ -45,23 +44,20 @@ if (!$config['autodiscovery']['ospf'])
// OSPF-MIB::ospfNbmaNbrStatus[103.52.56.4][0] = INTEGER: active(1)
$ospf_array = snmpwalk_cache_twopart_oid($device, 'ospfNbmaNbrStatus', [], 'OSPF-MIB', NULL, OBS_SNMP_ALL_TABLE);
if (snmp_status())
{
if (snmp_status()) {
$ospf_array = snmpwalk_cache_twopart_oid($device, 'ospfNbrRtrId', $ospf_array, 'OSPF-MIB', NULL, OBS_SNMP_ALL_TABLE);
print_debug_vars($ospf_array);
foreach ($ospf_array as $ip => $entry)
{
foreach ($ospf_array as $ip => $entry) {
if ($ip === '0.0.0.0') { continue; }
foreach ($entry as $if => $ospf)
{
foreach ($entry as $if => $ospf) {
if ($ospf['ospfNbmaNbrStatus'] !== 'active' || $ospf['ospfNbrRtrId'] === '0.0.0.0') { continue; }
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $ospf['ospfNbrRtrId']);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($ospf['ospfNbrRtrId'])) // Check all previous autodiscovery rounds
{
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($ospf['ospfNbrRtrId'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($ospf['ospfNbrRtrId'], NULL, 'OSPF', NULL, $device);
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
if (!$config['autodiscovery']['ospf']) {
print_debug("Autodiscovery for OSPF disabled.");
return;
}
// OSPFV3-MIB::ospfv3NbrAddressType.4.0.3110374402 = INTEGER: ipv6(2)
// OSPFV3-MIB::ospfv3NbrAddressType.4.0.3110374403 = INTEGER: ipv6(2)
// OSPFV3-MIB::ospfv3NbrAddress.4.0.3110374402 = Hex-STRING: FE 80 00 00 00 00 00 00 02 25 90 FF FE E5 63 D0
// OSPFV3-MIB::ospfv3NbrAddress.4.0.3110374403 = Hex-STRING: FE 80 00 00 00 00 00 00 02 25 90 FF FE E3 DF 1A
// OSPFV3-MIB::ospfv3NbrOptions.4.0.3110374402 = INTEGER: 19
// OSPFV3-MIB::ospfv3NbrOptions.4.0.3110374403 = INTEGER: 19
// OSPFV3-MIB::ospfv3NbrPriority.4.0.3110374402 = INTEGER: 10
// OSPFV3-MIB::ospfv3NbrPriority.4.0.3110374403 = INTEGER: 10
// OSPFV3-MIB::ospfv3NbrState.4.0.3110374402 = INTEGER: full(8)
// OSPFV3-MIB::ospfv3NbrState.4.0.3110374403 = INTEGER: full(8)
// OSPFV3-MIB::ospfv3NbrEvents.4.0.3110374402 = Counter32: 6
// OSPFV3-MIB::ospfv3NbrEvents.4.0.3110374403 = Counter32: 6
// OSPFV3-MIB::ospfv3NbrLsRetransQLen.4.0.3110374402 = Gauge32: 0
// OSPFV3-MIB::ospfv3NbrLsRetransQLen.4.0.3110374403 = Gauge32: 0
// OSPFV3-MIB::ospfv3NbrHelloSuppressed.4.0.3110374402 = INTEGER: false(2)
// OSPFV3-MIB::ospfv3NbrHelloSuppressed.4.0.3110374403 = INTEGER: false(2)
// OSPFV3-MIB::ospfv3NbrIfId.4.0.3110374402 = INTEGER: 4
// OSPFV3-MIB::ospfv3NbrIfId.4.0.3110374403 = INTEGER: 3
$ospf_array = snmpwalk_cache_oid($device, 'ospfv3NbrAddress', [], 'OSPFV3-MIB', NULL, OBS_SNMP_ALL_HEX);
if (snmp_status()) {
$ospf_array = snmpwalk_cache_oid($device, 'ospfv3NbrIfId', $ospf_array, 'OSPFV3-MIB');
print_debug_vars($ospf_array);
foreach ($ospf_array as $index => $entry) {
$ip = hex2ip($entry['ospfv3NbrAddress']);
$ip_compressed = ip_compress($ip);
if ($ip_compressed === '::') { continue; }
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $ip);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($ip)) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$port = get_port_by_index_cache($device, $entry['ospfv3NbrIfId']);
$remote_device_id = autodiscovery_device($ip, NULL, 'OSPF', NULL, $device, $port);
}
}
}
// EOF

View File

@ -33,7 +33,7 @@ $oids_db = dbFetchRows("SELECT * FROM `oids` WHERE `oid_autodiscover` = '1'");
foreach($oids_db as $oid)
{
$value = snmp_get($device, $oid['oid'], "-OUQnv");
$value = snmp_get($device, $oid['oid'], "-OUQtnv");
if (is_numeric($value) && $value != '4294967295' && $value != '2147483647' && $value != '-2147483647') // Don't discover stuff which is returning min/max 32 bit values
{
if(!isset($entries[$oid['oid_id']]))

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -16,10 +15,9 @@
if ($os) { return; }
if (str_contains_array($sysDescr, 'FreeBSD') ||
str_starts($sysObjectID, array('.1.3.6.1.4.1.8072.3.2.8', // NET-SNMP
'.1.3.6.1.4.1.12325.1.1.2.1'))) // BSNMP daemon
{
if (str_contains($sysDescr, 'FreeBSD') ||
str_starts($sysObjectID, [ '.1.3.6.1.4.1.8072.3.2.8', // NET-SNMP
'.1.3.6.1.4.1.12325.1.1.2.1' ])) { // BSNMP daemon
$os = 'freebsd';
}

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -14,31 +14,45 @@
// FIXME. Need rename db schema port_id_high -> port_ifIndex_high, port_id_low -> port_ifIndex_low
$query = 'SELECT * FROM `ports_stack` WHERE `device_id` = ?';
$stack_db_array = [];
foreach (dbFetchRows($query, array($device['device_id'])) as $entry) {
$stack_db_array[$entry['port_id_high']][$entry['port_id_low']] = $entry;
}
$ifmib_stack = FALSE;
$insert_array = [];
if (is_device_mib($device, 'IF-MIB')) {
$stack_poll_array = snmpwalk_cache_twopart_oid($device, 'ifStackStatus', array(), 'IF-MIB');
$stack_poll_array = snmpwalk_cache_twopart_oid($device, 'ifStackStatus', [], 'IF-MIB');
foreach ($stack_poll_array as $port_ifIndex_high => $entry_high) {
if (is_numeric($port_ifIndex_high)) {
$port_high = get_port_by_index_cache($device, $port_ifIndex_high);
if ($device['os'] === 'ciscosb' && $port_high['ifType'] === 'propVirtual') {
// Skip stacking on Vlan ports (Cisco SB)
continue;
if ($device['os'] === 'ciscosb') {
$port_high = get_port_by_index_cache($device, $port_ifIndex_high); // Limit port queries to specific os(es)
if ($port_high['ifType'] === 'propVirtual') {
// Skip stacking on Vlan ports (Cisco SB)
continue;
}
}
foreach ($entry_high as $port_ifIndex_low => $entry_low) {
if (is_numeric($port_ifIndex_low)) {
$port_low = get_port_by_index_cache($device, $port_ifIndex_low);
if ($device['os'] === 'ciscosb' && $port_low['ifType'] === 'propVirtual') {
// Skip stacking on Vlan ports (Cisco SB)
if ($device['os'] === 'ciscosb') {
$port_low = get_port_by_index_cache($device, $port_ifIndex_low); // Limit port queries to specific os(es)
if ($port_low['ifType'] === 'propVirtual') {
// Skip stacking on Vlan ports (Cisco SB)
continue;
}
}
$ifStackStatus = $entry_low['ifStackStatus'];
//if ($ifStackStatus === 'notInService') { continue; } // FIXME. Skip inactive entries
if ($ifStackStatus === 'notInService' && ($port_ifIndex_low == 0 || $port_ifIndex_high == 0)) {
print_debug("Skipped inactive stack entry: high [$port_ifIndex_high] & low [$port_ifIndex_low], ifStackStatus [$ifStackStatus].");
continue;
}
$ifStackStatus = $entry_low['ifStackStatus'];
//if ($ifStackStatus !== 'active') { continue; } // Skip inactive entries
// Set stacks found by IF-MIB
$ifmib_stack = TRUE;
// Store valid for others
$valid[$module][$port_ifIndex_high][$port_ifIndex_low] = $ifStackStatus;
@ -48,8 +62,8 @@ if (is_device_mib($device, 'IF-MIB')) {
//echo('.');
$GLOBALS['module_stats'][$module]['unchanged']++;
} else {
$update_array = array( 'ifStackStatus' => $ifStackStatus );
dbUpdate($update_array, 'ports_stack', '`port_stack_id` = ?', array( $entry_low['port_stack_id'] ));
$update_array = [ 'ifStackStatus' => $ifStackStatus ];
dbUpdate($update_array, 'ports_stack', '`port_stack_id` = ?', [ $entry_low['port_stack_id'] ]);
//echo('U');
$GLOBALS['module_stats'][$module]['updated']++;
}
@ -60,10 +74,12 @@ if (is_device_mib($device, 'IF-MIB')) {
// 'port_id_low' => $port_ifIndex_low,
// 'ifStackStatus' => $ifStackStatus);
//dbInsert($update_array, 'ports_stack');
$insert_array[] = [ 'device_id' => $device['device_id'],
'port_id_high' => $port_ifIndex_high,
'port_id_low' => $port_ifIndex_low,
'ifStackStatus' => $ifStackStatus ];
$insert_array[] = [
'device_id' => $device['device_id'],
'port_id_high' => $port_ifIndex_high,
'port_id_low' => $port_ifIndex_low,
'ifStackStatus' => $ifStackStatus
];
$GLOBALS['module_stats'][$module]['added']++;
//echo('+');
}
@ -73,6 +89,70 @@ if (is_device_mib($device, 'IF-MIB')) {
}
}
if (!$ifmib_stack && is_device_mib($device, 'IEEE8023-LAG-MIB') &&
$stack_list_ports = snmpwalk_cache_oid($device, 'dot3adAggPortListPorts', [], 'IEEE8023-LAG-MIB')) {
// ifDescr.51 = 1/1/51
// ifDescr.52 = 1/1/52
// ifDescr.769 = lag1
// IEEE8023-LAG-MIB::dot3adAggPortListPorts.769 = STRING: "1/1/51,1/1/52"
// IEEE8023-LAG-MIB::dot3adAggPortSelectedAggID.51 = INTEGER: 769
// IEEE8023-LAG-MIB::dot3adAggPortSelectedAggID.52 = INTEGER: 769
// IEEE8023-LAG-MIB::dot3adAggPortAttachedAggID.51 = INTEGER: 769
// IEEE8023-LAG-MIB::dot3adAggPortAttachedAggID.52 = INTEGER: 769
$stack_agg_ports = snmpwalk_cache_oid($device, 'dot3adAggPortSelectedAggID', [], 'IEEE8023-LAG-MIB');
$stack_agg_ports = snmpwalk_cache_oid($device, 'dot3adAggPortAttachedAggID', $stack_agg_ports, 'IEEE8023-LAG-MIB');
$stack_agg_ports = snmpwalk_cache_oid($device, 'dot3adAggPortAggregateOrIndividual', $stack_agg_ports, 'IEEE8023-LAG-MIB');
// IEEE8023-LAG-MIB::dot3adAggPortActorAdminState.1000009 = BITS: E0 lacpActivity(0) lacpTimeout(1) aggregation(2)
// IEEE8023-LAG-MIB::dot3adAggPortActorAdminState.1000010 = BITS: E0 lacpActivity(0) lacpTimeout(1) aggregation(2)
$stack_agg_ports = snmpwalk_cache_oid($device, 'dot3adAggPortActorAdminState', $stack_agg_ports, 'IEEE8023-LAG-MIB', NULL, OBS_SNMP_ALL_HEX);
print_debug_vars($stack_agg_ports);
foreach ($stack_agg_ports as $port_ifIndex_low => $entry_low) {
$entry_low['admin_bits'] = get_bits_state_array($entry_low['dot3adAggPortActorAdminState'], 'IEEE8023-LAG-MIB', 'LacpState');
print_debug_vars($entry_low);
$port_ifIndex_high = $entry_low['dot3adAggPortAttachedAggID'];
$ifStackStatus = 'active'; // always active
if ($entry_low['dot3adAggPortAggregateOrIndividual'] === 'false' || !in_array('aggregation', (array)$entry_low['admin_bits'], TRUE)) {
// Skip not aggregate ports
print_debug("Skipped inactive stack entry: high [$port_ifIndex_high] & low [$port_ifIndex_low], dot3adAggPortAggregateOrIndividual [{$entry_low['dot3adAggPortAggregateOrIndividual']}].");
continue;
}
// Store valid for others
$valid[$module][$port_ifIndex_high][$port_ifIndex_low] = $ifStackStatus;
if (isset($stack_db_array[$port_ifIndex_high][$port_ifIndex_low])) {
if ($stack_db_array[$port_ifIndex_high][$port_ifIndex_low]['ifStackStatus'] == $ifStackStatus) {
//echo('.');
$GLOBALS['module_stats'][$module]['unchanged']++;
} else {
$update_array = [ 'ifStackStatus' => $ifStackStatus ];
dbUpdate($update_array, 'ports_stack', '`port_stack_id` = ?', [ $entry_low['port_stack_id'] ]);
//echo('U');
$GLOBALS['module_stats'][$module]['updated']++;
}
unset($stack_db_array[$port_ifIndex_high][$port_ifIndex_low]);
} else {
// $update_array = array('device_id' => $device['device_id'],
// 'port_id_high' => $port_ifIndex_high,
// 'port_id_low' => $port_ifIndex_low,
// 'ifStackStatus' => $ifStackStatus);
//dbInsert($update_array, 'ports_stack');
$insert_array[] = [
'device_id' => $device['device_id'],
'port_id_high' => $port_ifIndex_high,
'port_id_low' => $port_ifIndex_low,
'ifStackStatus' => $ifStackStatus
];
$GLOBALS['module_stats'][$module]['added']++;
//echo('+');
}
}
}
/*
if (OBS_DEBUG && is_device_mib($device, 'HUAWEI-IF-EXT-MIB')) {
$tmp = snmpwalk_cache_twopart_oid($device, 'hwTrunkMemEntry', [], 'HUAWEI-IF-EXT-MIB');
@ -130,10 +210,12 @@ if (is_device_mib($device, 'HUAWEI-IF-EXT-MIB')) {
}
unset($stack_db_array[$port_ifIndex_high][$port_ifIndex_low]);
} else {
$insert_array[] = [ 'device_id' => $device['device_id'],
'port_id_high' => $port_ifIndex_high,
'port_id_low' => $port_ifIndex_low,
'ifStackStatus' => $ifStackStatus ];
$insert_array[] = [
'device_id' => $device['device_id'],
'port_id_high' => $port_ifIndex_high,
'port_id_low' => $port_ifIndex_low,
'ifStackStatus' => $ifStackStatus
];
$GLOBALS['module_stats'][$module]['added']++;
}
}
@ -159,7 +241,7 @@ foreach ($stack_db_array as $port_ifIndex_high => $array) {
// MultiDelete old entries
if (count($delete_array)) {
print_debug_vars($delete_array);
dbDelete('ports_stack', generate_query_values($delete_array, 'port_stack_id', NULL, FALSE));
dbDelete('ports_stack', generate_query_values_ng($delete_array, 'port_stack_id'));
}
unset($insert_array, $update_array, $delete_array);

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -209,7 +209,7 @@ foreach ($ports_ids as $port_id => $port)
// Complete remove duplicates
if (count($ports_duplicates_ids))
{
dbDelete('ports', generate_query_values($ports_duplicates_ids, 'port_id', NULL, FALSE));
dbDelete('ports', generate_query_values_ng($ports_duplicates_ids, 'port_id'));
}
// End interfaces clean
echo(PHP_EOL);

View File

@ -0,0 +1,129 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
*
*/
/*
.1.3.6.1.4.1.42229.1.2.4.1.9 - eth100gTable for a single port (1/1/6)
CORIANT-GROOVE-MIB::eth100gEthFecType.1.1.0.6.0 = INTEGER: auto(3)
CORIANT-GROOVE-MIB::eth100gEthFecTypeState.1.1.0.6.0 = INTEGER: disabled(2)
CORIANT-GROOVE-MIB::eth100gTransmitInterpacketgap.1.1.0.6.0 = Gauge32: 8
CORIANT-GROOVE-MIB::eth100gGfpPayloadFcs.1.1.0.6.0 = INTEGER: disabled(2)
CORIANT-GROOVE-MIB::eth100gMappingMode.1.1.0.6.0 = INTEGER: gmp(1)
CORIANT-GROOVE-MIB::eth100gAdminStatus.1.1.0.6.0 = INTEGER: up(1)
CORIANT-GROOVE-MIB::eth100gOperStatus.1.1.0.6.0 = INTEGER: down(2)
CORIANT-GROOVE-MIB::eth100gAvailStatus.1.1.0.6.0 = BITS: 10 00 00 00 lowerLayerDown(3)
CORIANT-GROOVE-MIB::eth100gAliasName.1.1.0.6.0 = STRING: "100gbe-1/1/6"
CORIANT-GROOVE-MIB::eth100gClientShutdown.1.1.0.6.0 = INTEGER: no(2)
CORIANT-GROOVE-MIB::eth100gClientShutdownHoldoffTimer.1.1.0.6.0 = Gauge32: 0
CORIANT-GROOVE-MIB::eth100gNearEndAls.1.1.0.6.0 = INTEGER: no(2)
CORIANT-GROOVE-MIB::eth100gAlsDegradeMode.1.1.0.6.0 = INTEGER: disabled(2)
CORIANT-GROOVE-MIB::eth100gLoopbackEnable.1.1.0.6.0 = INTEGER: disabled(2)
CORIANT-GROOVE-MIB::eth100gLoopbackType.1.1.0.6.0 = INTEGER: none(0)
CORIANT-GROOVE-MIB::eth100gTestSignalType.1.1.0.6.0 = INTEGER: none(0)
CORIANT-GROOVE-MIB::eth100gTestSignalEnable.1.1.0.6.0 = INTEGER: none(0)
CORIANT-GROOVE-MIB::eth100gServiceLabel.1.1.0.6.0 = ""
CORIANT-GROOVE-MIB::eth100gLldpStatusIf.1.1.0.6.0 = INTEGER: disabled(4)
CORIANT-GROOVE-MIB::eth100gHoldoffSignal.1.1.0.6.0 = INTEGER: no(2)
CORIANT-GROOVE-MIB::eth100gManagedBy.1.1.0.6.0 = INTEGER: system(1)
.1.3.6.1.4.1.42229.1.2.4.1.9 - eth100gStatisticsTable for a single port (1/1/6)
CORIANT-GROOVE-MIB::eth100gStatisticsEntryLastClear.1.1.0.6.0 = STRING: "0000-01-01T00:00:00.000Z"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryLossOfSignalSeconds.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryBitErrorFec.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryUncorrectedBlockErrorFec.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInSymbolErrors.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInDropEvents.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInOctets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInBroadcastPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInMulticastPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInCrcAlignErrors.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInUndersizePackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInOversizePackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInFragments.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInJabbers.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets64octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets65to127octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets128to255octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets256to511octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets512to1023octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets1024to1518octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutSymbolErrors.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutDropEvents.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutOctets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutBroadcastPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutMulticastPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutCrcAlignErrors.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutUndersizePackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutOversizePackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutFragments.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutJabbers.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets64octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets65to127octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets128to255octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets256to511octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets512to1023octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets1024to1518octets.1.1.0.6.0 = STRING: "0"
*/
$mib = 'CORIANT-GROOVE-MIB';
// this is eth100g only, note that fc8gTable, fc16gTable, eth10gTable, eth40gTable, eth400gtable all exist too!
//eth100gTable
$entries = [];
$entries = snmpwalk_cache_oid($device, 'eth100gTable', $entries, $mib);
print_debug_vars($entries);
foreach ($entries as $port_oid_suffix => $port) {
$ifIndex = $port_oid_suffix;
// basics
$port_stats[$ifIndex]['ifDescr'] = $port['eth100gAliasName'];
$port_stats[$ifIndex]['ifName'] = $port['eth100gAliasName'];
$port_stats[$ifIndex]['ifAlias'] = $port['eth100gServiceLabel'];
$port_stats[$ifIndex]['ifOperStatus'] = $port['eth100gOperStatus'];
$port_stats[$ifIndex]['ifAdminStatus'] = $port['eth100gAdminStatus'];
$port_stats[$ifIndex]['ifType'] = 'ethernetCsmacd'; // can we do better than hard coding?
}
// eth400gtable
$entries = [];
$entries = snmpwalk_cache_oid($device, 'eth400gTable', $entries, $mib);
print_debug_vars($entries);
foreach ($entries as $port_oid_suffix => $port) {
$ifIndex = $port_oid_suffix;
// basics
$port_stats[$ifIndex]['ifDescr'] = $port['eth400gAliasName'];
$port_stats[$ifIndex]['ifName'] = $port['eth400gAliasName'];
$port_stats[$ifIndex]['ifAlias'] = $port['eth400gServiceLabel'];
$port_stats[$ifIndex]['ifOperStatus'] = $port['eth400gOperStatus'];
$port_stats[$ifIndex]['ifAdminStatus'] = $port['eth400gAdminStatus'];
$port_stats[$ifIndex]['ifType'] = 'ethernetCsmacd'; // can we do better than hard coding?
}
print_debug_vars($port_stats);
// EOF

View File

@ -12,8 +12,9 @@
$prt_supplies = snmpwalk_cache_oid($device, 'prtMarkerSuppliesTable', array(), 'Printer-MIB', NULL, OBS_SNMP_ALL_UTF8);
$prt_colorant = snmpwalk_cache_twopart_oid($device, 'prtMarkerColorantTable', array(), 'Printer-MIB', NULL, OBS_SNMP_ALL_UTF8);
//print_vars($prt_supplies);
//print_vars($prt_colorant);
print_debug_vars($prt_supplies);
print_debug_vars($prt_colorant);
// Count toner/ink, if Toner not has colorant table or name non informative (ie: TK-340) set to black for single toner
$toner_count = 0;

View File

@ -6,22 +6,22 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$hrDevice_oids = array('hrDevice', 'hrProcessorLoad');
$hrDevice_array = [];
foreach ($hrDevice_oids as $oid) {
$hrDevice_array = snmpwalk_cache_oid($device, $oid, $hrDevice_array, 'HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES');
}
$hr_array = snmpwalk_cache_oid($device, 'hrProcessorLoad', [], 'HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES');
$hr_count = safe_count($hr_array);
$hr_cpus = 0;
$hr_total = 0;
if ($hr_count) {
$hr_array = snmpwalk_cache_oid($device, 'hrDevice', $hr_array, 'HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES');
if (safe_count($hrDevice_array)) {
foreach ($hrDevice_array as $index => $entry) {
$hr_cpus = 0;
$hr_total = 0;
foreach ($hr_array as $index => $entry) {
if (!is_numeric($entry['hrProcessorLoad'])) { continue; }
if ($device['os'] === 'arista_eos' && $index == 1) { continue; }
if (!isset($entry['hrDeviceType'])) {
$entry['hrDeviceType'] = 'hrDeviceProcessor';
@ -38,40 +38,44 @@ if (safe_count($hrDevice_array)) {
$usage_oid = ".1.3.6.1.2.1.25.3.3.1.2.$index";
$usage = $entry['hrProcessorLoad'];
// What is this for? I have forgotten. What has : in its hrDeviceDescr?
// Set description to that found in hrDeviceDescr, first part only if containing a :
$descr_array = explode(':',$entry['hrDeviceDescr']);
if ($descr_array['1']) { $descr = $descr_array['1']; } else { $descr = $descr_array['0']; }
// Workaround to set fake description for Mikrotik and other who don't populate hrDeviceDescr
if (empty($entry['hrDeviceDescr'])) { $descr = 'Processor'; }
if (empty($entry['hrDeviceDescr'])) {
$descr = 'Processor';
if ($hr_count > 1) {
// Append processor index
$descr .= ' ' . ($index - 1);
}
} elseif (str_contains($entry['hrDeviceDescr'], ':')) {
// What is this for? I have forgotten. What has : in its hrDeviceDescr?
// Set description to that found in hrDeviceDescr, first part only if containing a :
list(, $descr) = explode(':', $entry['hrDeviceDescr']);
} else {
$descr = $entry['hrDeviceDescr'];
}
$descr = rewrite_entity_name($descr);
if ($device['os'] === 'arista_eos' && $index == 1) { continue; }
if ($descr !== 'An electronic chip that makes the computer work.') {
discover_processor($valid['processor'], $device, $usage_oid, $index, 'hr', $descr, 1, $usage, NULL, $hrDeviceIndex);
$hr_cpus++;
$hr_total += $usage;
}
unset($old_rrd,$new_rrd,$descr,$entry,$usage_oid,$index,$usage,$hrDeviceIndex,$descr_array);
unset($old_rrd, $new_rrd, $descr, $entry, $usage_oid, $index, $usage, $hrDeviceIndex);
}
unset($entry);
}
if ($hr_cpus) {
$hr_total = $hr_total / $hr_cpus;
discover_processor($valid['processor'], $device, 1, 1, 'hr-average', 'Average', 1, $usage);
discover_processor($valid['processor'], $device, 1, 1, 'hr-average', 'Average', 1, $hr_total / $hr_cpus);
//$ucd_count = @dbFetchCell("SELECT COUNT(*) FROM `processors` WHERE `device_id` = ? AND `processor_type` = 'ucd-old'", array($device['device_id']));
//if ($ucd_count)
if (dbExist('processors', '`device_id` = ? AND `processor_type` = ?', array($device['device_id'], 'ucd-old'))) {
if (dbExist('processors', '`device_id` = ? AND `processor_type` = ?', [ $device['device_id'], 'ucd-old' ])) {
$GLOBALS['module_stats']['processors']['deleted']++; //echo('-');
dbDelete('processors', "`device_id` = ? AND `processor_type` = ?", array($device['device_id'], 'ucd-old')); // Heh, this is because UCD-SNMP-MIB run earlier
dbDelete('processors', "`device_id` = ? AND `processor_type` = ?", [ $device['device_id'], 'ucd-old' ]); // Heh, this is because UCD-SNMP-MIB run earlier
}
}
unset($hrDevice_oids, $hrDevice_array, $oid);
unset($hr_array, $oid);
}
// EOF

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -37,7 +36,7 @@ $pws = snmpwalk_cache_oid($device, "cpwVcMplsLocalLdpID", $pws, "CISCO-IETF-PW-M
$pws = snmpwalk_cache_oid($device, "cpwVcMplsPeerLdpID", $pws, "CISCO-IETF-PW-MPLS-MIB");
//echo("PWS_WALK: ".count($pws)."\n"); var_dump($pws);
$peer_where = generate_query_values($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
$peer_where = generate_query_values_and($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
foreach ($pws as $pw_id => $pw)
{
$peer_addr = hex2ip($pw['cpwVcPeerAddr']);
@ -96,7 +95,7 @@ $pws = snmpwalk_cache_oid($device, "cpwVcMplsPeerLdpID", $pws, "CISCO-IETF-PW-M
// cpwVcName.3221225473 = STRING: 82.209.169.153,3055
// cpwVcMplsLocalLdpID.3221225473 = STRING: 82.209.169.129:0
list($local_addr) = explode(':', $pw['cpwVcMplsLocalLdpID']);
$local_where = generate_query_values($device['device_id'], 'device_id'); // Filter by self IPs
$local_where = generate_query_values_and($device['device_id'], 'device_id'); // Filter by self IPs
if ($ids = get_entity_ids_ip_by_network('port', $local_addr, $local_where))
{
$if_id = $ids[0];

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -34,7 +33,7 @@ if ($GLOBALS['snmp_status'] === FALSE)
echo('PWS_WALK: '.count($pws)."\n"); print_vars($pws);
}
$peer_where = generate_query_values($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
$peer_where = generate_query_values_and($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
foreach ($pws as $pw_type => $entry)
{
foreach ($entry as $pw_name => $entry2)

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -33,7 +32,7 @@ $pws = snmpwalk_cache_oid($device, "pwMplsLocalLdpID", $pws, "PW-MPLS-STD-MIB");
$pws = snmpwalk_cache_oid($device, "pwMplsPeerLdpID", $pws, "PW-MPLS-STD-MIB");
//echo("PWS_WALK: ".count($pws)."\n"); var_dump($pws);
$peer_where = generate_query_values($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
$peer_where = generate_query_values_and($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
foreach ($pws as $pw_id => $pw)
{
$peer_addr_type = $pw['pwPeerAddrType'];
@ -84,7 +83,7 @@ $pws = snmpwalk_cache_oid($device, "pwMplsPeerLdpID", $pws, "PW-MPLS-STD-MIB");
$pw['pwDescr'] = rtrim($pw['pwDescr'], ". \t\n\r\0\x0B");
$pw['pwRemoteIfString'] = rtrim($pw['pwRemoteIfString'], ". \t\n\r\0\x0B");
$if_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `ifDescr` = ? AND `device_id` = ? LIMIT 1;', array($pw['pwName'], $device['device_id']));
$if_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ? LIMIT 1;', array($pw['pwName'], $pw['pwName'], $device['device_id']));
if (!is_numeric($if_id) && strpos($pw['pwName'], '_'))
{
// IOS-XR some time use '_' instead '/'. http://jira.observium.org/browse/OBSERVIUM-246
@ -99,7 +98,7 @@ $pws = snmpwalk_cache_oid($device, "pwMplsPeerLdpID", $pws, "PW-MPLS-STD-MIB");
// pwName.3221225473 = STRING: 82.209.169.153,3055
// pwMplsLocalLdpID.3221225473 = STRING: 82.209.169.129:0
list($local_addr) = explode(':', $pw['pwMplsLocalLdpID']);
$local_where = generate_query_values($device['device_id'], 'device_id'); // Filter by self IPs
$local_where = generate_query_values_and($device['device_id'], 'device_id'); // Filter by self IPs
if ($ids = get_entity_ids_ip_by_network('port', $local_addr, $local_where))
{
$if_id = $ids[0];

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -58,20 +57,20 @@ foreach (explode("\n", $oids) as $data)
for ($encNum = 1; $encNum <= 8; $encNum++) {
$table = "hwEnclosure$encNum";
$enclosures = snmpwalk_cache_oid($device, $table, [], "ARECA-SNMP-MIB");
if (!isset($enclosures[0]) || !$enclosures[0]["hwEnclosure0${encNum}Installed"]) {
if (!isset($enclosures[0]) || !$enclosures[0]["hwEnclosure0{$encNum}Installed"]) {
// Index 0 is the main enclosure data, we check if the enclosure is connected, but it will
// not have any sensors of its own, so we skip index 0.
continue;
}
$enclosure = $enclosures[0];
unset($enclosures[0]);
$name = $enclosure["hwEnclosure0${encNum}Description"];
$name = $enclosure["hwEnclosure0{$encNum}Description"];
foreach ($enclosures as $index => $entry) {
if ($entry["hwEnclosure0${encNum}VolIndex"]) {
$descr = $name . ' (' . $encNum . ') ' . $entry["hwEnclosure0${encNum}VolDesc"];
if ($entry["hwEnclosure0{$encNum}VolIndex"]) {
$descr = $name . ' (' . $encNum . ') ' . $entry["hwEnclosure0{$encNum}VolDesc"];
$oid_num = ".1.3.6.1.4.1.18928.1.2.2." . ($encNum+1) . ".8.1.3.$index";
$oid_name = "hwEnclosure0${encNum}VolValue";
$oid_name = "hwEnclosure0{$encNum}VolValue";
$value = $entry[$oid_name];
//discover_sensor('voltage', $device, $oid_num, "$oid_name.$index", 'areca', $descr, 0.001, $value);
@ -79,10 +78,10 @@ for ($encNum = 1; $encNum <= 8; $encNum++) {
discover_sensor_ng($device, 'voltage', $mib, $oid_name, $oid_num, $index, NULL, $descr, 0.001, $value, $options);
}
if ($entry["hwEnclosure0${encNum}FanIndex"]) {
$descr = $name . ' (' . $encNum . ') ' . $entry["hwEnclosure0${encNum}FanDesc"];
if ($entry["hwEnclosure0{$encNum}FanIndex"]) {
$descr = $name . ' (' . $encNum . ') ' . $entry["hwEnclosure0{$encNum}FanDesc"];
$oid_num = ".1.3.6.1.4.1.18928.1.2.2." . ($encNum+1) . ".9.1.3.$index";
$oid_name = "hwEnclosure0${encNum}FanSpeed";
$oid_name = "hwEnclosure0{$encNum}FanSpeed";
$value = $entry[$oid_name];
//discover_sensor('fanspeed', $device, $oid_num, "$oid_name.$index", 'areca', $descr, 1, $value);
@ -90,10 +89,10 @@ for ($encNum = 1; $encNum <= 8; $encNum++) {
discover_sensor_ng($device, 'fanspeed', $mib, $oid_name, $oid_num, $index, NULL, $descr, 1, $value, $options);
}
if ($entry["hwEnclosure0${encNum}TempIndex"]) {
$descr = $name . ' (' . $encNum . ') ' . $entry["hwEnclosure0${encNum}TempDesc"];
if ($entry["hwEnclosure0{$encNum}TempIndex"]) {
$descr = $name . ' (' . $encNum . ') ' . $entry["hwEnclosure0{$encNum}TempDesc"];
$oid_num = ".1.3.6.1.4.1.18928.1.2.2." . ($encNum+1) . ".10.1.3.$index";
$oid_name = "hwEnclosure0${encNum}TempValue";
$oid_name = "hwEnclosure0{$encNum}TempValue";
$value = $entry[$oid_name];
//discover_sensor('temperature', $device, $oid_num, "$oid_name.$index", 'areca', $descr, 1, $value);
@ -101,13 +100,13 @@ for ($encNum = 1; $encNum <= 8; $encNum++) {
discover_sensor_ng($device, 'temperature', $mib, $oid_name, $oid_num, $index, NULL, $descr, 1, $value, $options);
}
if ($entry["hwEnclosure0${encNum}PowerIndex"]) {
$descr = $name . ' (' . $encNum . ') ' . $entry["hwEnclosure0${encNum}PowerDesc"];
if ($entry["hwEnclosure0{$encNum}PowerIndex"]) {
$descr = $name . ' (' . $encNum . ') ' . $entry["hwEnclosure0{$encNum}PowerDesc"];
$oid_num = ".1.3.6.1.4.1.18928.1.2.2." . ($encNum+1) . ".7.1.3.$index";
$oid_name = "hwEnclosure0${encNum}PowerState";
$oid_name = "hwEnclosure0{$encNum}PowerState";
$value = $entry[$oid_name];
//discover_status($device, $oid, "hwEnclosure0${encNum}PowerState.$index", 'areca-power-state', $descr, $value, array('entPhysicalClass' => 'power'));
//discover_status($device, $oid, "hwEnclosure0{$encNum}PowerState.$index", 'areca-power-state', $descr, $value, array('entPhysicalClass' => 'power'));
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, 'areca-power-state', $descr, $value, [ 'entPhysicalClass' => 'power' ]);
}
}
@ -118,21 +117,21 @@ for ($encNum = 1; $encNum <= 8; $encNum++) {
for ($encNum = 1; $encNum <= 8; $encNum++) {
$table = "hddEnclosure$encNum";
$enclosures = snmpwalk_cache_oid($device, $table, [], "ARECA-SNMP-MIB");
if (!isset($enclosures[0]) || !$enclosures[0]["hddEnclosure0${encNum}Installed"]) {
if (!isset($enclosures[0]) || !$enclosures[0]["hddEnclosure0{$encNum}Installed"]) {
// Index 0 is the main enclosure data, we check if the enclosure is connected, but it will
// not have any sensors of its own, so we skip index 0.
continue;
}
$enclosure = $enclosures[0];
unset($enclosures[0]);
$name = $enclosure["hddEnclosure0${encNum}Description"];
$name = $enclosure["hddEnclosure0{$encNum}Description"];
foreach ($enclosures as $index => $entry) {
if ($entry["hddEnclosure0${encNum}Name"] === 'N.A.') { continue; }
if ($entry["hddEnclosure0{$encNum}Name"] === 'N.A.') { continue; }
$descr = 'Slot ' . $entry["hddEnclosure0${encNum}Slots"] . ', ' . trim($entry["hddEnclosure0${encNum}Name"]) . ' (SN: ' . trim($entry["hddEnclosure0${encNum}Serial"]) . ", $name)";
$descr = 'Slot ' . $entry["hddEnclosure0{$encNum}Slots"] . ', ' . trim($entry["hddEnclosure0{$encNum}Name"]) . ' (SN: ' . trim($entry["hddEnclosure0{$encNum}Serial"]) . ", $name)";
$oid_num = ".1.3.6.1.4.1.18928.1.2.3." . $encNum . ".4.1.8.$index";
$oid_name = "hddEnclosure0${encNum}State";
$oid_name = "hddEnclosure0{$encNum}State";
$value = $entry[$oid_name];
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, 'areca-hdd-state', $descr, $value, [ 'entPhysicalClass' => 'storage' ]);

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -15,25 +14,19 @@
//AXIS-VIDEO-MIB::tempSensorStatus.common.2 = INTEGER: ok(1)
//AXIS-VIDEO-MIB::tempSensorValue.common.1 = INTEGER: 26
//AXIS-VIDEO-MIB::tempSensorValue.common.2 = INTEGER: 32
//AXIS-VIDEO-MIB::storageName.1 = STRING: SD_DISK
//AXIS-VIDEO-MIB::storageName.2 = STRING: NetworkShare
//AXIS-VIDEO-MIB::storageDisruptionDetected.1 = INTEGER: no(1)
//AXIS-VIDEO-MIB::storageDisruptionDetected.2 = INTEGER: yes(2)
$mib = 'AXIS-VIDEO-MIB';
// Temperature Sensor
$oids = snmpwalk_cache_oid($device, 'tempSensorEntry', array(), $mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
$oids = snmpwalk_cache_oid($device, 'tempSensorEntry', [], $mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
print_debug_vars($oids);
foreach ($oids as $index => $entry)
{
foreach ($oids as $index => $entry) {
//if ($entry['tempSensorStatus'] == 'failure') { continue; } // ok(1), failure(2), outOfBoundary(3)
// common(1), housing(2), rack(3), cpu(4)
list($tempSensorType, $tempSensorId) = explode('.', $index);
switch ($tempSensorType)
{
switch ($tempSensorType) {
case '1':
$descr = 'System temperature';
break;
@ -49,8 +42,7 @@ foreach ($oids as $index => $entry)
default:
$descr = 'Temperature';
}
if (count($oids) > 1)
{
if (count($oids) > 1) {
$descr .= ' ' . $tempSensorId;
}
@ -69,19 +61,17 @@ foreach ($oids as $index => $entry)
$type = 'axisStatus';
$value = $entry[$oid_name];
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, $type, $descr, $value, array('entPhysicalClass' => 'other'));
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, $type, $descr, $value, [ 'entPhysicalClass' => 'other' ]);
}
// Fan Sensor
$oids = snmpwalk_cache_oid($device, 'fanEntry', array(), $mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
$oids = snmpwalk_cache_oid($device, 'fanEntry', [], $mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
print_debug_vars($oids);
foreach ($oids as $index => $entry)
{
foreach ($oids as $index => $entry) {
// common(1), housing(2), rack(3), cpu(4)
list($SensorType, $SensorId) = explode('.', $index);
switch ($SensorType)
{
switch ($SensorType) {
case '1':
$descr = 'System fan';
break;
@ -97,8 +87,7 @@ foreach ($oids as $index => $entry)
default:
$descr = 'Fan';
}
if (count($oids) > 1)
{
if (count($oids) > 1) {
$descr .= ' ' . $SensorId;
}
@ -107,7 +96,7 @@ foreach ($oids as $index => $entry)
$type = 'axisStatus';
$value = $entry[$oid_name];
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, $type, $descr, $value, array('entPhysicalClass' => 'fan'));
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, $type, $descr, $value, [ 'entPhysicalClass' => 'fan' ]);
}
// EOF

View File

@ -6,20 +6,16 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$entity_array = snmpwalk_cache_oid($device, 'entSensorValueEntry', $entity_array, 'CISCO-ENTITY-SENSOR-MIB');
if ($GLOBALS['snmp_status'])
{
if (is_array($GLOBALS['cache']['snmp']['ENTITY-MIB'][$device['device_id']]))
{
if (snmp_status()) {
if (is_array($GLOBALS['cache']['snmp']['ENTITY-MIB'][$device['device_id']])) {
// If this already received in inventory module, skip walking
foreach ($GLOBALS['cache']['snmp']['ENTITY-MIB'][$device['device_id']] as $index => $entry)
{
if (isset($entity_array[$index]))
{
foreach ($GLOBALS['cache']['snmp']['ENTITY-MIB'][$device['device_id']] as $index => $entry) {
if (isset($entity_array[$index])) {
$entity_array[$index] = array_merge($entity_array[$index], $entry);
} else {
$entity_array[$index] = $entry;
@ -54,10 +50,9 @@ if ($GLOBALS['snmp_status'])
}
}
$t_oids = array('entSensorThresholdSeverity', 'entSensorThresholdRelation', 'entSensorThresholdValue');
$t_entity_array = array();
foreach ($t_oids as $oid)
{
$t_oids = [ 'entSensorThresholdSeverity', 'entSensorThresholdRelation', 'entSensorThresholdValue' ];
$t_entity_array = [];
foreach ($t_oids as $oid) {
$t_entity_array = snmpwalk_cache_twopart_oid($device, $oid, $t_entity_array, 'CISCO-ENTITY-SENSOR-MIB');
}
@ -79,7 +74,7 @@ if ($GLOBALS['snmp_status'])
dBm(14): dB relative to 1mW of power
*/
$c_entitysensor = array(
$c_entitysensor = [
'voltsAC' => 'voltage',
'voltsDC' => 'voltage',
'amperes' => 'current',
@ -92,14 +87,14 @@ if ($GLOBALS['snmp_status'])
'truthvalue' => 'state',
//'specialEnum' => 'gauge', // This sensors seems as useless
'dBm' => 'dbm'
);
];
$i = [];
foreach ($entity_array as $index => $entry) {
if (is_numeric($index) && isset($c_entitysensor[$entry['entSensorType']]) &&
is_numeric($entry['entSensorValue']) && $entry['entSensorStatus'] === 'ok') {
$ok = TRUE;
$options = array('entPhysicalIndex' => $index);
$options = [ 'entPhysicalIndex' => $index ];
$descr = rewrite_entity_name($entry['entPhysicalDescr']);
if ($device['os'] === 'cisco-firepower') {
@ -174,7 +169,7 @@ if ($GLOBALS['snmp_status'])
print_debug_vars($entry);
// Now try to search port bounded with sensor by ENTITY-MIB
if ($ok && in_array($type, array('temperature', 'voltage', 'current', 'dbm', 'power'))) {
if ($ok && in_array($type, [ 'temperature', 'voltage', 'current', 'dbm', 'power' ])) {
$port = get_port_by_ent_index($device, $index);
$options['entPhysicalIndex'] = $index;
if (is_array($port)) {
@ -209,17 +204,22 @@ if ($GLOBALS['snmp_status'])
}
// Set thresholds for numeric sensors
$limits = array();
$limits = [];
$scale = NULL;
if ($c_entitysensor[$entry['entSensorType']] !== 'state') {
$precision = $entry['entSensorPrecision'];
// See: https://jira.observium.org/browse/OBS-3026
// Note, issue not actual on firmware less than 16.11, not sure if fixed on more newer firmwares
// Seems as not actual on 16.12.x, see: https://jira.observium.org/browse/OBS-3707
if ($device['os'] === 'iosxe' && $precision > 0 &&
version_compare($device['version'], '16.11', '>=') && version_compare($device['version'], '16.12', '<')) {
// See: https://jira.observium.org/browse/OBS-3026
// Note, issue not actual on firmware less than 16.11, not sure if fixed on newer firmwares
// Seems as not actual on 16.12.x, see: https://jira.observium.org/browse/OBS-3707
// I not sure that this fully correct, but for issue case - works
$precision -= 1;
} elseif ($device['os'] === 'iosxr' && $precision > 0 && $type === 'power' &&
$device['version'] === '6.4.2' && preg_match('/ASR\-90\d{2}/', $device['hardware'])) {
// See: https://jira.observium.org/browse/OBS-4079
// ASR9k 32bit platform issue for power sensor
$precision -= 1;
}
$scale = si_to_scale($entry['entSensorScale'], $precision);

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,17 +6,16 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2014 Adam Armstrong
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$hpups_array = array();
$hpups_array = [];
$hpups_array = snmpwalk_cache_oid($device, 'upsInput', $hpups_array, 'CPQPOWER-MIB');
$hpups_array = snmpwalk_cache_oid($device, 'upsOutput', $hpups_array, 'CPQPOWER-MIB');
$hpups_array = snmpwalk_cache_oid($device, 'upsBypass', $hpups_array, 'CPQPOWER-MIB');
foreach (array_slice(array_keys($hpups_array),1) as $phase)
{
foreach (array_slice(array_keys($hpups_array),1) as $phase) {
# Skip garbage output:
# upsOutput.6.0 = 0
# upsOutput.7.0 = 0
@ -39,8 +37,7 @@ foreach (array_slice(array_keys($hpups_array),1) as $phase)
$oid = ".1.3.6.1.4.1.232.165.3.3.4.1.3.$index"; # CPQPOWER-MIB:upsInputCurrent.$index
$value = $hpups_array[$phase]['upsInputCurrent'];
if ($value < 10000) # upsInputCurrent.1 = 136137420 ? really? You're nuts.
{
if ($value < 10000) { # upsInputCurrent.1 = 136137420 ? really? You're nuts.
$options = [ 'rename_rrd' => "CPQPOWER-MIB-upsInputEntry.$index" ];
discover_sensor_ng($device, 'current', $mib, 'upsInputCurrent', $oid, $index, NULL, $descr, 1, $value, $options);
}
@ -132,29 +129,26 @@ unset($hpups_array);
//CPQPOWER-MIB::pduOutputPower.2 = INTEGER: 671
//CPQPOWER-MIB::pduOutputNumBreakers.1 = INTEGER: 3
//CPQPOWER-MIB::pduOutputNumBreakers.2 = INTEGER: 3
$hppdu_array = snmpwalk_cache_oid($device, 'pduIdentTable', array(), 'CPQPOWER-MIB');
$hppdu_array = snmpwalk_cache_oid($device, 'pduIdentTable', [], 'CPQPOWER-MIB');
$hppdu_array = snmpwalk_cache_oid($device, 'pduOutputTable', $hppdu_array, 'CPQPOWER-MIB');
foreach ($hppdu_array as $index => $entry)
{
foreach ($hppdu_array as $index => $entry) {
// Monitor PDU Status
$oid = ".1.3.6.1.4.1.232.165.2.1.2.1.8.$index";
$descr = $entry['pduName'].' Status';
if (!empty($entry['pduStatus']))
{
if (!empty($entry['pduStatus'])) {
discover_status_ng($device, $mib, 'pduStatus', $oid, $index, 'cpqpower-pdu-status', $descr, $entry['pduStatus'], array('entPhysicalClass' => 'power', 'rename_rrd' => 'cpqpower-pdu-status-%index%'));
}
// Monitor PDU Output load
$oid = ".1.3.6.1.4.1.232.165.2.3.1.1.2.$index";
$descr = $entry['pduName'].' Load';
$limits = array();
if (!empty($entry['pduOutputLoad']) && $entry['pduOutputLoad'] != '-1')
{
$limits = [];
if (!empty($entry['pduOutputLoad']) && $entry['pduOutputLoad'] != '-1') {
$options = [ 'rename_rrd' => "CPQPOWER-MIB-%index%" ];
discover_sensor_ng($device, 'capacity', $mib, 'pduOutputLoad', $oid, $index, NULL, $descr, 1, $entry['pduOutputLoad'], $options);
// Find power limit by measure the reported output power divided by the reported load of the PDU
$pdu_maxload = 100 * ($entry['pduOutputPower'] / $entry['pduOutputLoad']);
$pdu_maxload = 100 * float_div($entry['pduOutputPower'], $entry['pduOutputLoad']);
$pdu_warnload = 0.8 * $pdu_maxload;
$limits = array('limit_high' => round($pdu_maxload, 2),
'limit_high_warn' => round($pdu_warnload, 2));
@ -164,8 +158,7 @@ foreach ($hppdu_array as $index => $entry)
$oid = ".1.3.6.1.4.1.232.165.2.3.1.1.4.$index";
$descr = $entry['pduName'].' Output Power';
if (!empty($entry['pduOutputPower']) && $entry['pduOutputPower'] != '-1')
{
if (!empty($entry['pduOutputPower']) && $entry['pduOutputPower'] != '-1') {
$options = $limits;
$options['rename_rrd'] = "CPQPOWER-MIB-%index%";
discover_sensor_ng($device, 'power', $mib, 'pduOutputPower', $oid, $index, NULL, $descr, 1, $entry['pduOutputPower'], $options);
@ -182,9 +175,8 @@ foreach ($hppdu_array as $index => $entry)
//CPQPOWER-MIB::breakerPercentLoad.2.6 = INTEGER: 0
//CPQPOWER-MIB::breakerStatus.1.1 = INTEGER: 0
//CPQPOWER-MIB::breakerStatus.2.6 = INTEGER: 0
$hppdu_breaker_array = snmpwalk_cache_oid($device, 'pduOutputBreakerTable', array(), 'CPQPOWER-MIB');
foreach ($hppdu_breaker_array as $index => $entry)
{
$hppdu_breaker_array = snmpwalk_cache_oid($device, 'pduOutputBreakerTable', [], 'CPQPOWER-MIB');
foreach ($hppdu_breaker_array as $index => $entry) {
if ($entry['breakerVoltage'] <= 0) { continue; }
list($breaker_output, $breaker_unit) = explode('.', $index, 2);
@ -192,7 +184,7 @@ foreach ($hppdu_breaker_array as $index => $entry)
// Find powerlimit by measure the reported output power devivded by the reported load of the PDU
//$breaker_maxload = 100 * ($entry['breakerCurrent'] / $entry['breakerPercentLoad']);
$breaker_maxload = $entry['breakerCurrent'] / $entry['breakerPercentLoad']; // breakerCurrent already scaled by 100
$breaker_maxload = float_div($entry['breakerCurrent'], $entry['breakerPercentLoad']); // breakerCurrent already scaled by 100
$breaker_warnload = 0.8 * $breaker_maxload;
$limits = array('limit_high' => round($breaker_maxload, 2),
'limit_high_warn' => round($breaker_warnload, 2));

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -113,12 +113,18 @@ foreach ($oids as $index => $entry) {
$oid_num = '.1.3.6.1.4.1.171.12.72.2.1.1.1.2.'.$index;
$scale = 1;
$value = $entry[$oid_name];
$limits = [
'limit_high' => $oids_limit[$index]['temperature']['swDdmHighAlarm'],
'limit_low' => $oids_limit[$index]['temperature']['swDdmLowAlarm'],
'limit_high_warn' => $oids_limit[$index]['temperature']['swDdmHighWarning'],
'limit_low_warn' => $oids_limit[$index]['temperature']['swDdmLowWarning']
];
$limits = [];
$limit_type = 'temperature';
$limits_oids = [ 'limit_high' => 'swDdmHighAlarm', 'limit_high_warn' => 'swDdmHighWarning',
'limit_low' => 'swDdmLowAlarm', 'limit_low_warn' => 'swDdmLowWarning' ];
foreach ($limits_oids as $limit => $limit_oid) {
// Prevent php8 fatal errors
if (!is_numeric($oids_limit[$index][$limit_type][$limit_oid])) { continue; }
$limits[$limit] = $oids_limit[$index][$limit_type][$limit_oid] * $scale;
}
discover_sensor_ng($device, $class, $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, array_merge($options, $limits));
// Voltage
@ -128,12 +134,18 @@ foreach ($oids as $index => $entry) {
$oid_num = '.1.3.6.1.4.1.171.12.72.2.1.1.1.3.'.$index;
$scale = 1;
$value = $entry[$oid_name];
$limits = [
'limit_high' => $oids_limit[$index]['voltage']['swDdmHighAlarm'],
'limit_low' => $oids_limit[$index]['voltage']['swDdmLowAlarm'],
'limit_high_warn' => $oids_limit[$index]['voltage']['swDdmHighWarning'],
'limit_low_warn' => $oids_limit[$index]['voltage']['swDdmLowWarning']
];
$limits = [];
$limit_type = 'voltage';
$limits_oids = [ 'limit_high' => 'swDdmHighAlarm', 'limit_high_warn' => 'swDdmHighWarning',
'limit_low' => 'swDdmLowAlarm', 'limit_low_warn' => 'swDdmLowWarning' ];
foreach ($limits_oids as $limit => $limit_oid) {
// Prevent php8 fatal errors
if (!is_numeric($oids_limit[$index][$limit_type][$limit_oid])) { continue; }
$limits[$limit] = $oids_limit[$index][$limit_type][$limit_oid] * $scale;
}
discover_sensor_ng($device, $class, $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, array_merge($options, $limits));
// Tx Bias
@ -143,12 +155,18 @@ foreach ($oids as $index => $entry) {
$oid_num = '.1.3.6.1.4.1.171.12.72.2.1.1.1.4.'.$index;
$scale = 0.001;
$value = $entry[$oid_name];
$limits = [
'limit_high' => $oids_limit[$index]['bias']['swDdmHighAlarm'] * $scale,
'limit_low' => $oids_limit[$index]['bias']['swDdmLowAlarm'] * $scale,
'limit_high_warn' => $oids_limit[$index]['bias']['swDdmHighWarning'] * $scale,
'limit_low_warn' => $oids_limit[$index]['bias']['swDdmLowWarning'] * $scale
];
$limits = [];
$limit_type = 'bias';
$limits_oids = [ 'limit_high' => 'swDdmHighAlarm', 'limit_high_warn' => 'swDdmHighWarning',
'limit_low' => 'swDdmLowAlarm', 'limit_low_warn' => 'swDdmLowWarning' ];
foreach ($limits_oids as $limit => $limit_oid) {
// Prevent php8 fatal errors
if (!is_numeric($oids_limit[$index][$limit_type][$limit_oid])) { continue; }
$limits[$limit] = $oids_limit[$index][$limit_type][$limit_oid] * $scale;
}
discover_sensor_ng($device, $class, $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, array_merge($options, $limits));
// Tx Power
@ -158,12 +176,18 @@ foreach ($oids as $index => $entry) {
$oid_num = '.1.3.6.1.4.1.171.12.72.2.1.1.1.5.'.$index;
$scale = $power_unit === 'mw' ? 0.001 : 1;
$value = $entry[$oid_name];
$limits = [
'limit_high' => $oids_limit[$index]['txPower']['swDdmHighAlarm'] * $scale,
'limit_low' => $oids_limit[$index]['txPower']['swDdmLowAlarm'] * $scale,
'limit_high_warn' => $oids_limit[$index]['txPower']['swDdmHighWarning'] * $scale,
'limit_low_warn' => $oids_limit[$index]['txPower']['swDdmLowWarning'] * $scale
];
$limits = [];
$limit_type = 'txPower';
$limits_oids = [ 'limit_high' => 'swDdmHighAlarm', 'limit_high_warn' => 'swDdmHighWarning',
'limit_low' => 'swDdmLowAlarm', 'limit_low_warn' => 'swDdmLowWarning' ];
foreach ($limits_oids as $limit => $limit_oid) {
// Prevent php8 fatal errors
if (!is_numeric($oids_limit[$index][$limit_type][$limit_oid])) { continue; }
$limits[$limit] = $oids_limit[$index][$limit_type][$limit_oid] * $scale;
}
discover_sensor_ng($device, $class, $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, array_merge($options, $limits));
// Rx Power
@ -173,12 +197,18 @@ foreach ($oids as $index => $entry) {
$oid_num = '.1.3.6.1.4.1.171.12.72.2.1.1.1.6.'.$index;
$scale = $power_unit === 'mw' ? 0.001 : 1;
$value = $entry[$oid_name];
$limits = [
'limit_high' => $oids_limit[$index]['rxPower']['swDdmHighAlarm'] * $scale,
'limit_low' => $oids_limit[$index]['rxPower']['swDdmLowAlarm'] * $scale,
'limit_high_warn' => $oids_limit[$index]['rxPower']['swDdmHighWarning'] * $scale,
'limit_low_warn' => $oids_limit[$index]['rxPower']['swDdmLowWarning'] * $scale
];
$limits = [];
$limit_type = 'rxPower';
$limits_oids = [ 'limit_high' => 'swDdmHighAlarm', 'limit_high_warn' => 'swDdmHighWarning',
'limit_low' => 'swDdmLowAlarm', 'limit_low_warn' => 'swDdmLowWarning' ];
foreach ($limits_oids as $limit => $limit_oid) {
// Prevent php8 fatal errors
if (!is_numeric($oids_limit[$index][$limit_type][$limit_oid])) { continue; }
$limits[$limit] = $oids_limit[$index][$limit_type][$limit_oid] * $scale;
}
discover_sensor_ng($device, $class, $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, array_merge($options, $limits));
}

View File

@ -99,6 +99,7 @@ foreach ($cache_discovery['DKSF-48-4-X-X-1']['temphum'] as $index => $entry)
}
}
/* Moved to DEF
$cache_discovery['DKSF-48-4-X-X-1']['thermo'] = snmpwalk_cache_oid($device, 'npThermoTable', array(), 'DKSF-48-4-X-X-1');
foreach ($cache_discovery['DKSF-48-4-X-X-1']['thermo'] as $index => $entry)
{
@ -113,6 +114,7 @@ foreach ($cache_discovery['DKSF-48-4-X-X-1']['thermo'] as $index => $entry)
discover_sensor('temperature', $device, $oid, "npThermoValue.$index", 'dskf-mib', $descr, 1, $value, $limits);
}
}
*/
$cache_discovery['DKSF-48-4-X-X-1']['io'] = snmpwalk_cache_oid($device, 'npIoTable', array(), 'DKSF-48-4-X-X-1');
foreach ($cache_discovery['DKSF-48-4-X-X-1']['io'] as $index => $entry)

View File

@ -73,6 +73,7 @@ foreach ($cache_discovery['DKSF-50-11-X-X-X']['loop'] as $index => $entry)
}
}
/* Moved to DEF
$cache_discovery['DKSF-50-11-X-X-X']['temphum'] = snmpwalk_cache_oid($device, 'npRelHumTable', array(), 'DKSF-50-11-X-X-X');
foreach ($cache_discovery['DKSF-50-11-X-X-X']['temphum'] as $index => $entry)
{
@ -113,6 +114,7 @@ foreach ($cache_discovery['DKSF-50-11-X-X-X']['thermo'] as $index => $entry)
discover_sensor('temperature', $device, $oid, "npThermoValue.$index", 'dskf-mib', $descr, 1, $value, $limits);
}
}
*/
$cache_discovery['DKSF-50-11-X-X-X']['io'] = snmpwalk_cache_oid($device, 'npIoTable', array(), 'DKSF-50-11-X-X-X');
foreach ($cache_discovery['DKSF-50-11-X-X-X']['io'] as $index => $entry)

View File

@ -110,6 +110,7 @@ foreach ($cache_discovery['DKSF-60-4-X-X-X']['temphum'] as $index => $entry)
}
}
/* Moved to DEF
$cache_discovery['DKSF-60-4-X-X-X']['thermo'] = snmpwalk_cache_oid($device, 'npThermoTable', array(), 'DKSF-60-4-X-X-X');
foreach ($cache_discovery['DKSF-60-4-X-X-X']['thermo'] as $index => $entry)
{
@ -124,6 +125,7 @@ foreach ($cache_discovery['DKSF-60-4-X-X-X']['thermo'] as $index => $entry)
discover_sensor('temperature', $device, $oid, "npThermoValue.$index", 'dskf-mib', $descr, 1, $value, $limits);
}
}
*/
$cache_discovery['DKSF-60-4-X-X-X']['io'] = snmpwalk_cache_oid($device, 'npIoTable', array(), 'DKSF-60-4-X-X-X');
foreach ($cache_discovery['DKSF-60-4-X-X-X']['io'] as $index => $entry)

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,14 +6,15 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// FIXME migrate to definitions
$cache_discovery['DKSF-70-5-X-X-1']['smoke'] = snmpwalk_cache_oid($device, 'npSmokeTable', array(), 'DKSF-70-5-X-X-1');
foreach ($cache_discovery['DKSF-70-5-X-X-1']['smoke'] as $index => $entry)
/* It's broken and renamed, need device access
$cache_discovery['DKSF-70-MIB']['smoke'] = snmpwalk_cache_oid($device, 'npSmokeTable', array(), 'DKSF-70-MIB');
foreach ($cache_discovery['DKSF-70-MIB']['smoke'] as $index => $entry)
{
if ($entry['npSmokePower'] == 'off') { continue; }
@ -27,9 +27,10 @@ foreach ($cache_discovery['DKSF-70-5-X-X-1']['smoke'] as $index => $entry)
discover_status($device, $oid, 'npSmokeStatus.'.$index, 'dskf-mib-smoke-state', $descr, $value, array('entPhysicalClass' => 'other'));
}
}
*/
$cache_discovery['DKSF-70-5-X-X-1']['loop'] = snmpwalk_cache_oid($device, 'npCurLoopTable', array(), 'DKSF-70-5-X-X-1');
foreach ($cache_discovery['DKSF-70-5-X-X-1']['loop'] as $index => $entry)
$cache_discovery['DKSF-70-MIB']['loop'] = snmpwalk_cache_oid($device, 'npCurLoopTable', array(), 'DKSF-70-MIB');
foreach ($cache_discovery['DKSF-70-MIB']['loop'] as $index => $entry)
{
if ($entry['npCurLoopPower'] == 'off' || $entry['npCurLoopStatus'] == 'notPowered') { continue; }
@ -72,8 +73,9 @@ foreach ($cache_discovery['DKSF-70-5-X-X-1']['loop'] as $index => $entry)
}
}
$cache_discovery['DKSF-70-5-X-X-1']['temphum'] = snmpwalk_cache_oid($device, 'npRelHumTable', array(), 'DKSF-70-5-X-X-1');
foreach ($cache_discovery['DKSF-70-5-X-X-1']['temphum'] as $index => $entry)
/* Moved to DEF
$cache_discovery['DKSF-70-MIB']['temphum'] = snmpwalk_cache_oid($device, 'npRelHumTable', array(), 'DKSF-70-MIB');
foreach ($cache_discovery['DKSF-70-MIB']['temphum'] as $index => $entry)
{
// Temperature
$descr = ($entry['npRelHumMemo'] ? $entry['npRelHumMemo'] : 'Temperature '.$index);
@ -98,8 +100,8 @@ foreach ($cache_discovery['DKSF-70-5-X-X-1']['temphum'] as $index => $entry)
}
}
$cache_discovery['DKSF-70-5-X-X-1']['thermo'] = snmpwalk_cache_oid($device, 'npThermoTable', array(), 'DKSF-70-5-X-X-1');
foreach ($cache_discovery['DKSF-70-5-X-X-1']['thermo'] as $index => $entry)
$cache_discovery['DKSF-70-MIB']['thermo'] = snmpwalk_cache_oid($device, 'npThermoTable', array(), 'DKSF-70-MIB');
foreach ($cache_discovery['DKSF-70-MIB']['thermo'] as $index => $entry)
{
// Temperature
$descr = ($entry['npThermoMemo'] ? $entry['npThermoMemo'] : 'Thermo '.$index);
@ -112,9 +114,10 @@ foreach ($cache_discovery['DKSF-70-5-X-X-1']['thermo'] as $index => $entry)
discover_sensor('temperature', $device, $oid, "npThermoValue.$index", 'dskf-mib', $descr, 1, $value, $limits);
}
}
*/
$cache_discovery['DKSF-70-5-X-X-1']['io'] = snmpwalk_cache_oid($device, 'npIoTable', array(), 'DKSF-70-5-X-X-1');
foreach ($cache_discovery['DKSF-70-5-X-X-1']['io'] as $index => $entry)
$cache_discovery['DKSF-70-MIB']['io'] = snmpwalk_cache_oid($device, 'npIoTable', array(), 'DKSF-70-MIB');
foreach ($cache_discovery['DKSF-70-MIB']['io'] as $index => $entry)
{
if ($entry['npIoLevelIn'] == '0') { continue; }
@ -127,8 +130,8 @@ foreach ($cache_discovery['DKSF-70-5-X-X-1']['io'] as $index => $entry)
discover_counter($device, 'counter', $mib, $oid_name, $oid, $index, $descr, 1, $value);
}
print_debug_vars($cache_discovery['DKSF-70-5-X-X-1']);
print_debug_vars($cache_discovery['DKSF-70-MIB']);
unset($cache_discovery['DKSF-70-5-X-X-1']);
unset($cache_discovery['DKSF-70-MIB']);
// EOF

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -156,32 +155,39 @@ $outlets = snmpwalk_cache_twopart_oid($device, 'outletCurrentTable', $outle
// Power statistics currently not collected.
//$outlets = snmpwalk_cache_twopart_oid($device, 'outletCurrentTable', $outlets, 'EATON-EPDU-MIB');
foreach ($outlets AS $unit_id => $unit_data)
{
foreach ($unit_data AS $outlet_id => $outlet)
{
foreach ($outlets as $unit_id => $unit_data) {
foreach ($unit_data as $outlet_id => $entry) {
$outlet_index = $unit_id.".".$outlet_id;
$outlet_descr = "Unit $unit_id ".$outlet['outletName'] . " (".$outlet['outletType'].")";
$outlet_capacity = $outlet['outletCurrentCapacity'] * 0.001;
$outlet_descr = "Unit $unit_id ".$entry['outletName'] . " (".$entry['outletType'].")";
$outlet_capacity = $entry['outletCurrentCapacity'] * 0.001;
$current_value = $outlet['outletCurrent'];
$percent_value = $outlet['outletCurrentPercentLoad'];
$status_value = $outlet['outletCurrentThStatus'];
$crest_value = $outlet['outletCurrentCrestFactor'];
$current_value = $entry['outletCurrent'];
$percent_value = $entry['outletCurrentPercentLoad'];
$status_value = $entry['outletCurrentThStatus'];
$crest_value = $entry['outletCurrentCrestFactor'];
$current_oid = '.1.3.6.1.4.1.534.6.6.7.6.4.1.3.'.$outlet_index;
$percent_oid = '.1.3.6.1.4.1.534.6.6.7.6.4.1.10.'.$outlet_index;
$status_oid = '.1.3.6.1.4.1.534.6.6.7.6.4.1.4.'.$outlet_index;
$crest_oid = '.1.3.6.1.4.1.534.6.6.7.6.4.1.9.'.$outlet_index;
$crest_oid = '.1.3.6.1.4.1.534.6.6.7.6.4.1.9.'.$outlet_index;
discover_status($device, $status_oid, "outletCurrentThStatus.".$outlet_index, 'outletCurrentThStatus', $outlet_descr, $status_value, array('entPhysicalClass' => 'outlet'));
discover_status($device, $status_oid, "outletCurrentThStatus.".$outlet_index, 'outletCurrentThStatus', $outlet_descr, $status_value, [ 'entPhysicalClass' => 'outlet' ]);
$limits = array('limit_low' => $entry['outletCurrentThLowerCritical']*0.001, 'limit_low_warn' => $entry['outletCurrentThLowerWarning']*0.001,
'limit_high' => $entry['outletCurrentThUpperCritical']*0.001, 'limit_high_warn' => $entry['outletCurrentThUpperWarning']*0.001);
$limits = [
'limit_low' => $entry['outletCurrentThLowerCritical'] * 0.001,
'limit_low_warn' => $entry['outletCurrentThLowerWarning'] * 0.001,
'limit_high' => $entry['outletCurrentThUpperCritical'] * 0.001,
'limit_high_warn' => $entry['outletCurrentThUpperWarning'] * 0.001
];
discover_sensor('current', $device, $current_oid, "outletCurrent.$outlet_index", 'eaton-epdu-mib', $outlet_descr, 0.001, $current_value, $limits);
discover_sensor('load', $device, $percent_oid, "outletCurrentPercentLoad.$outlet_index", 'eaton-epdu-mib', $outlet_descr, 1, $percent_value);
discover_sensor('crestfactor', $device, $crest_oid, "outletCurrentCrestFactor.$outlet_index", 'eaton-epdu-mib', $outlet_descr, 1, $crest_value);
if ($percent_value >= 0) {
discover_sensor('load', $device, $percent_oid, "outletCurrentPercentLoad.$outlet_index", 'eaton-epdu-mib', $outlet_descr, 1, $percent_value);
}
if ($crest_value > 0) {
discover_sensor('crestfactor', $device, $crest_oid, "outletCurrentCrestFactor.$outlet_index", 'eaton-epdu-mib', $outlet_descr, 0.001, $crest_value);
}
}
}

View File

@ -0,0 +1,96 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// EGW4MIB::EGW4GatewaySensorDeviceCount.0 = INTEGER: 2
if (!snmp_get_oid($device, 'EGW4GatewaySensorDeviceCount.0', $mib)) {
return;
}
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceID.856694 = Gauge32: 856694
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceID.875433 = Gauge32: 875433
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceType.856694 = STRING: "WaterDetect"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceType.875433 = STRING: "Temperature+Humidity"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceReadingValuesAll.856694 = STRING: "No"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceReadingValuesAll.875433 = STRING: "24.57, 40.46"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceReadingUnitsAll.856694 = STRING: "Detected"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceReadingUnitsAll.875433 = STRING: "deg. C, RH"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceRptUT.856694 = STRING: "0x00"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceRptUT.875433 = STRING: "0x9909CE0F"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceReadingTime.856694 = STRING: "392901311"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceReadingTime.875433 = STRING: "392900464"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceReadingAge.856694 = Gauge32: 4511
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceReadingAge.875433 = Gauge32: 5358
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceTypeNo.856694 = STRING: "4"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceTypeNo.875433 = STRING: "43"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceRFStrength.856694 = STRING: "96"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceRFStrength.875433 = STRING: "34"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceActive.856694 = STRING: "Active"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceActive.875433 = STRING: "Active"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceAlarming.856694 = STRING: "Not alarming"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceAlarming.875433 = STRING: "Not alarming"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceVoltage.856694 = STRING: "3.02"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceVoltage.875433 = STRING: "3.04"
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceWDIndexNo.856694 = Wrong Type (should be OCTET STRING): INTEGER: 1
// EGW4MIB::EGW4SensorInfoTranslatedFormatSensorDeviceWDIndexNo.875433 = Wrong Type (should be OCTET STRING): INTEGER: 2
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberSensorDeviceID.856694.1 = Gauge32: 856694
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberSensorDeviceID.875433.1 = Gauge32: 875433
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberSensorDeviceID.875433.2 = Gauge32: 875433
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberDatumNumber.856694.1 = INTEGER: 1
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberDatumNumber.875433.1 = INTEGER: 1
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberDatumNumber.875433.2 = INTEGER: 2
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberReadingValue.856694.1 = STRING: "No"
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberReadingValue.875433.1 = STRING: "24.57"
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberReadingValue.875433.2 = STRING: "40.46"
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberReadingUnits.856694.1 = STRING: "Detected"
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberReadingUnits.875433.1 = STRING: "deg. C"
// EGW4MIB::EGW4SensorInfoTranslatedFormatByDatumNumberReadingUnits.875433.2 = STRING: "RH"
$egw4 = snmpwalk_cache_oid($device, 'EGW4SensorInfoTranslatedFormatEntry', [], $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'EGW4SensorInfoTranslatedFormatByDatumNumberEntry', [], $mib);
foreach ($oids as $egw4deviceid => $egw4device) {
if ($egw4[$egw4deviceid]['EGW4SensorInfoTranslatedFormatSensorDeviceActive'] !== 'Active') {
continue;
}
$name = $egw4[$egw4deviceid]['EGW4SensorInfoTranslatedFormatSensorDeviceType'];
$egw4count = count($egw4device);
foreach ($egw4device as $sensorid => $entry) {
//$entry = array_merge($entry, (array)$egw4[$egw4deviceid]);
$descr = $name;
if ($egw4count > 1) {
$descr .= " #$sensorid";
}
$index = "$egw4deviceid.$sensorid";
$oid_name = 'EGW4SensorInfoTranslatedFormatByDatumNumberReadingValue';
$oid_num = '.1.3.6.1.4.1.41542.2.2.2.3.'.$index;
$value = $entry[$oid_name];
switch (strtolower($entry['EGW4SensorInfoTranslatedFormatByDatumNumberReadingUnits'])) {
case 'deg. c':
discover_sensor_ng($device, 'temperature', $mib, $oid_name, $oid_num, $index, NULL, $descr, 1, $value);
break;
case 'ph':
discover_sensor_ng($device, 'humidity', $mib, $oid_name, $oid_num, $index, NULL, $descr, 1, $value);
break;
case 'detected':
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, 'EGW4SensorDetected', $descr, $value, [ 'entPhysicalClass' => 'sensor' ]);
break;
default:
print_warning("Unknown sensor Unit: ".$entry['EGW4SensorInfoTranslatedFormatByDatumNumberReadingUnits']);
print_debug_vars($egw4[$egw4deviceid]);
print_debug_vars($entry);
}
}
}
// EOF

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -38,7 +38,7 @@ $scale_current = 0.01;
// ENLOGIC-PDU2-MIB::pduUnitConfigAlarmStateChangeDelay.1 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
// ENLOGIC-PDU2-MIB::pduUnitConfigEnabledThresholds.1 = BITS: 00
$oids = snmpwalk_cache_oid($device, 'pduUnitStatusEntry', array(), $mib);
$oids = snmpwalk_cache_oid($device, 'pduUnitStatusEntry', [], $mib);
$oids = snmpwalk_cache_oid($device, 'pduUnitConfigLowerCriticalThreshold', $oids, $mib);
$oids = snmpwalk_cache_oid($device, 'pduUnitConfigLowerWarningThreshold', $oids, $mib);
$oids = snmpwalk_cache_oid($device, 'pduUnitConfigUpperCriticalThreshold', $oids, $mib);
@ -46,8 +46,7 @@ $oids = snmpwalk_cache_oid($device, 'pduUnitConfigUpperWarningThreshold', $oids
$oids = snmpwalk_cache_oid($device, 'pduUnitConfigEnabledThresholds', $oids, $mib);
print_debug_vars($oids);
foreach ($oids as $index => $entry)
{
foreach ($oids as $index => $entry) {
$name = "Unit $index";
// pduUnitStatusLoadState
@ -68,22 +67,18 @@ foreach ($oids as $index => $entry)
// upperWarning (2),
// upperCritical (3)
// }
$options = array();
$options = [];
$limits_flags = base_convert(str_replace(' ', '', $entry['pduUnitConfigEnabledThresholds']), 16, 10);
if (is_flag_set(bindec(10000000), $limits_flags)) // 0b 1000 0000
{
if (is_flag_set(bindec(10000000), $limits_flags)) { // 0b 1000 0000
$options['limit_low'] = $entry['pduUnitConfigLowerCriticalThreshold'] * $scale;
}
if (is_flag_set(bindec(1000000), $limits_flags)) // 0b 0100 0000
{
if (is_flag_set(bindec(1000000), $limits_flags)) { // 0b 0100 0000
$options['limit_low_warn'] = $entry['pduUnitConfigLowerWarningThreshold'] * $scale;
}
if (is_flag_set(bindec(100000), $limits_flags)) // 0b 0010 0000
{
if (is_flag_set(bindec(100000), $limits_flags)) { // 0b 0010 0000
$options['limit_high_warn'] = $entry['pduUnitConfigUpperWarningThreshold'] * $scale;
}
if (is_flag_set(bindec(10000), $limits_flags)) // 0b 0001 0000
{
if (is_flag_set(bindec(10000), $limits_flags)) { // 0b 0001 0000
$options['limit_high'] = $entry['pduUnitConfigUpperCriticalThreshold'] * $scale;
}
@ -110,8 +105,7 @@ foreach ($oids as $index => $entry)
$oid_num = ".1.3.6.1.4.1.38446.1.2.4.1.9.$index";
$value = $entry[$oid_name];
if ($value > 0)
{
if ($value > 0) {
discover_counter($device, 'energy', $mib, $oid_name, $oid_num, $index, $descr, 1, $value);
}
}
@ -136,7 +130,7 @@ $units = snmpwalk_cache_oid($device, 'pduUnitPropertiesCircuitBreakerCount',
$units = snmpwalk_cache_oid($device, 'pduUnitPropertiesConnExternalSensorCount', $units, $mib); // The current number of external sensors connected to the PDU
print_debug_vars($units);
$oids = snmpwalk_cache_twopart_oid($device, 'pduInputPhaseStatusEntry', array(), $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'pduInputPhaseStatusEntry', [], $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'pduInputPhaseConfigCurrentLowerCriticalThreshold', $oids, $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'pduInputPhaseConfigCurrentLowerWarningThreshold', $oids, $mib);
@ -151,10 +145,8 @@ $oids = snmpwalk_cache_twopart_oid($device, 'pduInputPhaseConfigVoltageUpperWarn
$oids = snmpwalk_cache_twopart_oid($device, 'pduInputPhaseConfigVoltageEnabledThresholds', $oids, $mib);
print_debug_vars($oids);
foreach ($oids as $unit => $entry1)
{
foreach ($entry1 as $phase => $entry)
{
foreach ($oids as $unit => $entry1) {
foreach ($entry1 as $phase => $entry) {
if ($entry['pduInputPhaseStatusCount'] < 1) { continue; } // Skip not exist phases
$name = "Unit $unit, Phase $phase Input";
@ -187,22 +179,18 @@ foreach ($oids as $unit => $entry1)
// upperWarning (2),
// upperCritical (3)
// }
$options = array();
$options = [];
$limits_flags = base_convert(str_replace(' ', '', $entry['pduInputPhaseConfigCurrentEnabledThresholds']), 16, 10);
if (is_flag_set(bindec(10000000), $limits_flags)) // 0b 1000 0000
{
if (is_flag_set(bindec(10000000), $limits_flags)) { // 0b 1000 0000
$options['limit_low'] = $entry['pduInputPhaseConfigCurrentLowerCriticalThreshold'] * $scale_current;
}
if (is_flag_set(bindec(1000000), $limits_flags)) // 0b 0100 0000
{
if (is_flag_set(bindec(1000000), $limits_flags)) { // 0b 0100 0000
$options['limit_low_warn'] = $entry['pduInputPhaseConfigCurrentLowerWarningThreshold'] * $scale_current;
}
if (is_flag_set(bindec(100000), $limits_flags)) // 0b 0010 0000
{
if (is_flag_set(bindec(100000), $limits_flags)) { // 0b 0010 0000
$options['limit_high_warn'] = $entry['pduInputPhaseConfigCurrentUpperWarningThreshold'] * $scale_current;
}
if (is_flag_set(bindec(10000), $limits_flags)) // 0b 0001 0000
{
if (is_flag_set(bindec(10000), $limits_flags)) { // 0b 0001 0000
$options['limit_high'] = $entry['pduInputPhaseConfigCurrentUpperCriticalThreshold'] * $scale_current;
}
@ -223,22 +211,18 @@ foreach ($oids as $unit => $entry1)
// upperWarning (2),
// upperCritical (3)
// }
$options = array();
$options = [];
$limits_flags = base_convert(str_replace(' ', '', $entry['pduInputPhaseConfigVoltageEnabledThresholds']), 16, 10);
if (is_flag_set(bindec(10000000), $limits_flags)) // 0b 1000 0000
{
if (is_flag_set(bindec(10000000), $limits_flags)) { // 0b 1000 0000
$options['limit_low'] = $entry['pduInputPhaseConfigVoltageLowerCriticalThreshold'] * $scale;
}
if (is_flag_set(bindec(1000000), $limits_flags)) // 0b 0100 0000
{
if (is_flag_set(bindec(1000000), $limits_flags)) { // 0b 0100 0000
$options['limit_low_warn'] = $entry['pduInputPhaseConfigVoltageLowerWarningThreshold'] * $scale;
}
if (is_flag_set(bindec(100000), $limits_flags)) // 0b 0010 0000
{
if (is_flag_set(bindec(100000), $limits_flags)) { // 0b 0010 0000
$options['limit_high_warn'] = $entry['pduInputPhaseConfigVoltageUpperWarningThreshold'] * $scale;
}
if (is_flag_set(bindec(10000), $limits_flags)) // 0b 0001 0000
{
if (is_flag_set(bindec(10000), $limits_flags)) { // 0b 0001 0000
$options['limit_high'] = $entry['pduInputPhaseConfigVoltageUpperCriticalThreshold'] * $scale;
}
@ -279,7 +263,7 @@ foreach ($oids as $unit => $entry1)
}
}
$oids = snmpwalk_cache_twopart_oid($device, 'pduCircuitBreakerStatusEntry', array(), $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'pduCircuitBreakerStatusEntry', [], $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'pduCircuitBreakerConfigLowerCriticalThreshold', $oids, $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'pduCircuitBreakerConfigLowerWarningThreshold', $oids, $mib);
@ -288,10 +272,8 @@ $oids = snmpwalk_cache_twopart_oid($device, 'pduCircuitBreakerConfigUpperWarning
$oids = snmpwalk_cache_twopart_oid($device, 'pduCircuitBreakerConfigEnabledThresholds', $oids, $mib);
print_debug_vars($oids);
foreach ($oids as $unit => $entry1)
{
foreach ($entry1 as $i => $entry)
{
foreach ($oids as $unit => $entry1) {
foreach ($entry1 as $i => $entry) {
if ($entry['pduCircuitBreakerStatusCount'] < 1) { continue; } // Skip not exist Circuit Breaker
$name = "Unit $unit, Circuit Breaker $i";
@ -315,22 +297,18 @@ foreach ($oids as $unit => $entry1)
// upperWarning (2),
// upperCritical (3)
// }
$options = array();
$options = [];
$limits_flags = base_convert(str_replace(' ', '', $entry['pduCircuitBreakerConfigEnabledThresholds']), 16, 10);
if (is_flag_set(bindec(10000000), $limits_flags)) // 0b 1000 0000
{
if (is_flag_set(bindec(10000000), $limits_flags)) { // 0b 1000 0000
$options['limit_low'] = $entry['pduCircuitBreakerConfigLowerCriticalThreshold'] * $scale_current;
}
if (is_flag_set(bindec(1000000), $limits_flags)) // 0b 0100 0000
{
if (is_flag_set(bindec(1000000), $limits_flags)) { // 0b 0100 0000
$options['limit_low_warn'] = $entry['pduCircuitBreakerConfigLowerWarningThreshold'] * $scale_current;
}
if (is_flag_set(bindec(100000), $limits_flags)) // 0b 0010 0000
{
if (is_flag_set(bindec(100000), $limits_flags)) { // 0b 0010 0000
$options['limit_high_warn'] = $entry['pduCircuitBreakerConfigUpperWarningThreshold'] * $scale_current;
}
if (is_flag_set(bindec(10000), $limits_flags)) // 0b 0001 0000
{
if (is_flag_set(bindec(10000), $limits_flags)) { // 0b 0001 0000
$options['limit_high'] = $entry['pduCircuitBreakerConfigUpperCriticalThreshold'] * $scale_current;
}
@ -347,14 +325,13 @@ foreach ($oids as $unit => $entry1)
// NOTE, next part not tested, but should be working (mike)
$sensors_count = 0;
foreach ($units as $entry)
{
foreach ($units as $entry) {
$sensors_count += $entry['pduUnitPropertiesConnExternalSensorCount'];
}
if ($sensors_count == 0) { return; } // Skip next sensors discovery (not exist)
$oids = snmpwalk_cache_twopart_oid($device, 'pduExternalSensorStatusEntry', array(), $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'pduExternalSensorStatusEntry', [], $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'pduExternalSensorNamePlateType', $oids, $mib);
$oids = snmpwalk_cache_twopart_oid($device, 'pduExternalSensorNamePlateUnits', $oids, $mib);
@ -366,10 +343,8 @@ $oids = snmpwalk_cache_twopart_oid($device, 'pduExternalSensorConfigUpperWarning
$oids = snmpwalk_cache_twopart_oid($device, 'pduExternalSensorConfigEnabledThresholds', $oids, $mib);
print_debug_vars($oids);
foreach ($oids as $unit => $entry1)
{
foreach ($entry1 as $i => $entry)
{
foreach ($oids as $unit => $entry1) {
foreach ($entry1 as $i => $entry) {
if ($entry['pduExternalSensorStatusState'] === 'notPresent') { continue; } // Skip not exist Sensors
$name = "Unit $unit, Sensor ".$entry['pduExternalSensorStatusName'];
@ -394,22 +369,18 @@ foreach ($oids as $unit => $entry1)
// upperWarning (2),
// upperCritical (3)
// }
$options = array();
$options = [];
$limits_flags = base_convert(str_replace(' ', '', $entry['pduExternalSensorConfigEnabledThresholds']), 16, 10);
if (is_flag_set(bindec(10000000), $limits_flags)) // 0b 1000 0000
{
if (is_flag_set(bindec(10000000), $limits_flags)) { // 0b 1000 0000
$options['limit_low'] = $entry['pduExternalSensorConfigLowerCriticalThreshold'] * $scale;
}
if (is_flag_set(bindec(1000000), $limits_flags)) // 0b 0100 0000
{
if (is_flag_set(bindec(1000000), $limits_flags)) { // 0b 0100 0000
$options['limit_low_warn'] = $entry['pduExternalSensorConfigLowerWarningThreshold'] * $scale;
}
if (is_flag_set(bindec(100000), $limits_flags)) // 0b 0010 0000
{
if (is_flag_set(bindec(100000), $limits_flags)) { // 0b 0010 0000
$options['limit_high_warn'] = $entry['pduExternalSensorConfigUpperWarningThreshold'] * $scale;
}
if (is_flag_set(bindec(10000), $limits_flags)) // 0b 0001 0000
{
if (is_flag_set(bindec(10000), $limits_flags)) { // 0b 0001 0000
$options['limit_high'] = $entry['pduExternalSensorConfigUpperCriticalThreshold'] * $scale;
}
@ -427,8 +398,7 @@ foreach ($oids as $unit => $entry1)
// modbusAdapter (17),
// hidAdapter (18)
// }
switch ($entry['pduExternalSensorNamePlateType'])
{
switch ($entry['pduExternalSensorNamePlateType']) {
case 'temperature':
case 'humidity':
$sensor_class = $entry['pduExternalSensorNamePlateType'];
@ -439,13 +409,11 @@ foreach ($oids as $unit => $entry1)
default:
continue 2;
}
if ($entry['pduExternalSensorNamePlateUnits'] === 'degreeF')
{
if ($entry['pduExternalSensorNamePlateUnits'] === 'degreeF') {
$options['sensor_unit'] = 'F';
}
if (isset($entry['pduExternalSensorStatusHighPrecisionValue'])) // && $entry['pduExternalSensorStatusHighPrecisionValue'] > 0)
{
if (isset($entry['pduExternalSensorStatusHighPrecisionValue'])) { // && $entry['pduExternalSensorStatusHighPrecisionValue'] > 0)
$scale = 0.1;
$oid_name = 'pduExternalSensorStatusHighPrecisionValue';
$oid_num = ".1.3.6.1.4.1.38446.1.6.4.1.8.$index";

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,70 +6,199 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2015 Adam Armstrong
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
echo('Caching OIDs: ');
$ups_array = array();
$InputTableCount = snmp_get($device, 'upsESystemInputNumPhases.0', '-OQv', $mib);
echo('upsESystemInputTable ('.$InputTableCount.' entries)');
$ups_array = snmpwalk_cache_oid($device, 'upsESystemInputTable', $ups_array, $mib);
$OutputTableCount = snmp_get($device, 'upsESystemOutputNumPhase.0', '-OQv', $mib);
echo('upsESystemOutputTable ('.$OutputTableCount.' entries)');
$ups_array = snmpwalk_cache_oid($device, 'upsESystemOutputTable', $ups_array, $mib);
$BypassTableCount = snmp_get($device, 'upsESystemBypassNumPhase.0', '-OQv', $mib);
echo('upsESystemBypassTable ('.$BypassTableCount.' entries)');
$ups_array = snmpwalk_cache_oid($device, 'upsESystemBypassTable', $ups_array, $mib);
$scale = 0.1;
$nominal = snmp_get($device, 'upsESystemConfigOutputVoltage.0', '-OQv', $mib) * $scale;
$voltage_limits = array('limit_high' => ($nominal * 1.03), 'limit_high_warn' => ($nominal * 1.01), 'limit_low' => ($nominal * 0.97), 'limit_low_warn' => ($nominal * 0.99));
# Input Sensors
for ($index = 1; $index <= $InputTableCount; $index++)
{
$data = $ups_array[$index];
$descr = 'Input';
$oid = '.1.3.6.1.4.1.935.10.1.1.2.16.1.3.'.$index; # EPPC-MIB:upsESystemInputVoltage.$index
$value = $data['upsESystemInputVoltage'];
discover_sensor('voltage', $device, $oid, "upsESystemInputVoltage.$index", 'eppc-mib', $descr, 0.1, $value, $voltage_limits);
// EPPC-MIB::upsESystemConfigInputVoltage.0 = INTEGER: 2300
// EPPC-MIB::upsESystemConfigInputFrequence.0 = INTEGER: 500
// EPPC-MIB::upsESystemInputSourceNum.0 = INTEGER: 1
// EPPC-MIB::upsESystemInputLineBads.0 = Counter32: 0
// EPPC-MIB::upsESystemInputNumPhases.0 = INTEGER: 1
// EPPC-MIB::upsESystemInputFrequency.1 = INTEGER: 500
// EPPC-MIB::upsESystemInputVoltage.1 = INTEGER: 2301
// EPPC-MIB::upsESystemInputCurrent.1 = INTEGER: -1
// EPPC-MIB::upsESystemInputWatts.1 = INTEGER: -1
$input_phases = snmp_get_oid($device, 'upsESystemInputNumPhases.0', $mib);
if ($input_phases > 0) {
echo('upsESystemInputTable ('.$input_phases.' phases)');
$descr = "Input";
$oid = ".1.3.6.1.4.1.935.10.1.1.2.16.1.2.".$index; # EPPC-MIB:upsESystemInputFrequency.$index
$value = $data['upsESystemInputFrequency'];
$limits = array('limit_high' => 55, 'limit_high_warn' => 51, 'limit_low' => 45, 'limit_low_warn' => 49);
discover_sensor('frequency', $device, $oid, "upsESystemInputFrequency.$index", 'eppc-mib', $descr, 0.1, $value, $limits);
$scale = 0.1;
$ups_array = snmpwalk_cache_oid($device, 'upsESystemInputTable', [], $mib);
$input_voltage = snmp_get_oid($device, 'upsESystemConfigInputVoltage.0', $mib) * $scale;
if ($input_voltage > 0) {
$voltage_limits = [
'limit_high' => $input_voltage * 1.03, 'limit_high_warn' => $input_voltage * 1.01,
'limit_low' => $input_voltage * 0.97, 'limit_low_warn' => $input_voltage * 0.99
];
} else {
$voltage_limits = [];
}
$input_frequency = snmp_get_oid($device, 'upsESystemConfigInputFrequence.0', $mib) * $scale;
if ($input_frequency > 0) {
$frequency_limits = [
'limit_high' => $input_frequency * 1.10, 'limit_high_warn' => $input_frequency * 1.02,
'limit_low' => $input_frequency * 0.90, 'limit_low_warn' => $input_frequency * 0.98
];
} else {
$frequency_limits = [];
}
foreach ($ups_array as $phase => $entry) {
$descr = 'Input';
if ($input_phases > 1) {
$descr .= ' (Phase '.$phase.')';
}
$oid_name = 'upsESystemInputVoltage';
$oid_num = '.1.3.6.1.4.1.935.10.1.1.2.16.1.3.'.$phase;
$value = $entry[$oid_name];
$options = $voltage_limits;
$options['rename_rrd'] = "eppc-mib-upsESystemInputVoltage.%index%";
//discover_sensor('voltage', $device, $oid, "upsESystemInputVoltage.$index", 'eppc-mib', $descr, 0.1, $value, $voltage_limits);
discover_sensor_ng($device, 'voltage', $mib, $oid_name, $oid_num, $phase, NULL, $descr, $scale, $value, $options);
$oid_name = 'upsESystemInputFrequency';
$oid_num = '.1.3.6.1.4.1.935.10.1.1.2.16.1.2.'.$phase;
$value = $entry[$oid_name];
$options = $frequency_limits;
$options['rename_rrd'] = "eppc-mib-upsESystemInputFrequency.%index%";
//discover_sensor('frequency', $device, $oid, "upsESystemInputFrequency.$index", 'eppc-mib', $descr, 0.1, $value, $limits);
discover_sensor_ng($device, 'frequency', $mib, $oid_name, $oid_num, $phase, NULL, $descr, $scale, $value, $options);
if ($entry['upsESystemInputCurrent'] > 0) {
$oid_name = 'upsESystemInputCurrent';
$oid_num = '.1.3.6.1.4.1.935.10.1.1.2.16.1.4.'.$phase;
$value = $entry[$oid_name];
discover_sensor_ng($device, 'current', $mib, $oid_name, $oid_num, $phase, NULL, $descr, $scale, $value);
}
if ($entry['upsESystemInputWatts'] > 0) {
$oid_name = 'upsESystemInputWatts';
$oid_num = '.1.3.6.1.4.1.935.10.1.1.2.16.1.5.'.$phase;
$value = $entry[$oid_name];
discover_sensor_ng($device, 'power', $mib, $oid_name, $oid_num, $phase, NULL, $descr, 1, $value);
}
}
}
# Output Sensors
for ($index = 1; $index <= $InputTableCount; $index++)
{
$data = $ups_array[$index];
// EPPC-MIB::upsESystemConfigOutputVoltage.0 = INTEGER: -1
// EPPC-MIB::upsESystemConfigOutputFrequency.0 = INTEGER: -1
// EPPC-MIB::upsESystemConfigOutputVA.0 = INTEGER: -1
// EPPC-MIB::upsESystemConfigOutputPower.0 = INTEGER: -1
// EPPC-MIB::upsESystemConfigOutputLoadHighSetPoint.0 = INTEGER: 90
// EPPC-MIB::upsESystemOutputNumPhase.0 = INTEGER: 1
// EPPC-MIB::upsESystemOutputFrequency.1 = INTEGER: 500
// EPPC-MIB::upsESystemOutputVoltage.1 = INTEGER: 2299
// EPPC-MIB::upsESystemOutputCurrent.1 = INTEGER: 64
// EPPC-MIB::upsESystemOutputWatts.1 = INTEGER: 1300
// EPPC-MIB::upsESystemOutputVA.1 = INTEGER: 1400
// EPPC-MIB::upsESystemOutputLoad.1 = INTEGER: 24
$descr = "Output";
$oid = ".1.3.6.1.4.1.935.10.1.1.2.18.1.3.$index"; # EPPC-MIB:upsESystemOutputVoltage.$index
$value = $data['upsESystemOutputVoltage'];
discover_sensor('voltage', $device, $oid, "upsESystemOutputVoltage.$index", 'eppc-mib', $descr, 0.1, $value, $voltage_limits);
$output_phases = snmp_get_oid($device, 'upsESystemOutputNumPhase.0', $mib);
if ($output_phases > 0) {
echo('upsESystemOutputTable (' . $output_phases . ' phases)');
$descr = "Output";
$oid = ".1.3.6.1.4.1.935.10.1.1.2.18.1.2.$index"; # EPPC-MIB:upsESystemOutputFrequency.$index
$value = $data['upsESystemOutputFrequency'];
$limits = array('limit_high' => 55, 'limit_high_warn' => 51, 'limit_low' => 45, 'limit_low_warn' => 49); // FIXME orly? 50Hz only?
discover_sensor('frequency', $device, $oid, "upsESystemOutputFrequency.$index", 'eppc-mib', $descr, 0.1, $value, $limits);
$scale = 0.1;
$ups_array = snmpwalk_cache_oid($device, 'upsESystemOutputTable', [], $mib);
$descr = "Output";
$oid = ".1.3.6.1.4.1.935.10.1.1.2.18.1.7.$index"; # EPPC-MIB:upsESystemOutputLoad.$index
$value = $data['upsESystemOutputLoad'];
$limits = array('limit_high' => 100, 'limit_high_warn' => 75, 'limit_low' => 0);
discover_sensor('load', $device, $oid, "upsESystemOutputLoad.$index", 'eppc-mib', $descr, 1, $value, $limits);
$output_voltage = snmp_get_oid($device, 'upsESystemConfigOutputVoltage.0', $mib) * $scale;
if ($output_voltage > 0) {
$voltage_limits = [
'limit_high' => $output_voltage * 1.03, 'limit_high_warn' => $output_voltage * 1.01,
'limit_low' => $output_voltage * 0.97, 'limit_low_warn' => $output_voltage * 0.99
];
} else {
// Keep input voltage limits
//$voltage_limits = [];
}
$output_frequency = snmp_get_oid($device, 'upsESystemConfigOutputFrequency.0', $mib) * $scale;
if ($output_frequency > 0) {
$frequency_limits = [
'limit_high' => $output_frequency * 1.10, 'limit_high_warn' => $output_frequency * 1.02,
'limit_low' => $output_frequency * 0.90, 'limit_low_warn' => $output_frequency * 0.98
];
} else {
// Keep input frequency limits
//$frequency_limits = [];
}
foreach ($ups_array as $phase => $entry) {
$descr = 'Output';
if ($input_phases > 1) {
$descr .= ' (Phase ' . $phase . ')';
}
$oid_name = 'upsESystemOutputVoltage';
$oid_num = ".1.3.6.1.4.1.935.10.1.1.2.18.1.3.$index";
$value = $entry[$oid_name];
$options = $voltage_limits;
$options['rename_rrd'] = "eppc-mib-upsESystemOutputVoltage.%index%";
//discover_sensor('voltage', $device, $oid, "upsESystemOutputVoltage.$index", 'eppc-mib', $descr, 0.1, $value, $voltage_limits);
discover_sensor_ng($device, 'voltage', $mib, $oid_name, $oid_num, $phase, NULL, $descr, $scale, $value, $options);
$oid_name = 'upsESystemOutputFrequency';
$oid_num = ".1.3.6.1.4.1.935.10.1.1.2.18.1.2.$index";
$value = $entry[$oid_name];
$options = $frequency_limits;
$options['rename_rrd'] = "eppc-mib-upsESystemOutputFrequency.%index%";
//discover_sensor('frequency', $device, $oid, "upsESystemOutputFrequency.$index", 'eppc-mib', $descr, 0.1, $value, $limits);
discover_sensor_ng($device, 'frequency', $mib, $oid_name, $oid_num, $phase, NULL, $descr, $scale, $value, $options);
$oid_name = 'upsESystemOutputLoad';
$oid_num = ".1.3.6.1.4.1.935.10.1.1.2.18.1.7.$index";
$value = $entry[$oid_name];
$options = [ 'limit_high' => 90, 'limit_high_warn' => 75 ];
$options['rename_rrd'] = "eppc-mib-upsESystemOutputLoad.%index%";
//discover_sensor('load', $device, $oid, "upsESystemOutputLoad.$index", 'eppc-mib', $descr, 1, $value, $limits);
discover_sensor_ng($device, 'load', $mib, $oid_name, $oid_num, $phase, NULL, $descr, 1, $value, $options);
if ($entry['upsESystemOutputCurrent'] > 0) {
$oid_name = 'upsESystemOutputCurrent';
$oid_num = '.1.3.6.1.4.1.935.10.1.1.2.18.1.4.'.$phase;
$value = $entry[$oid_name];
discover_sensor_ng($device, 'current', $mib, $oid_name, $oid_num, $phase, NULL, $descr, $scale, $value);
}
if ($entry['upsESystemOutputWatts'] > 0) {
$oid_name = 'upsESystemOutputWatts';
$oid_num = '.1.3.6.1.4.1.935.10.1.1.2.18.1.5.'.$phase;
$value = $entry[$oid_name];
discover_sensor_ng($device, 'power', $mib, $oid_name, $oid_num, $phase, NULL, $descr, 1, $value);
}
if ($entry['upsESystemOutputVA'] > 0) {
$oid_name = 'upsESystemOutputVA';
$oid_num = '.1.3.6.1.4.1.935.10.1.1.2.18.1.6.'.$phase;
$value = $entry[$oid_name];
discover_sensor_ng($device, 'apower', $mib, $oid_name, $oid_num, $phase, NULL, $descr, 1, $value);
}
}
}
// FIXME Sensors below are a definite candidate for definition-based discovery
# bypass sensors
// EPPC-MIB::upsESystemBypassNumPhase.0 = INTEGER: -1
$bypass_phases = snmp_get_oid($device, 'upsESystemBypassNumPhase.0', $mib);
if ($bypass_phases > 0) {
echo('upsESystemBypassTable (' . $bypass_phases . ' phases)');
$ups_array = snmpwalk_cache_oid($device, 'upsESystemBypassTable', [], $mib);
}
/* FIXME Sensors below are a definite candidate for definition-based discovery
$descr = 'Charge Remaining';
$oid = '.1.3.6.1.4.1.935.10.1.1.3.4.0'; # EPPC-MIB:upsEBatteryEstimatedChargeRemaining
@ -96,7 +224,7 @@ $high = snmp_get($device, 'upsEEnvironmentTemperatureHighSetPoint.0', '-OQv',
$low = snmp_get($device, 'upsEEnvironmentTemperatureLowSetPoint.0', '-OQv', $mib);
$limits = array('limit_high' => $high * $scale, 'limit_high_warn' => ($high * $scale) * .75, 'limit_low' => $low * $scale);
discover_sensor('temperature', $device, $oid, 'upsESystemTemperature', 'eppc-mib', $descr, $scale, $value, $limits); // FIXME should be upsESystemTemperature.0
*/
unset($limits, $ups_array);
// EOF

View File

@ -6,18 +6,17 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Currently not possible convert to definitions because type detection is hard, based on descriptions
// SAME code in ATEN-IPMI-MIB
$oids = snmpwalk_multipart_oid($device, "fgHwSensorTable", array(), "FORTINET-FORTIGATE-MIB");
$oids = snmpwalk_multipart_oid($device, "fgHwSensorTable", [], "FORTINET-FORTIGATE-MIB");
print_debug_vars($oids);
foreach ($oids as $index => $entry)
{
foreach ($oids as $index => $entry) {
$descr = $entry['fgHwSensorEntName'];
$oid_name = 'fgHwSensorEntValue';
@ -25,6 +24,8 @@ foreach ($oids as $index => $entry)
$scale = 1;
$value = $entry[$oid_name];
if (empty($descr) && $value == 0) { continue; }
// Detect class based on descr anv value (this is derp, table not have other data for detect class
if (str_iends($descr, ' Temp')) {
if ($value == 0) { continue; }
@ -58,7 +59,10 @@ foreach ($oids as $index => $entry)
$class = 'temperature';
}
discover_sensor_ng($device, $class, $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value);
discover_status_ng($device, $mib, `fgHwSensorEntAlarmStatus`, '.1.3.6.1.4.1.12356.101.4.3.2.1.4.'.$index, $index,
'fgHwSensorEntAlarmStatus', $descr, $entry['fgHwSensorEntAlarmStatus']);
discover_sensor_ng($device, $class, $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value);
}
// EOF

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -105,6 +105,7 @@ $entity_array = [];
*/
$power_class = 'power';
$power_scale = 0.000001;
$power_scale_multi = 0.01;
foreach (snmpwalk_cache_oid($device, 'hwEntityOpticalTemperature', [], 'HUAWEI-ENTITY-EXTENT-MIB') as $index => $entry) {
// Ignore optical sensors with temperature of zero or negative
if ($entry['hwEntityOpticalTemperature'] > 1) {
@ -223,25 +224,40 @@ foreach ($entity_array as $index => $entry) {
}
if ($multilane) {
// Fix incorrect Power scale.. again
// See: https://jira.observium.org/browse/OBS-4148
/*
hwEntityOpticalRxPower.16850463 = -121
hwEntityOpticalRxHighThreshold.16850463 = 400
hwEntityOpticalRxHighWarnThreshold.16850463 = No Such Object available on this agent at this OID
hwEntityOpticalRxLowThreshold.16850463 = -1801
hwEntityOpticalRxLowWarnThreshold.16850463 = No Such Object available on this agent at this OID
hwEntityOpticalLaneRxPower.16850463 = -1.21,-1.51,-1.83,-2.18
*/
list($lane1_rxpower) = explode(',', $entry['hwEntityOpticalLaneRxPower']);
if (($entry['hwEntityOpticalRxPower'] != -1) && float_cmp($entry['hwEntityOpticalRxPower'] * 0.01, $lane1_rxpower, 0.01) === 0) {
$power_scale_multi = 1;
}
$rxoptions['sensor_unit'] = 'split1';
$lane_descr = $entry['ifDescr'] . ' Lane 1 Rx Power' . $trans;
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, 0.01, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, $power_scale_multi, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
$rxoptions['sensor_unit'] = 'split2';
$lane_descr = $entry['ifDescr'] . ' Lane 2 Rx Power' . $trans;
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, 0.01, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, $power_scale_multi, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
$rxoptions['sensor_unit'] = 'split3';
$lane_descr = $entry['ifDescr'] . ' Lane 3 Rx Power' . $trans;
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, 0.01, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, $power_scale_multi, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
$rxoptions['sensor_unit'] = 'split4';
$lane_descr = $entry['ifDescr'] . ' Lane 4 Rx Power' . $trans;
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, 0.01, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, $power_scale_multi, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
} else {
$rxoptions['rename_rrd'] = "HUAWEI-ENTITY-EXTENT-MIB-hwEntityOpticalRxPower-$index";
$lane_descr = $entry['ifDescr'] . ' Rx Power' . $trans;
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, 0.01, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneRxPower', $lane_oid, $index, NULL, $lane_descr, $power_scale_multi, $entry['hwEntityOpticalLaneRxPower'], $rxoptions);
}
} elseif ($entry['hwEntityOpticalRxPower'] != -1) {
// Huawei does not follow their own MIB for some devices and instead reports Rx/Tx Power as dBm converted to mW then multiplied by 1000
@ -275,21 +291,36 @@ foreach ($entity_array as $index => $entry) {
}
if ($multilane) {
// Fix incorrect Power scale.. again
// See: https://jira.observium.org/browse/OBS-4148
/*
hwEntityOpticalTxPower.16850463 = -25
hwEntityOpticalTxHighThreshold.16850463 = 400
hwEntityOpticalTxHighWarnThreshold.16850463 = No Such Object available on this agent at this OID
hwEntityOpticalTxLowThreshold.16850463 = -1060
hwEntityOpticalTxLowWarnThreshold.16850463 = No Such Object available on this agent at this OID
hwEntityOpticalLaneTxPower.16850463 = -0.25,-0.26,-0.26,-0.23
*/
list($lane1_txpower) = explode(',', $entry['hwEntityOpticalLaneTxPower']);
if (($entry['hwEntityOpticalTxPower'] != -1) && float_cmp($entry['hwEntityOpticalTxPower'] * 0.01, $lane1_txpower, 0.01) === 0) {
$power_scale_multi = 1;
}
$txoptions['sensor_unit'] = 'split1';
$lane_descr = $entry['ifDescr'] . ' Lane 1 Tx Power' . $trans;
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneTxPower', $lane_oid, $index, NULL, $lane_descr, 0.01, $entry['hwEntityOpticalLaneTxPower'], $txoptions);
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneTxPower', $lane_oid, $index, NULL, $lane_descr, $power_scale_multi, $entry['hwEntityOpticalLaneTxPower'], $txoptions);
$txoptions['sensor_unit'] = 'split2';
$lane_descr = $entry['ifDescr'] . ' Lane 2 Tx Power' . $trans;
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneTxPower', $lane_oid, $index, NULL, $lane_descr, 0.01, $entry['hwEntityOpticalLaneTxPower'], $txoptions);
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneTxPower', $lane_oid, $index, NULL, $lane_descr, $power_scale_multi, $entry['hwEntityOpticalLaneTxPower'], $txoptions);
$txoptions['sensor_unit'] = 'split3';
$lane_descr = $entry['ifDescr'] . ' Lane 3 Tx Power' . $trans;
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneTxPower', $lane_oid, $index, NULL, $lane_descr, 0.01, $entry['hwEntityOpticalLaneTxPower'], $txoptions);
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneTxPower', $lane_oid, $index, NULL, $lane_descr, $power_scale_multi, $entry['hwEntityOpticalLaneTxPower'], $txoptions);
$txoptions['sensor_unit'] = 'split4';
$lane_descr = $entry['ifDescr'] . ' Lane 4 Tx Power' . $trans;
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneTxPower', $lane_oid, $index, NULL, $lane_descr, 0.01, $entry['hwEntityOpticalLaneTxPower'], $txoptions);
discover_sensor_ng($device, 'dbm', $mib, 'hwEntityOpticalLaneTxPower', $lane_oid, $index, NULL, $lane_descr, $power_scale_multi, $entry['hwEntityOpticalLaneTxPower'], $txoptions);
} else {
$txoptions['rename_rrd'] = "HUAWEI-ENTITY-EXTENT-MIB-hwEntityOpticalTxPower-$index";
$lane_descr = $entry['ifDescr'] . ' Tx Power' . $trans;

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -19,7 +18,7 @@
//POWER-ETHERNET-MIB::pethMainPseConsumptionPower.10 = Gauge32: 0 Watts
//POWER-ETHERNET-MIB::pethMainPseConsumptionPower.11 = Gauge32: 1 Watts
$oids = snmpwalk_cache_oid($device, 'pethMainPseTable', array(), 'POWER-ETHERNET-MIB');
$oids = snmpwalk_cache_oid($device, 'pethMainPseTable', [], 'POWER-ETHERNET-MIB');
//NETONIX-SWITCH-MIB::poeStatus.10 = STRING: Off
//NETONIX-SWITCH-MIB::poeStatus.11 = STRING: 48V
@ -30,14 +29,12 @@ print_debug_vars($oids);
////// Per-port Statistics
foreach ($oids as $index => $entry)
{
$options = array('entPhysicalIndex' => $index);
foreach ($oids as $index => $entry) {
$options = [ 'entPhysicalIndex' => $index ];
$port = get_port_by_ifIndex($device['device_id'], $index);
// print_vars($port);
if (is_array($port))
{
if (is_array($port)) {
$entry['ifDescr'] = $port['port_label'];
$options['measured_class'] = 'port';
$options['measured_entity'] = $port['port_id'];
@ -55,8 +52,7 @@ foreach ($oids as $index => $entry)
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, $options);
if ($entry['pethMainPseOperStatus'] != 'off')
{
if ($entry['pethMainPseOperStatus'] != 'off') {
$descr = $entry['ifDescr'] . ' PoE Power';
$oid_name = 'pethMainPseConsumptionPower';

View File

@ -1407,7 +1407,7 @@ foreach ($cache['apc'] as $index => $entry)
$descr = $entry['uioSensorStatusSensorName'];
$status = $entry['uioSensorStatusCommStatus'];
if ($status != 'commsOK') { continue; } // Skip unconnected sensors entirely
if ($status !== 'commsOK') { continue; } // Skip unconnected sensors entirely
// Humidity
$value = $entry['uioSensorStatusHumidity'];
@ -1417,7 +1417,7 @@ foreach ($cache['apc'] as $index => $entry)
if ($value != '' && $value > 0) // Humidity = 0 or -1 -> Sensor not available
{
// Skip if already discovered through iem
if (!in_array($descr, $iem_sensors['humidity']))
if (!in_array($descr, (array)$iem_sensors['humidity']))
{
//discover_sensor('humidity', $device, $oid, "uioSensorStatusHumidity.$index", 'apc', $descr, 1, $value);
$options = [ 'rename_rrd' => 'apc-uioSensorStatusHumidity.%index%' ];
@ -1435,7 +1435,7 @@ foreach ($cache['apc'] as $index => $entry)
if ($value != '' && $value != -1) // Temperature = -1 -> Sensor not available
{
// Skip if already discovered through iem
if (!in_array($descr, $iem_sensors['temperature']))
if (!in_array($descr, (array)$iem_sensors['temperature']))
{
//discover_sensor('temperature', $device, $oid, "uioSensorStatusTemperatureDegC.$index", 'apc', $descr, 1, $value);
$options = [ 'rename_rrd' => 'apc-uioSensorStatusTemperatureDegC.%index%' ];

View File

@ -0,0 +1,215 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Inlets
// PWTv1-MIB::pduPwrMonitoringInletNum.0 = INTEGER: 1
// PWTv1-MIB::inletIndex.1 = INTEGER: 0
// PWTv1-MIB::inletPowerAll.1 = INTEGER: 11114 0.1W
// PWTv1-MIB::inletResetFrom.1 = STRING: "07/02/2022 15:40:15"
// PWTv1-MIB::inletEnergy.1 = INTEGER: 10526559 KWh
// PWTv1-MIB::inletStatus.1 = INTEGER: normal(1)
// PWTv1-MIB::inletCurrPhase1.1 = INTEGER: 526 0.01A
// PWTv1-MIB::inletCurrPhase2.1 = INTEGER: 0 0.01A
// PWTv1-MIB::inletCurrPhase3.1 = INTEGER: 0 0.01A
// PWTv1-MIB::inletVoltPhase1.1 = INTEGER: 2291 0.1V
// PWTv1-MIB::inletVoltPhase2.1 = INTEGER: 0 0.1V
// PWTv1-MIB::inletVoltPhase3.1 = INTEGER: 0 0.1V
// PWTv1-MIB::inletPowerPhase1.1 = INTEGER: 11114 0.1W
// PWTv1-MIB::inletPowerPhase2.1 = INTEGER: 0 0.1W
// PWTv1-MIB::inletPowerPhase3.1 = INTEGER: 0 0.1W
$inlet_count = snmp_get_oid($device, 'pduPwrMonitoringInletNum.0', 'PWTv1-MIB');
$oids = snmpwalk_cache_oid($device, 'pduPwrMonitoringInletStatusTable', [], 'PWTv1-MIB');
$oids = snmpwalk_cache_oid($device, 'pduPwrMonitoringInletCfgTable', $oids, 'PWTv1-MIB');
foreach ($oids as $index => $entry) {
// PDU reports all inlets as "normal" status, but really only as in count
if ($index > $inlet_count) { break; }
$name = $inlet_count > 1 ? " #$index" : '';
$descr = "Inlet Total".$name;
$oid_num = ".1.3.6.1.4.1.42610.1.4.4.1.6.1.2.1.2.$index";
$oid_name = 'inletPowerAll';
$value = $entry[$oid_name];
$scale = 0.1;
$options = [
'limit_high' => $entry['inletCfgLoadCritical'] * 1000 * $scale,
'limit_high_warn' => $entry['inletCfgLoadWarning'] * 1000 * $scale
];
discover_sensor_ng($device, 'power', $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, $options);
$descr = "Inlet Total".$name;
$oid_num = ".1.3.6.1.4.1.42610.1.4.4.1.6.1.2.1.4.$index";
$oid_name = 'inletEnergy';
$value = $entry[$oid_name];
$scale = 1000;
$options = [];
discover_counter($device, 'energy', $mib, $oid_name, $oid_num, $index, $descr, $scale, $value, $options);
$descr = "Inlet".$name;
$oid_num = ".1.3.6.1.4.1.42610.1.4.4.1.6.1.2.1.5.$index";
$oid_name = 'inletStatus';
$value = $entry[$oid_name];
$options = [];
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, 'inletStatus', $descr, $value, $options);
$phase_count = ($entry['inletVoltPhase2'] > 0) || ($entry['inletVoltPhase3'] > 0) ? 3 : 1;
for ($phase = 1; $phase <= $phase_count; $phase++) {
$phase_name = $phase_count > 1 ? " (Phase $phase)" : '';
$descr = "Inlet".$name.$phase_name;
$oid_name = 'inletCurrPhase'.$phase;
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$scale = 0.1;
$options = [
'limit_high' => $entry['inletCfgTotalCurrCritPhase'.$phase] * $scale,
'limit_high_warn' => $entry['inletCfgTotalCurrWarnPhase'.$phase] * $scale
];
discover_sensor_ng($device, 'current', $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, $options);
$descr = "Inlet".$name.$phase_name;
$oid_name = 'inletVoltPhase'.$phase;
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$scale = 0.1;
$options = [
'limit_high' => $entry['inletCfgVoltCritPhase'.$phase] * $scale,
'limit_high_warn' => $entry['inletCfgVoltWarnPhase'.$phase] * $scale
];
discover_sensor_ng($device, 'voltage', $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, $options);
$descr = "Inlet".$name.$phase_name;
$oid_name = 'inletFreqPhase'.$phase;
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$scale = 0.01;
$options = [];
discover_sensor_ng($device, 'frequency', $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, $options);
if ($phase_count > 1) {
// Three Phase
$descr = "Inlet".$name.$phase_name;
$oid_name = 'inletPowerPhase'.$phase;
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$scale = 0.1;
$options = [];
discover_sensor_ng($device, 'power', $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, $options);
$descr = "Inlet".$name.$phase_name;
$oid_name = 'inletStatusPhase'.$phase;
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$options = [];
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, 'inletStatus', $descr, $value, $options);
}
}
}
// Outlets
// PWTv1-MIB::pduPwrMonitoringOutletNumPduA.0 = INTEGER: 0
// PWTv1-MIB::pduPwrMonitoringOutletNumPduB.0 = INTEGER: 0
// PWTv1-MIB::pduPwrMonitoringOutletNumPduC.0 = INTEGER: 0
// PWTv1-MIB::pduPwrMonitoringOutletNumPduD.0 = INTEGER: 0
// PWTv1-MIB::pduPwrMonitoringOutletNumPduE.0 = INTEGER: 0
// PWTv1-MIB::pduPwrMonitoringOutletNumPduF.0 = INTEGER: 0
// PWTv1-MIB::pduPwrMonitoringOutletNumPduG.0 = INTEGER: 0
// PWTv1-MIB::pduPwrMonitoringOutletNumPduH.0 = INTEGER: 0
// PWTv1-MIB::outletPduAIndex.11 = INTEGER: 10
// PWTv1-MIB::outletPduAState.11 = INTEGER: off(1)
// PWTv1-MIB::outletPduACurrent.11 = INTEGER: 0 0.01A
// PWTv1-MIB::outletPduAPwrFactor.11 = INTEGER: 0 0.1%
// PWTv1-MIB::outletPduAPower.11 = INTEGER: 0 0.1W
// PWTv1-MIB::outletPduAEnergy.11 = INTEGER: 0 KWh
// PWTv1-MIB::outletPduAResetFrom.11 = STRING: "07/02/2022 15:40:15"
// PWTv1-MIB::outletPduAStatus.11 = INTEGER: normal(1)
// PWTv1-MIB::outletPduAAppPower.11 = INTEGER: 0 0.1W
// PWTv1-MIB::outletPduAVoltage.11 = INTEGER: 0 0.1V
// PWTv1-MIB::outletCfgPduAIndex.11 = INTEGER: 10
// PWTv1-MIB::outletCfgPduAName.11 = STRING: "outlet 11"
// PWTv1-MIB::outletCfgPduADelayOnStatus.11 = INTEGER: nodelay(1)
// PWTv1-MIB::outletCfgPduADelayOnTime.11 = INTEGER: 11 seconds
// PWTv1-MIB::outletCfgPduADelayOffStatus.11 = INTEGER: nodelay(1)
// PWTv1-MIB::outletCfgPduADelayOffTime.11 = INTEGER: 11 seconds
// PWTv1-MIB::outletCfgPduAReboot.11 = INTEGER: 5 seconds
// PWTv1-MIB::outletCfgPduAOverCurrCritical.11 = INTEGER: 160 0.1A
// PWTv1-MIB::outletCfgPduAOverCurrWarning.11 = INTEGER: 130 0.1A
// PWTv1-MIB::outletCfgPduAOverPwrCritical.11 = INTEGER: 2500 1W
// PWTv1-MIB::outletCfgPduAOverPwrWarning.11 = INTEGER: 2000 1W
// PWTv1-MIB::outletCtlPduAIndex.11 = INTEGER: 10
// PWTv1-MIB::outletCtlPduAControl.11 = INTEGER: nothing(1)
foreach ([ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' ] as $char) {
if ($outlet_count = snmp_get_oid($device, "pduPwrMonitoringOutletNumPdu{$char}.0", 'PWTv1-MIB')) {
$oids = snmpwalk_cache_oid($device, 'pduPwrMonitoringOutletStatusTablePdu'.$char, [], 'PWTv1-MIB');
$oids = snmpwalk_cache_oid($device, 'pduPwrMonitoringOutletCfgTablePdu'.$char, $oids, 'PWTv1-MIB');
$name = "Pdu $char";
foreach ($oids as $index => $entry) {
// PDU reports all outlets as "normal" status, but really only as in count
if ($index > $outlet_count) { break; }
$descr = "Outlet $index State ($name)";
$oid_name = "outletPdu{$char}State";
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$options = [];
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, 'outletPduState', $descr, $value, $options);
$descr = "Outlet $index ($name)";
$oid_name = "outletPdu{$char}Current";
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$scale = 0.01;
$options = [
'limit_high' => $entry["outletCfgPdu{$char}OverCurrCritical"] * 0.1,
'limit_high_warn' => $entry["outletCfgPdu{$char}OverCurrWarning"] * 0.1
];
discover_sensor_ng($device, 'current', $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, $options);
$descr = "Outlet $index ($name)";
$oid_name = "outletPdu{$char}Power";
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$scale = 0.1;
$options = [
'limit_high' => $entry["outletCfgPdu{$char}OverPwrCritical"],
'limit_high_warn' => $entry["outletCfgPdu{$char}OverPwrWarning"]
];
discover_sensor_ng($device, 'power', $mib, $oid_name, $oid_num, $index, NULL, $descr, $scale, $value, $options);
$descr = "Outlet $index ($name)";
$oid_name = "outletPdu{$char}Energy";
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$scale = 1000;
$options = [];
if ($value > 0) {
discover_counter($device, 'energy', $mib, $oid_name, $oid_num, $index, $descr, $scale, $value, $options);
}
$descr = "Outlet $index ($name)";
$oid_name = "outletPdu{$char}Status";
$oid_num = snmp_translate($oid_name, $mib).".$index";
$value = $entry[$oid_name];
$options = [];
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, 'inletStatus', $descr, $value, $options);
}
}
}
unset($inlet_count, $phase_count, $oids, $outlet_count);
// EOF

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -91,7 +91,7 @@ foreach ($physicalConnectorEntry as $ifIndex => $entry)
//print_debug_vars($options);
$name = $options['port_label'];
$name_ext = " (${entry['portMfgName']} ${entry['portVendorPartNo']} ${entry['physicalConnectorString']})";
$name_ext = " ({$entry['portMfgName']} {$entry['portVendorPartNo']} {$entry['physicalConnectorString']})";
// Temperature
$descr = $name . ' Temperature' . $name_ext;

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -43,10 +43,10 @@ $temp_unit = snmp_get_oid($device, 'cmcIIISetTempUnit.0', $mib);
//RITTAL-CMC-III-MIB::cmcIIIVarName.1.26 = STRING: Input 2.Delay
//RITTAL-CMC-III-MIB::cmcIIIVarName.1.27 = STRING: Input 2.Status
//RITTAL-CMC-III-MIB::cmcIIIVarName.1.28 = STRING: Input 2.Category
$oids = snmpwalk_cache_oid($device, "cmcIIIVarTable", array(), $mib);
$oids = snmpwalk_cache_oid($device, "cmcIIIVarTable", [], $mib);
//print_debug_vars($oids);
$device_oids = snmpwalk_cache_oid($device, "cmcIIIDevTable", array(), $mib);
$device_oids = snmpwalk_cache_oid($device, "cmcIIIDevTable", [], $mib);
print_debug_vars($device_oids);
$device_names = [];
@ -68,7 +68,7 @@ foreach ($device_oids as $index => $entry) {
}
// Rearrage this dumb array as more logic
$device_sensors = array();
$device_sensors = [];
foreach ($oids as $index => $entry) {
$device_index = explode('.', $index)[0];
@ -96,8 +96,8 @@ foreach($device_sensors as $device_index => $sensors) {
}
if (strlen($sensor['description']['cmcIIIVarValueStr'])) {
$tmp = str_replace(array( '_', 'Sys ' ),
array( ' ', 'System ' ), $sensor['description']['cmcIIIVarValueStr']);
$tmp = str_replace([ '_', 'Sys ' ],
[ ' ', 'System ' ], $sensor['description']['cmcIIIVarValueStr']);
if (!str_contains_array($name, $tmp)) {
$descr .= ' - ' . $sensor['description']['cmcIIIVarValueStr'];
}
@ -115,7 +115,6 @@ foreach($device_sensors as $device_index => $sensors) {
$oid_num = '.1.3.6.1.4.1.2606.7.4.2.2.1.11.' . $index;
if ($datatype === 'enum') {
//discover_status($device, $oid_num, "$oid_name.$index", 'cmcIIIMsgStatus', $descr, $value, array( 'entPhysicalClass' => 'other' ));
discover_status_ng($device, $mib, $oid_name, $oid_num, $index, 'cmcIIIMsgStatus', $descr, $value, [ 'entPhysicalClass' => 'other' ]);
}
@ -149,7 +148,7 @@ foreach($device_sensors as $device_index => $sensors) {
$value = $entry['cmcIIIVarValueInt'];
$oid_num = '.1.3.6.1.4.1.2606.7.4.2.2.1.11.' . $index;
$options = array();
$options = [];
/*
if ($type == 'outputPWM')
{
@ -174,7 +173,7 @@ foreach($device_sensors as $device_index => $sensors) {
} elseif (str_ends($unit, 'V')) {
$type = "voltage";
} elseif ($unit === "%") {
if (str_icontains_array($name, [ 'RPM', ' Fan', 'Valve' ]) || str_iends($entry['cmcIIIVarName'], 'Rpm')) {
if (str_icontains_array($descr, [ 'RPM', ' Fan', 'Valve', 'Airflow' ]) || str_iends($entry['cmcIIIVarName'], 'Rpm')) {
$type = "load";
} elseif (str_icontains_array($name, 'Humidity')) {
$type = "humidity";

View File

@ -0,0 +1,84 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$scale = 1; // Start at 1 for 2 digits setting.
//$scale = 0.01;
$oids = snmpwalk_cache_oid($device, "digital", [], "ROOMALERT12S-MIB");
$index = 0;
$i = 1;
//for ($i = 1; $i <= 2; $i++) {
if (isset($oids[$index]["digital-sen$i-1"])) {
$name = "External Digital Sensor";
// Sensor is present.
if (!isset($oids[$index]["digital-sen$i-3"])) {
// Temp sensor
$descr = "$name: Temperature";
$oid = ".1.3.6.1.4.1.20916.1.12.1.2.$i.1.$index";
$value = $oids[$index]["digital-sen$i-1"];
if ($value > 100) { $scale = 0.01; }
discover_sensor_ng($device, 'temperature', $mib, "digital-sen$i-1", $oid, $index, NULL, $descr, $scale, $value);
} elseif (isset($oids[$index]["digital-sen$i-5"])) {
// Temp/Humidity sensor
$descr = "$name: Temperature";
$oid = ".1.3.6.1.4.1.20916.1.12.1.2.$i.1.$index";
$value = $oids[$index]["digital-sen$i-1"];
if ($value > 100) { $scale = 0.01; }
discover_sensor_ng($device, 'temperature', $mib, "digital-sen$i-1", $oid, $index, NULL, $descr, $scale, $value);
$descr = "$name: Heat index";
$oid = ".1.3.6.1.4.1.20916.1.12.1.2.$i.5.$index";
$value = $oids[$index]["digital-sen$i-5"];
discover_sensor_ng($device, 'temperature', $mib, "digital-sen$i-5", $oid, $index, NULL, $descr, $scale, $value);
$descr = "$name: Humidity";
$oid = ".1.3.6.1.4.1.20916.1.12.1.2.$i.3.$index";
$value = $oids[$index]["digital-sen$i-3"];
discover_sensor_ng($device, 'humidity', $mib, "digital-sen$i-3", $oid, $index, NULL, $descr, $scale, $value);
$descr = "$name: Dew Point";
$oid = ".1.3.6.1.4.1.20916.1.12.1.2.$i.6.$index";
$value = $oids[$index]["digital-sen$i-6"];
discover_sensor_ng($device, 'dewpoint', $mib, "digital-sen$i-6", $oid, $index, NULL, $descr, $scale, $value);
} else {
// Power sensor
$descr = "Channel $i: Current";
$oid = ".1.3.6.1.4.1.20916.1.12.1.2.$i.1.$index";
$value = $oids[$index]["digital-sen$i-1"];
discover_sensor('current', $device, $oid, "digital-sen$i-1.$index", 'roomalert', $descr, $scale, $value);
$descr = "Channel $i: Power";
$oid = ".1.3.6.1.4.1.20916.1.12.1.2.$i.2.$index";
$value = $oids[$index]["digital-sen$i-2"];
discover_sensor('power', $device, $oid, "digital-sen$i-2.$index", 'roomalert', $descr, $scale, $value);
$descr = "Channel $i: Voltage";
$oid = ".1.3.6.1.4.1.20916.1.12.1.2.$i.3.$index";
$value = $oids[$index]["digital-sen$i-3"];
discover_sensor('voltage', $device, $oid, "digital-sen$i-3.$index", 'roomalert', $descr, $scale, $value);
$descr = "Channel $i: Reference voltage";
$oid = ".1.3.6.1.4.1.20916.1.12.1.2.$i.4.$index";
$value = $oids[$index]["digital-sen$i-4"];
discover_sensor('voltage', $device, $oid, "digital-sen$i-4.$index", 'roomalert', $descr, $scale, $value);
}
}
//}
// EOF

View File

@ -77,13 +77,14 @@ for ($i = 1; $i <= 4; $i++) {
discover_status($device, $oid, 'relay'.$i.'State.0', 'teracom-relay-state', $descr, $value, array('entPhysicalClass' => 'other'));
}
// Status FIXME definition-based
/* Status FIXME definition-based
$value = snmp_get_oid($device, 'hardwareErr.0', $mib);
if (!safe_empty($value)) {
$descr = 'Status';
$oid = '.1.3.6.1.4.1.38783.1.3.8.0';
discover_status($device, $oid, 'hardwareErr.0', 'teracom-alarm-state', $descr, $value, array('entPhysicalClass' => 'other'));
}
*/
unset($data, $oid, $descr, $limits, $value);

View File

@ -0,0 +1,144 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Teracom MIBs are stupid
// TERACOM-TCW241-MIB::temperatureUnit.0 = INTEGER: celcius(0)
$temp_unit = snmp_get_oid($device, 'temperatureUnit.0', $mib);
$flags = OBS_QUOTES_TRIM | OBS_SNMP_DISPLAY_HINT; // disable use display-hint, for correct scales
$invalid = [ '0', '-2147483648' ];
// 1-Wire sensors
for ($i = 1; $i <= 8; $i++) {
// TERACOM-TCW241-MIB::s1description.0 = STRING: S1:TSH2xx
// TERACOM-TCW241-MIB::s11MAXInt.0 = INTEGER: 85.000
// TERACOM-TCW241-MIB::s11MINInt.0 = INTEGER: -40.000
// TERACOM-TCW241-MIB::s11HYSTInt.0 = INTEGER: 8.500
// TERACOM-TCW241-MIB::s12MAXInt.0 = INTEGER: 100.000
// TERACOM-TCW241-MIB::s12MINInt.0 = INTEGER: .000
// TERACOM-TCW241-MIB::s12HYSTInt.0 = INTEGER: 10.000
// TERACOM-TCW241-MIB::s11Int.0 = INTEGER: 17.875
// TERACOM-TCW241-MIB::s12Int.0 = INTEGER: 27.500
// TERACOM-TCW241-MIB::s1ID.0 = STRING: 01FBBC5A1800FF40
$oids = [
"s{$i}description.0", "s{$i}ID.0",
"s{$i}1Int.0", "s{$i}1MAXInt.0", "s{$i}1MINInt.0",
"s{$i}2Int.0", "s{$i}2MAXInt.0", "s{$i}2MINInt.0",
];
$data = snmp_get_multi_oid($device, $oids, [], $mib, NULL, $flags);
if ($data[0]['s'.$i.'ID'] === '0000000000000000') { continue; }
if (!in_array($data[0]["s{$i}1Int"], $invalid)) {
$descr = '#1 ' . $data[0]["s{$i}description"] . ' (' . $data[0]["s{$i}ID"] . ')';
$oid_num = ".1.3.6.1.4.1.38783.3.3.1.$i.1.0";
$oid_name = "s{$i}1Int";
$value = $data[0][$oid_name];
$scale = 0.001;
$options = [
'limit_low' => $data[0]["s{$i}1MINInt"] * $scale,
'limit_high' => $data[0]["s{$i}1MAXInt"] * $scale
];
if ($temp_unit === 'fahrenheit') {
$options['sensor_unit'] = 'F';
}
discover_sensor_ng($device, 'temperature', $mib, $oid_name, $oid_num, 0, NULL, $descr, $scale, $value, $options);
}
if (!in_array($data[0]["s{$i}2Int"], $invalid)) {
$descr = '#2 ' . $data[0]["s{$i}description"] . ' (' . $data[0]["s{$i}ID"] . ')';
$oid_num = ".1.3.6.1.4.1.38783.3.3.1.$i.2.0";
$oid_name = "s{$i}2Int";
$value = $data[0][$oid_name];
$scale = 0.001;
$options = [
'limit_low' => $data[0]["s{$i}2MINInt"] * $scale,
'limit_high' => $data[0]["s{$i}2MAXInt"] * $scale
];
if ($temp_unit === 'fahrenheit') {
$options['sensor_unit'] = 'F';
}
discover_sensor_ng($device, 'temperature', $mib, $oid_name, $oid_num, 0, NULL, $descr, $scale, $value, $options);
}
}
// Analog inputs
for ($i = 1; $i <= 4; $i++) {
$oids = [
"voltage{$i}description.0",
"voltage{$i}Int.0", "voltage{$i}max.0", "voltage{$i}min.0",
];
$data = snmp_get_multi_oid($device, $oids, [], $mib, NULL, $flags);
$descr = $data[0]["voltage{$i}description"];
switch(substr($descr, 0, 2)) {
case 'I ':
$type = 'current';
$descr = substr($descr, 2);
break;
case 'F ':
$type = 'frequency';
$descr = substr($descr, 2);
break;
case 'H ':
$type = 'humidity';
$descr = substr($descr, 2);
break;
default:
$type = 'voltage';
}
if (!in_array($data[0]["voltage{$i}Int"], $invalid)) {
$oid_num = ".1.3.6.1.4.1.38783.3.3.2.$i.0";
$oid_name = "voltage{$i}Int";
$value = $data[0][$oid_name];
$scale = 0.001;
$options = [
'limit_low' => $data[0]["voltage{$i}min"] * $scale,
'limit_high' => $data[0]["voltage{$i}max"] * $scale
];
discover_sensor_ng($device, $type, $mib, $oid_name, $oid_num, 0, NULL, $descr, $scale, $value, $options);
}
}
// Digital inputs
for ($i = 1; $i <= 4; $i++) {
$oids = [
"digitalInput{$i}description.0", "digitalInput{$i}State.0",
];
$data = snmp_get_multi_oid($device, $oids, [], $mib);
$descr = $data[0]["digitalInput{$i}description"];
$oid_num = ".1.3.6.1.4.1.38783.3.3.3.$i.0";
$oid_name = "digitalInput{$i}State";
$value = $data[0][$oid_name];
discover_status_ng($device, $mib, $oid_name, $oid_num, 0, 'teracom-digitalin-state', $descr, $value, [ 'entPhysicalClass' => 'other' ]);
}
// Relay outputs
for ($i = 1; $i <= 4; $i++) {
$oids = [
"relay{$i}description.0", "relay{$i}State.0",
];
$data = snmp_get_multi_oid($device, $oids, [], $mib);
$descr = $data[0]["relay{$i}description"];
$oid_num = ".1.3.6.1.4.1.38783.3.3.4.$i.1.0";
$oid_name = "relay{$i}State";
$value = $data[0][$oid_name];
discover_status_ng($device, $mib, $oid_name, $oid_num, 0, 'teracom-relay-state', $descr, $value, [ 'entPhysicalClass' => 'other' ]);
}
// EOF

View File

@ -273,7 +273,8 @@ if (safe_count($ups_array)) {
$oid_name = 'upsInputVoltage';
if (isset($entry[$oid_name]) &&
!discovery_check_if_type_exist([ 'voltage->TRIPPLITE-PRODUCTS-tlpUpsInputPhaseVoltage',
'voltage->HUAWEI-UPS-MIB-hwUpsInputVoltageA' ], 'sensor')) {
'voltage->HUAWEI-UPS-MIB-hwUpsInputVoltageA',
'voltage->CPS-MIB-upsAdvanceInputLineVoltage' ], 'sensor')) {
$oid = ".1.3.6.1.2.1.33.1.3.3.1.3.$index";
//discover_sensor('voltage', $device, $oid, "upsInputEntry.".$phase, 'ups-mib', $descr, 1, $entry[$oid_name]);
$options = [ 'rename_rrd' => 'ups-mib-upsInputEntry.'.$phase ];
@ -368,7 +369,8 @@ if (safe_count($ups_array)) {
$oid_name = 'upsOutputVoltage';
if (isset($entry[$oid_name]) && $entry[$oid_name] > 0 &&
!discovery_check_if_type_exist([ 'voltage->TRIPPLITE-PRODUCTS-tlpUpsOutputLineVoltage',
'voltage->HUAWEI-UPS-MIB-hwUpsOutputVoltageA' ], 'sensor')) {
'voltage->HUAWEI-UPS-MIB-hwUpsOutputVoltageA',
'voltage->CPS-MIB-upsAdvanceOutputVoltage' ], 'sensor')) {
$oid = ".1.3.6.1.2.1.33.1.4.4.1.2.$index";
//discover_sensor('voltage', $device, $oid, "upsOutputEntry.".$phase, 'ups-mib', $descr, 1, $entry['upsOutputVoltage']);
$options = [ 'rename_rrd' => 'ups-mib-upsOutputEntry.'.$phase ];
@ -382,7 +384,8 @@ if (safe_count($ups_array)) {
## Output current
$oid_name = 'upsOutputCurrent';
if (isset($entry[$oid_name]) && $ups_total[$oid_name] > 0 &&
!discovery_check_if_type_exist([ 'current->HUAWEI-UPS-MIB-hwUpsOutputCurrentA' ], 'sensor')) {
!discovery_check_if_type_exist([ 'current->HUAWEI-UPS-MIB-hwUpsOutputCurrentA',
'current->CPS-MIB-upsAdvanceOutputCurrent' ], 'sensor')) {
$oid = ".1.3.6.1.2.1.33.1.4.4.1.3.$index";
//discover_sensor('current', $device, $oid, "upsOutputEntry.".$phase, 'ups-mib', $descr, $scale_current, $entry['upsOutputCurrent']);
$options = [ 'rename_rrd' => 'ups-mib-upsOutputEntry.'.$phase ];
@ -392,7 +395,8 @@ if (safe_count($ups_array)) {
## Output power
$oid_name = 'upsOutputPower';
if (isset($entry[$oid_name]) && $ups_total[$oid_name] > 0 &&
!discovery_check_if_type_exist('power->HUAWEI-UPS-MIB-hwUpsOutputActivePowerA', 'sensor')) {
!discovery_check_if_type_exist([ 'power->HUAWEI-UPS-MIB-hwUpsOutputActivePowerA',
'power->CPS-MIB-upsAdvanceOutputPower' ], 'sensor')) {
$oid = ".1.3.6.1.2.1.33.1.4.4.1.4.$index";
//discover_sensor('power', $device, $oid, "upsOutputEntry.".$phase, 'ups-mib', $descr, 1, $entry['upsOutputPower']);
$options = [ 'rename_rrd' => 'ups-mib-upsOutputEntry.'.$phase ];
@ -403,7 +407,7 @@ if (safe_count($ups_array)) {
if (isset($entry[$oid_name]) &&
!discovery_check_if_type_exist('load->HUAWEI-UPS-MIB-hwUpsOutputLoadA', 'sensor')) {
$oid = ".1.3.6.1.2.1.33.1.4.4.1.5.$index";
//rename_rrd($device, "sensor-capacity-ups-mib-upsOutputPercentLoad.${phase}", "sensor-load-ups-mib-upsOutputPercentLoad.${phase}");
//rename_rrd($device, "sensor-capacity-ups-mib-upsOutputPercentLoad.{$phase}", "sensor-load-ups-mib-upsOutputPercentLoad.{$phase}");
//discover_sensor('load', $device, $oid, "upsOutputPercentLoad.$phase", 'ups-mib', $descr, 1, $entry['upsOutputPercentLoad']);
$options = [ 'rename_rrd' => 'ups-mib-upsOutputPercentLoad.'.$phase ];
discover_sensor_ng($device, 'load', $mib, $oid_name, $oid, $index, NULL, $descr, 1, $entry[$oid_name], $options);

View File

@ -6,11 +6,11 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$xups_array = array();
$xups_array = [];
$xups_array = snmpwalk_cache_oid($device, "xupsInput", $xups_array, "XUPS-MIB");
$xups_array = snmpwalk_cache_oid($device, "xupsOutput", $xups_array, "XUPS-MIB");
$xups_array = snmpwalk_cache_oid($device, "xupsBypass", $xups_array, "XUPS-MIB");
@ -27,14 +27,11 @@ $xups_array = snmpwalk_cache_oid($device, "xupsConfig", $xups_array, "XUPS-MIB")
$xups_base = $xups_array[0];
unset($xups_array[0]);
foreach ($xups_array as $index => $entry)
{
foreach ($xups_array as $index => $entry) {
// Input
if (isset($entry['xupsInputPhase']))
{
if (isset($entry['xupsInputPhase'])) {
$descr = "Input";
if ($xups_base['xupsInputNumPhases'] > 1)
{
if ($xups_base['xupsInputNumPhases'] > 1) {
$descr .= " Phase $index";
}
@ -43,12 +40,10 @@ foreach ($xups_array as $index => $entry)
$value = $entry['xupsInputVoltage'];
if ($value != 0 &&
!isset($valid['sensor']['voltage']['mge-ups'][100+$index]))
{
!isset($valid['sensor']['voltage']['mge-ups'][100+$index])) {
// Limits
$limits = [];
if ($xups_base['xupsConfigInputVoltage'])
{
if ($xups_base['xupsConfigInputVoltage']) {
$limits['limit_low'] = $xups_base['xupsConfigInputVoltage'] - 15;
$limits['limit_high'] = $xups_base['xupsConfigInputVoltage'] + 15;
}
@ -60,16 +55,14 @@ foreach ($xups_array as $index => $entry)
$value = $entry['xupsInputCurrent'];
if ($value != 0 && $value < 10000 && // xupsInputCurrent.1 = 136137420 ? really? You're nuts.
!isset($valid['sensor']['current']['mge-ups'][100+$index]))
{
!isset($valid['sensor']['current']['mge-ups'][100+$index])) {
discover_sensor('current', $device, $oid, "xupsInputEntry.".$index, 'xups', $descr, 1, $value);
}
## Input power
$oid = ".1.3.6.1.4.1.534.1.3.4.1.4.$index"; # XUPS-MIB::xupsInputWatts.$index
$value = $entry['xupsInputWatts'];
if ($value != 0)
{
if ($value != 0) {
discover_sensor('power', $device, $oid, "xupsInputEntry.".$index, 'xups', $descr, 1, $value);
}
}
@ -96,11 +89,9 @@ foreach ($xups_array as $index => $entry)
// XUPS-MIB::xupsOutputTotalVA.0 = INTEGER: 98 VA
// XUPS-MIB::xupsOutputAveragePowerFactor.0 = INTEGER: 33
// XUPS-MIB::xupsOutput.10.0 = INTEGER: 3
if (isset($entry['xupsOutputPhase']))
{
if (isset($entry['xupsOutputPhase'])) {
$descr = "Output";
if ($xups_base['xupsOutputNumPhases'] > 1)
{
if ($xups_base['xupsOutputNumPhases'] > 1) {
$descr .= " Phase $index";
}
@ -108,12 +99,10 @@ foreach ($xups_array as $index => $entry)
$oid = ".1.3.6.1.4.1.534.1.4.4.1.2.$index"; # XUPS-MIB::xupsOutputVoltage.$index
$value = $entry['xupsOutputVoltage'];
if ($value != 0 &&
!isset($valid['sensor']['voltage']['mge-ups'][$index]))
{
!isset($valid['sensor']['voltage']['mge-ups'][$index])) {
// Limits
$limits = [];
if ($xups_base['xupsConfigLowOutputVoltageLimit'] && $xups_base['xupsConfigHighOutputVoltageLimit'])
{
if ($xups_base['xupsConfigLowOutputVoltageLimit'] && $xups_base['xupsConfigHighOutputVoltageLimit']) {
$limits['limit_low'] = $xups_base['xupsConfigLowOutputVoltageLimit'];
$limits['limit_high'] = $xups_base['xupsConfigHighOutputVoltageLimit'];
}
@ -121,19 +110,15 @@ foreach ($xups_array as $index => $entry)
}
## Output current
if (!isset($valid['sensor']['current']['mge-ups'][$index]))
{
if (!isset($valid['sensor']['current']['mge-ups'][$index])) {
$options = [ 'rename_rrd' => 'xups-xupsOutputEntry.'.$index ];
if (isset($entry['xupsOutputCurrentHighPrecision']) && $entry['xupsOutputCurrentHighPrecision'] != 0)
{
if (isset($entry['xupsOutputCurrentHighPrecision']) && $entry['xupsOutputCurrentHighPrecision'] != 0) {
// Prefer High precision
$oid = ".1.3.6.1.4.1.534.1.4.4.1.7.$index";
$value = $entry['xupsOutputCurrentHighPrecision'];
$options['limit_auto'] = FALSE; // Not sure
discover_sensor_ng($device, 'current', 'XUPS-MIB', 'xupsOutputCurrentHighPrecision', $oid, $index, NULL, $descr, 0.1, $value, $options);
}
elseif ($entry['xupsOutputCurrent'] != 0)
{
} elseif ($entry['xupsOutputCurrent'] != 0) {
$oid = ".1.3.6.1.4.1.534.1.4.4.1.3.$index"; # XUPS-MIB::xupsOutputCurrent.$index
$value = $entry['xupsOutputCurrent'];
discover_sensor_ng($device, 'current', 'XUPS-MIB', 'xupsOutputCurrent', $oid, $index, NULL, $descr, 1, $value, $options);
@ -144,11 +129,9 @@ foreach ($xups_array as $index => $entry)
## Output power
$oid = ".1.3.6.1.4.1.534.1.4.4.1.4.$index"; # XUPS-MIB::xupsOutputWatts.$index
$value = $entry['xupsOutputWatts'];
if ($value != 0)
{
if ($value != 0) {
$limits = [];
if ($xups_base['xupsConfigOutputWatts'])
{
if ($xups_base['xupsConfigOutputWatts']) {
$limits['limit_high_warn'] = $xups_base['xupsConfigOutputWatts'] * 0.8;
$limits['limit_high'] = $xups_base['xupsConfigOutputWatts'] * 0.95;
}
@ -158,8 +141,7 @@ foreach ($xups_array as $index => $entry)
## Output Active power
$oid = ".1.3.6.1.4.1.534.1.4.4.1.9.$index"; # XUPS-MIB::xupsOutputVA.$index
$value = $entry['xupsOutputVA'];
if ($value != 0)
{
if ($value != 0) {
discover_sensor_ng($device, 'apower', 'XUPS-MIB', 'xupsOutputVA', $oid, $index, NULL, $descr, 1, $value);
}
}
@ -176,23 +158,19 @@ foreach ($xups_array as $index => $entry)
// XUPS-MIB::xupsBypassAverageVoltage.0 = INTEGER: 229 RMS Volts
// XUPS-MIB::xupsBypassAverageCurrent.0 = INTEGER: 0 RMS tenth of Amps
if (isset($entry['xupsBypassPhase']))
{
if (isset($entry['xupsBypassPhase'])) {
$descr = "Bypass";
if ($xups_base['xupsBypassNumPhases'] > 1)
{
if ($xups_base['xupsBypassNumPhases'] > 1) {
$descr .= " Phase $index";
}
## Bypass voltage
$oid = ".1.3.6.1.4.1.534.1.5.3.1.2.$index"; # XUPS-MIB::xupsBypassVoltage.$index
$value = $entry['xupsBypassVoltage'];
if ($value != 0)
{
if ($value != 0) {
discover_sensor('voltage', $device, $oid, "xupsBypassEntry." . $index, 'xups', $descr, 1, $value);
if (isset($entry['xupsBypassCurrentHighPrecision'])) // && $entry['xupsBypassCurrentHighPrecision'] != 0)
{
if (isset($entry['xupsBypassCurrentHighPrecision'])) { // && $entry['xupsBypassCurrentHighPrecision'] != 0)
$oid = ".1.3.6.1.4.1.534.1.5.3.1.5.$index";
$value = $entry['xupsBypassCurrentHighPrecision'];
discover_sensor_ng($device, 'current', 'XUPS-MIB', 'xupsBypassCurrentHighPrecision', $oid, $index, NULL, $descr, 0.1, $value);
@ -208,8 +186,7 @@ $oid = ".1.3.6.1.4.1.534.1.3.1.0"; # XUPS-MIB::xupsInputFrequency.0
$scale = 0.1;
$value = $entry['xupsInputFrequency'];
if ($value != 0 &&
!isset($valid['sensor']['frequency']['mge-ups'][101]))
{
!isset($valid['sensor']['frequency']['mge-ups'][101])) {
discover_sensor('frequency', $device, $oid, "xupsInputFrequency.0", 'xups', "Input", $scale, $value);
}
@ -217,8 +194,7 @@ if ($value != 0 &&
$oid = ".1.3.6.1.4.1.534.1.4.1.0"; # XUPS-MIB::xupsOutputLoad.0
$descr = "Output Load";
$value = $entry['xupsOutputLoad'];
if (!isset($valid['sensor']['load']['mge-ups']['mgoutputLoadPerPhase.1']))
{
if (!isset($valid['sensor']['load']['mge-ups']['mgoutputLoadPerPhase.1'])) {
$limits = [ 'limit_high_warn' => 80, 'limit_high' => 95 ];
discover_sensor('load', $device, $oid, "xupsOutputLoad.0", 'xups', $descr, 1, $value, $limits);
}
@ -227,11 +203,9 @@ if (!isset($valid['sensor']['load']['mge-ups']['mgoutputLoadPerPhase.1']))
$oid = ".1.3.6.1.4.1.534.1.4.2.0"; # XUPS-MIB::xupsOutputFrequency.0
$value = $entry['xupsOutputFrequency'];
if ($value != 0 &&
!isset($valid['sensor']['frequency']['mge-ups'][1]))
{
!isset($valid['sensor']['frequency']['mge-ups'][1])) {
$limits = [];
if ($xups_base['xupsConfigOutputFreq'])
{
if ($xups_base['xupsConfigOutputFreq']) {
$limits['limit_low'] = $xups_base['xupsConfigOutputFreq'] * 0.099; // 50 -> 49,5
$limits['limit_low_warn'] = $xups_base['xupsConfigOutputFreq'] * 0.0996; // 50 -> 49.8
$limits['limit_high_warn'] = $xups_base['xupsConfigOutputFreq'] * 0.1004; // 50 -> 50.2
@ -244,16 +218,14 @@ if ($value != 0 &&
$oid = ".1.3.6.1.4.1.534.1.4.9.5.0"; # XUPS-MIB::xupsOutputAveragePowerFactor.0
$descr = "Output Power Factor";
$value = $entry['xupsOutputAveragePowerFactor'];
if ($value != 0)
{
if ($value != 0) {
discover_sensor_ng($device, 'powerfactor', 'XUPS-MIB', 'xupsOutputAveragePowerFactor', $oid, 0, NULL, $descr, 1, $value);
}
## Bypass Frequency
$oid = ".1.3.6.1.4.1.534.1.5.1.0"; # XUPS-MIB::xupsBypassFrequency.0
$value = $entry['xupsBypassFrequency'];
if ($value != 0)
{
if ($value != 0) {
discover_sensor('frequency', $device, $oid, "xupsBypassFrequency.0", 'xups', "Bypass", $scale, $value);
}
@ -264,7 +236,7 @@ $oid_num = '.1.3.6.1.4.1.534.1.3.5.0';
$type = 'xupsInputSource';
$value = $entry[$oid_name];
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, array('entPhysicalClass' => 'other'));
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, [ 'entPhysicalClass' => 'other' ]);
// xupsOutputSource
$descr = 'Output Source';
@ -273,7 +245,7 @@ $oid_num = '.1.3.6.1.4.1.534.1.4.5.0';
$type = 'xupsOutputSource';
$value = $entry[$oid_name];
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, array('entPhysicalClass' => 'other'));
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, [ 'entPhysicalClass' => 'other' ]);
// XUPS-MIB::xupsBatTimeRemaining.0 = INTEGER: 31500 seconds
// XUPS-MIB::xupsBatVoltage.0 = INTEGER: 104 Volts DC
@ -290,17 +262,15 @@ discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value,
// XUPS-MIB::xupsEnvAmbientUpperLimit.0 = INTEGER: 40 degrees Centigrade
// XUPS-MIB::xupsEnvNumContacts.0 = INTEGER: 0
$xups_array = array();
$xups_array = [];
$xups_array = snmpwalk_cache_oid($device, "xupsBattery", $xups_array, "XUPS-MIB");
$xups_array = snmpwalk_cache_oid($device, "xupsEnvironment", $xups_array, "XUPS-MIB");
$entry = $xups_array[0];
if ($entry['xupsBatteryNotPresent'] !== 'yes')
{
if ($entry['xupsBatteryNotPresent'] !== 'yes') {
if (isset($entry['xupsBatTimeRemaining']) &&
!isset($valid['sensor']['runtime']['mge']['upsmgBatteryRemainingTime.0']))
{
!isset($valid['sensor']['runtime']['mge']['upsmgBatteryRemainingTime.0'])) {
$oid = ".1.3.6.1.4.1.534.1.2.1.0"; # XUPS-MIB::xupsBatTimeRemaining.0
$scale = 1/60;
$value = $entry['xupsBatTimeRemaining'];
@ -309,8 +279,7 @@ if ($entry['xupsBatteryNotPresent'] !== 'yes')
}
if (isset($entry['xupsBatCapacity']) &&
!isset($valid['sensor']['capacity']['mge']['upsmgBatteryLevel.0']))
{
!isset($valid['sensor']['capacity']['mge']['upsmgBatteryLevel.0'])) {
$oid = ".1.3.6.1.4.1.534.1.2.4.0"; # XUPS-MIB::xupsBatCapacity.0
$value = $entry['xupsBatCapacity'];
@ -318,8 +287,7 @@ if ($entry['xupsBatteryNotPresent'] !== 'yes')
}
if (isset($entry['xupsBatVoltage']) && $entry['xupsBatVoltage'] != 0 &&
!isset($valid['sensor']['voltage']['mge']['upsmgBatteryVoltage.0']))
{
!isset($valid['sensor']['voltage']['mge']['upsmgBatteryVoltage.0'])) {
$oid = ".1.3.6.1.4.1.534.1.2.2.0"; # XUPS-MIB::xupsBatVoltage.0
$value = $entry['xupsBatVoltage'];
@ -327,8 +295,7 @@ if ($entry['xupsBatteryNotPresent'] !== 'yes')
}
if (isset($entry['xupsBatCurrent']) &&
!isset($valid['sensor']['current']['mge']['upsmgBatteryCurrent.0']))
{
!isset($valid['sensor']['current']['mge']['upsmgBatteryCurrent.0'])) {
$oid = ".1.3.6.1.4.1.534.1.2.3.0"; # XUPS-MIB::xupsBatCurrent.0
$value = $entry['xupsBatCurrent'];
@ -342,7 +309,7 @@ if ($entry['xupsBatteryNotPresent'] !== 'yes')
$type = 'xupsBatteryAbmStatus';
$value = $entry[$oid_name];
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, array('entPhysicalClass' => 'battery'));
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, [ 'entPhysicalClass' => 'battery' ]);
// xupsBatteryFailure
$descr = 'Battery Failure';
@ -351,17 +318,17 @@ if ($entry['xupsBatteryNotPresent'] !== 'yes')
$type = 'xupsBatteryFailure';
$value = $entry[$oid_name];
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, array('entPhysicalClass' => 'battery'));
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, [ 'entPhysicalClass' => 'battery' ]);
// xupsBatteryAged
$age = $entry['xupsBatteryLastReplacedDate'];
$descr = "Battery over aged ($age)";
$oid_name = 'xupsBatteryAged';
$oid_num = '.1.3.6.1.4.1.534.1.2.9.0';
$type = 'xupsBatteryFailure';
$type = 'xupsBatteryWarning';
$value = $entry[$oid_name];
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, array('entPhysicalClass' => 'battery'));
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, [ 'entPhysicalClass' => 'battery' ]);
// xupsBatteryLowCapacity
$descr = 'Battery Low Capacity';
@ -370,7 +337,7 @@ if ($entry['xupsBatteryNotPresent'] !== 'yes')
$type = 'xupsBatteryFailure';
$value = $entry[$oid_name];
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, array('entPhysicalClass' => 'battery'));
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, [ 'entPhysicalClass' => 'battery' ]);
}
// xupsBatteryNotPresent
@ -380,18 +347,16 @@ $oid_num = '.1.3.6.1.4.1.534.1.2.8.0';
$type = 'xupsBatteryNotPresent';
$value = $entry[$oid_name];
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, array('entPhysicalClass' => 'battery'));
discover_status($device, $oid_num, $oid_name.'.'.$index, $type, $descr, $value, [ 'entPhysicalClass' => 'battery' ]);
if (isset($entry['xupsEnvAmbientTemp']))
{
if (isset($entry['xupsEnvAmbientTemp'])) {
$oid = ".1.3.6.1.4.1.534.1.6.1.0"; # XUPS-MIB:xupsEnvAmbientTemp.0
$value = $entry['xupsEnvAmbientTemp'];
$limits = array('limit_low' => $xups_array[0]['upsEnvAmbientLowerLimit'],
'limit_high' => $xups_array[0]['upsEnvAmbientUpperLimit']);
$limits = [ 'limit_low' => $xups_array[0]['upsEnvAmbientLowerLimit'],
'limit_high' => $xups_array[0]['upsEnvAmbientUpperLimit'] ];
if ($value != 0)
{
if ($value != 0) {
discover_sensor('temperature', $device, $oid, "xupsEnvAmbientTemp.0", 'xups', "Ambient", 1, $value, $limits);
}
}

View File

@ -73,7 +73,6 @@ if (snmp_status())
$oid = '.1.3.6.1.4.1.9.9.500.1.1.3.0';
$descr = 'Stackports in redundant ring';
discover_status_ng($device, $mib, 'cswRingRedundant', $oid, '0', 'cisco-stackwise-redundant-state', $descr, $stackredundant, array('entPhysicalClass' => 'stack'));
//discover_status($device, $oid, "cswRingRedundant.0", 'cisco-stackwise-redundant-state', $descr, $stackredundant, array('entPhysicalClass' => 'stack'));
foreach ($stackportoper as $index => $entry)
{

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -19,123 +19,12 @@ foreach (get_device_mibs_permitted($device) as $mib) {
if (!is_array($config['mibs'][$mib]['storage'])) { continue; }
echo("$mib ");
print_cli_data_field($mib);
foreach ($config['mibs'][$mib]['storage'] as $entry_name => $entry) {
$entry['found'] = FALSE;
discover_storage_definition($device, $mib, $entry, $entry_name);
$entry['mib'] = $mib;
if (discovery_check_requires_pre($device, $entry, 'storage')) {
continue;
}
// Init Precision (scale)/total/used/free
$used = NULL;
$total = NULL;
$free = NULL;
$perc = NULL;
$options = [];
if (isset($entry['scale']) && is_numeric($entry['scale']) && $entry['scale']) {
$scale = $entry['scale'];
} else {
$scale = 1;
}
/////////////////////
// Table Discovery //
/////////////////////
/* FIXME. Partially changed, need rewrite to common style
// If the type is table, walk the table!
if ($entry['type'] == "table")
{
$entry['oids'][$entry_name] = $entry_name;
}
else
{
// Type is not table, so we have to walk each OID individually
foreach (array('oid_total', 'oid_total', 'oid_free', 'oid_perc', 'oid_descr') as $oid)
{
if (isset($entry[$oid]))
{
$entry['oids'][$oid] = $entry[$oid];
}
}
}
// FIXME - cache this outside the storage array and then just array_merge it in. Descr OIDs are probably shared a lot
// FIXME - Allow different MIBs for OIDs. Best done by prefixing with MIB and parsing it out?
if (isset($entry['extra_oids']))
{
foreach ((array)$entry['extra_oids'] as $oid)
{
$entry['oids'][$oid] = $oid;
}
}
foreach ($entry['oids'] as $oid)
{
$storage_array = snmpwalk_cache_oid($device, $oid, $storage_array, $mib);
}
*/
$table_oids = [ 'oid_total', 'oid_used', 'oid_free', 'oid_perc', 'oid_descr',
'oid_scale', 'oid_unit', 'oid_extra',
//'oid_limit_low', 'oid_limit_low_warn', 'oid_limit_high_warn', 'oid_limit_high',
//'oid_limit_nominal', 'oid_limit_delta_warn', 'oid_limit_delta', 'oid_limit_scale'
];
$storage_array = discover_fetch_oids($device, $mib, $entry, $table_oids);
// FIXME - generify description generation code and just pass it template and OID array.
$i = 1; // Used in descr as %i%
$storage_count = count($storage_array);
foreach ($storage_array as $index => $storage_entry) {
$oid_num = $entry['oid_num'] . '.' . $index;
// Generate storage description
$storage_entry['i'] = $i;
$storage_entry['index'] = $index;
$descr = entity_descr_definition('storage', $entry, $storage_entry, $storage_count);
// Convert strings '3.40 TB' to value
// See QNAP NAS-MIB or HIK-DEVICE-MIB
$unit = isset($entry['unit']) ? $entry['unit'] : NULL;
// Fetch used, total, free and percentage values, if OIDs are defined for them
if (!safe_empty($entry['oid_used'])) {
$used = snmp_fix_numeric($storage_entry[$entry['oid_used']], $unit);
}
if (!safe_empty($entry['oid_free'])) {
$free = snmp_fix_numeric($storage_entry[$entry['oid_free']], $unit);
}
if (!safe_empty($entry['oid_perc'])) {
$perc = snmp_fix_numeric($storage_entry[$entry['oid_perc']]);
}
// Prefer hardcoded total over SNMP OIDs
if (!safe_empty($entry['total'])) {
$total = $entry['total'];
} elseif (!safe_empty($entry['oid_total'])) {
$total = snmp_fix_numeric($storage_entry[$entry['oid_total']], $unit);
}
// Extrapolate all values from the ones we have.
$storage = calculate_mempool_properties($scale, $used, $total, $free, $perc, $options);
print_debug_vars(array($scale, $used, $total, $free, $perc, $options));
print_debug_vars($storage_entry);
print_debug_vars($storage);
print_debug_vars(array(is_numeric($storage['used']), is_numeric($storage['total'])));
// If we have valid used and total, discover the storage
if (is_numeric($storage['used']) && is_numeric($storage['total'])) {
discover_storage($valid['storage'], $device, $index, $entry_name, $mib, $descr, $scale, $storage['total'], $storage['used']); // FIXME storage_hc = ??
$entry['found'] = TRUE;
}
$i++;
}
}
print_cli(PHP_EOL);
}
print_debug_vars($valid['storage']);
@ -151,7 +40,7 @@ foreach (dbFetchRows($query, array($device['device_id'])) as $test_storage) {
if (!$valid['storage'][$storage_mib][$storage_index]) {
$GLOBALS['module_stats']['storage']['deleted']++; //echo('-');
dbDelete('storage', 'storage_id = ?', array($test_storage['storage_id']));
dbDelete('storage', 'storage_id = ?', [ $test_storage['storage_id'] ]);
log_event("Storage removed: index $storage_index, mib $storage_mib, descr $storage_descr", $device, 'storage', $test_storage['storage_id']);
}
}

View File

@ -1,30 +0,0 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
# lookup for storage data
$entry = snmpwalk_cache_oid($device, 'swStorage', NULL, 'EMBEDDED-NGX-MIB');
if (is_array($entry))
{
$index = 0;
$descr = "Config Storage";
$free = $entry[$index]['swStorageConfigFree'] * 1024;
$total = $entry[$index]['swStorageConfigTotal'] * 1024;
$used = $total - $free;
discover_storage($valid['storage'], $device, $index, 'StorageConfig', 'EMBEDDED-NGX-MIB', $descr, 1024, $total, $used);
}
unset ($entry, $index, $descr, $total, $used, $free);
// EOF

View File

@ -1,52 +0,0 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
$mib = 'GPFS-MIB';
$cache_discovery['gpfs-mib'] = snmpwalk_cache_oid($device, "gpfsFileSystemStatusTable", array(), $mib);
if (safe_count($cache_discovery['gpfs-mib'])) {
echo(" $mib ");
/*
Available data:
Array
(
[gpfsFileSystemName] => scratch_gs
[gpfsFileSystemStatus] => recovered
[gpfsFileSystemXstatus] => OFW
[gpfsFileSystemTotalSpaceL] => 1946157056
[gpfsFileSystemTotalSpaceH] => 94
[gpfsFileSystemNumTotalInodesL] => 402653184
[gpfsFileSystemNumTotalInodesH] => 0
[gpfsFileSystemFreeSpaceL] => 37208064
[gpfsFileSystemFreeSpaceH] => 26
[gpfsFileSystemNumFreeInodesL] => 326910126
[gpfsFileSystemNumFreeInodesH] => 0
)
*/
foreach ($cache_discovery['gpfs-mib'] as $index => $storage)
{
$fstype = "gpfs";
$descr = "/".$storage['gpfsFileSystemName'];
$hc = 1;
$size = snmp_size64_high_low($storage['gpfsFileSystemTotalSpaceH'], $storage['gpfsFileSystemTotalSpaceL']) * 1024;
$free = snmp_size64_high_low($storage['gpfsFileSystemFreeSpaceH'], $storage['gpfsFileSystemFreeSpaceL']) * 1024;
$used = $size - $free;
discover_storage($valid['storage'], $device, $index, $fstype, $mib, $descr, 1024, $size, $used, array('storage_hc' => $hc));
unset($deny, $fstype, $descr, $size, $used, $free, $percent, $hc);
}
unset($index, $storage);
}

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -101,10 +101,10 @@ if (!safe_empty($hrStorage)) {
}
}
if (is_numeric($index)) {
if (is_numeric($index) && $size != 0) {
discover_storage($valid['storage'], $device, $index, $fstype, $mib, $descr, $units, $size, $used, [ 'storage_hc' => $hc ]);
$dsk_done[$descr] = $descr;
$dsk_done[$descr] = $path;
}
unset($fstype, $descr, $size, $used, $units, $path, $dsk, $hc);
@ -136,7 +136,7 @@ if (!safe_empty($cache_discovery['ucd-snmp-mib'])) {
$used = $dsk['dskUsed'] * $units;
}
if (is_numeric($index)) {
if (is_numeric($index) && $size != 0) {
discover_storage($valid['storage'], $device, $index, $fstype, $mib, $descr, $units, $size, $used, [ 'storage_hc' => $hc ]);
}
unset($fstype, $descr, $size, $used, $units, $hc);

View File

@ -1,30 +0,0 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// Note, this mountpoint '/ifs' also discovered in HOST-RESOURCES-MIB, but ignored
//ISILON-MIB::ifsTotalBytes.0 = Counter64: 71376260235264
//ISILON-MIB::ifsUsedBytes.0 = Counter64: 38523365810176
//ISILON-MIB::ifsAvailableBytes.0 = Counter64: 28651530510336
//ISILON-MIB::ifsFreeBytes.0 = Counter64: 32852894425088
$cache_discovery['ISILON-MIB'] = snmp_get_multi_oid($device, 'ifsTotalBytes.0 ifsUsedBytes.0', array(), 'ISILON-MIB');
if (is_array($cache_discovery['ISILON-MIB'][0]))
{
$hc = 1;
$size = $cache_discovery['ISILON-MIB'][0]['ifsTotalBytes'];
$used = $cache_discovery['ISILON-MIB'][0]['ifsUsedBytes'];
discover_storage($valid['storage'], $device, 0, 'volume', 'ISILON-MIB', '/ifs', 1, $size, $used, array('storage_hc' => $hc));
}
// EOF

View File

@ -1,98 +0,0 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
$cache_discovery['netapp-mib'] = snmpwalk_cache_oid($device, "dfEntry", array(), 'NETAPP-MIB');
if (safe_count($cache_discovery['netapp-mib'])) {
/*
Available data:
array(40) {
["dfIndex"]=> "3"
["dfFileSys"]=> "/vol/vol0/"
["dfKBytesTotal"]=> "158387408"
["dfKBytesUsed"]=> "7600652"
["dfKBytesAvail"]=> "150786756"
["dfPerCentKBytesCapacity"]=> "5"
["dfInodesUsed"]=> "9405"
["dfInodesFree"]=> "14517028"
["dfPerCentInodeCapacity"]=> "0"
["dfMountedOn"]=> "/vol/vol0/"
["dfMaxFilesAvail"]=> "14526433"
["dfMaxFilesUsed"]=> "9405"
["dfMaxFilesPossible"]=> "39596840"
["dfHighTotalKBytes"]=> "0"
["dfLowTotalKBytes"]=> "158387408"
["dfHighUsedKBytes"]=> "0"
["dfLowUsedKBytes"]=> "7600652"
["dfHighAvailKBytes"]=> "0"
["dfLowAvailKBytes"]=> "150786756"
["dfStatus"]=> "mounted"
["dfMirrorStatus"]=> "invalid"
["dfPlexCount"]=> "0"
["dfType"]=> "flexibleVolume"
["dfHighSisSharedKBytes"]=> "0"
["dfLowSisSharedKBytes"]=> "0"
["dfHighSisSavedKBytes"]=> "0"
["dfLowSisSavedKBytes"]=> "0"
["dfPerCentSaved"]=> "0"
["df64TotalKBytes"]=> "158387408"
["df64UsedKBytes"]=> "7600644"
["df64AvailKBytes"]=> "150786764"
["df64SisSharedKBytes"]=> "0"
["df64SisSavedKBytes"]=> "0"
["df64CompressSaved"]=> "0"
["dfCompressSavedPercent"]=> "0"
["df64DedupeSaved"]=> "0"
["dfDedupeSavedPercent"]=> "0"
["df64TotalSaved"]=> "0"
["dfTotalSavedPercent"]=> "0"
["df64TotalReservedKBytes"]=> "263724"
}
*/
foreach ($cache_discovery['netapp-mib'] as $index => $storage)
{
$fstype = $storage['dfType'];
$descr = $storage['dfFileSys'];
if (!empty($storage['dfVserver']))
{
// Add server info on cluster devices
$descr .= ' - ' . $storage['dfVserver'];
}
$deny = FALSE;
if (!$deny)
{
if (is_numeric($storage['df64TotalKBytes']))
{
$size = $storage['df64TotalKBytes'] * 1024;
$used = $storage['df64UsedKBytes'] * 1024;
$hc = 1;
} else {
$size = $storage['dfKBytesTotal'] * 1024;
$used = $storage['dfKBytesUsed'] * 1024;
$hc = 0;
}
if (is_numeric($index))
{
discover_storage($valid['storage'], $device, $index, $fstype, 'NETAPP-MIB', $descr, 1024, $size, $used, array('storage_hc' => $hc));
}
}
unset($deny, $fstype, $descr, $size, $used, $free, $percent, $hc);
}
unset($index, $storage);
}
// EOF

View File

@ -1,49 +0,0 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mib = 'NIMBLE-MIB';
//$cache_discovery[$mib]
$oids = snmpwalk_cache_oid($device, 'volName', array(), $mib);
if (count($oids))
{
foreach (array('volSizeLow', 'volSizeHigh', 'volUsageLow', 'volUsageHigh', 'volOnline') as $oid)
{
$oids = snmpwalk_cache_oid($device, $oid, $oids, $mib);
}
if (OBS_DEBUG > 1) { print_vars($oids); }
foreach ($oids as $index => $storage)
{
$hc = 1;
$fstype = 'volume';
$descr = $storage['volName'];
$units = 1048576; // Hardcode units. In MIB is written that bytes, but really Mbytes
// FIXME, probably need additional field for storages like OperStatus up/down
$ignore = in_array($storage['volOnline'], array('0', 'false')) ? 1 : 0;
$deny = FALSE;
$size = snmp_size64_high_low($storage['volSizeHigh'], $storage['volSizeLow']) * $units;
$used = snmp_size64_high_low($storage['volUsageHigh'], $storage['volUsageLow']) * $units;
if (!$deny && is_numeric($index))
{
discover_storage($valid['storage'], $device, $index, $fstype, $mib, $descr, $units, $size, $used, array('storage_hc' => $hc, 'storage_ignore' => $ignore));
}
}
}
unset($oids, $deny, $fstype, $descr, $size, $used, $units, $hc);
// EOF

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,12 +6,12 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// NOTE. Here only walking, because needed additional checks by HOST-RESOURCES-MIB (see host-resources-mib.inc.php in current directory)
$cache_discovery['ucd-snmp-mib'] = snmpwalk_cache_oid($device, 'dskEntry', array(), 'UCD-SNMP-MIB');
$cache_discovery['ucd-snmp-mib'] = snmpwalk_cache_oid($device, 'dskEntry', [], 'UCD-SNMP-MIB');
// EOF

View File

@ -0,0 +1,57 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$domain_index = '1';
$hwdot1qVlan = snmpwalk_cache_oid($device, 'hwdot1qVlanMIBTable', [], 'A3COM-HUAWEI-LswVLAN-MIB');
/* Base port ifIndex association */
$dot1d_baseports = snmp_cache_table($device, 'dot1dBasePortIfIndex', [], 'BRIDGE-MIB');
foreach ($hwdot1qVlan as $vlan_num => $vlan) {
$vlan_array = [
'ifIndex' => $vlan['hwVlanInterfaceIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['hwdot1qVlanName'],
//'vlan_mtu' => '',
'vlan_type' => $vlan['hwdot1qVlanType'],
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
// Convert hex to binary map
$binary = hex2binmap($vlan['hwdot1qVlanPorts']);
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i]) {
//if ($use_baseports) {
// Skip all unknown indexes (OBS-2958)
if (!isset($dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'])) { continue; }
$ifIndex = $dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'];
// } else {
// $ifIndex = $i;
// }
//$binary_debug[$vlan_num][$i] = $ifIndex; // DEBUG
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
];
}
}
}
// EOF

View File

@ -86,7 +86,7 @@ foreach ($ports_vlans_oids as $ifIndex => $entry)
{
$vlan_num = $i;
//print_debug("ifIndex = $ifIndex, \$i = $i, mode ${entry['portMode']}");
//print_debug("ifIndex = $ifIndex, \$i = $i, mode {$entry['portMode']}");
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num]))
{
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num);

View File

@ -1,12 +1,12 @@
<?php
/*
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -20,13 +20,13 @@ $domain_index = '1';
if (safe_count($discovery_vlans[$domain_index]) &&
is_device_mib($device, [ 'CISCOSB-vlan-MIB', 'RADLAN-vlan-MIB', 'Dell-vlan-MIB',
'DLINK-3100-vlan-MIB', 'EDGECORE-vlan-MIB', 'NETGEAR-RADLAN-vlan-MIB',
'IEEE8021-Q-BRIDGE-MIB' ])) {
'A3COM-HUAWEI-LswVLAN-MIB', 'IEEE8021-Q-BRIDGE-MIB' ])) {
// Already discovered by RADLAN based vlans or IEEE8021-Q-BRIDGE-MIB
return;
}
// Simplify dot1qVlanStaticTable walk
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticName', array(), 'Q-BRIDGE-MIB');
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticName', [], 'Q-BRIDGE-MIB');
//$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticTable', array(), 'Q-BRIDGE-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
if (!snmp_status()) {
return;
@ -35,14 +35,13 @@ if (!snmp_status()) {
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticRowStatus', $dot1q_ports, 'Q-BRIDGE-MIB');
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticEgressPorts', $dot1q_ports, 'Q-BRIDGE-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
if (is_device_mib($device, 'JUNIPER-VLAN-MIB')) // Unsure if other Juniper platforms "affected"
{
if (is_device_mib($device, 'JUNIPER-VLAN-MIB')) { // Unsure if other Juniper platforms "affected"
// Fetch Juniper VLAN table for correct tag
$dot1q_ports = snmpwalk_cache_oid($device, 'jnxExVlanTable', $dot1q_ports, 'JUNIPER-VLAN-MIB');
}
/* Base port ifIndex association */
$dot1d_baseports = snmp_cache_table($device, 'dot1dBasePortIfIndex', array(), 'BRIDGE-MIB');
$dot1d_baseports = snmp_cache_table($device, 'dot1dBasePortIfIndex', [], 'BRIDGE-MIB');
// Detect min ifIndex for vlan base ports
// Why, see here: http://jira.observium.org/browse/OBS-963
@ -62,11 +61,11 @@ if ($use_baseports)
}*/
/* End base port ifIndex association */
$binary_debug = array(); // DEBUG
$binary_debug = []; // DEBUG
foreach ($dot1q_ports as $vlan_num => $vlan) {
$vlan['ifIndex'] = $vlan_num;
// FTOS vlan fix
if ($device['os'] == 'ftos') {
if ($device['os'] === 'ftos') {
// Q-BRIDGE-MIB::dot1qVlanStaticEgressPorts.1107787777, where 1107787777 is ifIndex for Vlan interface
//IF-MIB::ifDescr.1107787777 = STRING: Vlan 1
//IF-MIB::ifDescr.1107787998 = STRING: Vlan 222
@ -79,13 +78,15 @@ foreach ($dot1q_ports as $vlan_num => $vlan) {
$vlan_num = $vlan['jnxExVlanTag'];
}
$vlan_array = array('ifIndex' => $vlan['ifIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['dot1qVlanStaticName'],
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational');
$vlan_array = [
'ifIndex' => $vlan['ifIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['dot1qVlanStaticName'],
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
/* End vlans discovery */
@ -95,30 +96,27 @@ foreach ($dot1q_ports as $vlan_num => $vlan) {
$binary = hex2binmap($vlan['dot1qVlanStaticEgressPorts']);
if ($device['os'] == 'ftos') // FTOS specific
{
if ($device['os'] === 'ftos') { // FTOS specific
// FTOS devices use harder way for detect VLANs and associate ports
// See: https://www.force10networks.com/CSPortal20/TechTips/0041B_displaying_vlan_ports.aspx
// Port associations based on slot/port, each 12 hex pair (96 bin) is slot
foreach (str_split($binary, 96) as $slot => $binary_map)
{
foreach (str_split($binary, 96) as $slot => $binary_map) {
$length = strlen($binary_map);
for ($i = 0; $i < $length; $i++)
{
if ($binary_map[$i])
{
for ($i = 0; $i < $length; $i++) {
if ($binary_map[$i]) {
// Now find slot/port from ifDescr
$port_map = '% '.$slot.'/'.($i + 1);
$ifIndex = dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `ifDescr` LIKE ? AND `deleted` = ? LIMIT 1", array($device['device_id'], $port_map, 0));
$ifIndex = dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `ifDescr` LIKE ? AND `deleted` = ? LIMIT 1", [ $device['device_id'], $port_map, 0 ]);
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
);
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
];
}
}
}
@ -128,13 +126,10 @@ foreach ($dot1q_ports as $vlan_num => $vlan) {
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++)
{
if ($binary[$i])
{
for ($i = 0; $i < $length; $i++) {
if ($binary[$i]) {
//$ifIndex = $i + $vlan_ifindex_min; // This is incorrect ifIndex association!
if ($use_baseports)
{
if ($use_baseports) {
// Skip all unknown indexes (OBS-2958)
if (!isset($dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'])) { continue; }
$ifIndex = $dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'];
@ -143,13 +138,14 @@ foreach ($dot1q_ports as $vlan_num => $vlan) {
}
$binary_debug[$vlan_num][$i] = $ifIndex; // DEBUG
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
);
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
];
}
}
@ -158,18 +154,18 @@ foreach ($dot1q_ports as $vlan_num => $vlan) {
print_debug_vars($binary_debug); // DEBUG
// As last point validate access ports that vlan is added (some devices not report it in dot1qVlanStaticTable)
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qPvid', array(), 'Q-BRIDGE-MIB');
foreach ($dot1q_ports as $entry)
{
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qPvid', [], 'Q-BRIDGE-MIB');
foreach ($dot1q_ports as $entry) {
$vlan_num = $entry['dot1qPvid'];
if (!isset($discovery_vlans[$domain_index][$vlan_num]))
{
$vlan_array = array('vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => 'VLAN '.$vlan_num,
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational');
if (!isset($discovery_vlans[$domain_index][$vlan_num])) {
$vlan_array = [
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => 'VLAN '.$vlan_num,
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
}
}

View File

@ -46,7 +46,7 @@ if (!$config['enable_vrfs']) {
// Clean removed VRFs
print_debug_vars($valid['vrf']);
$where = '`device_id` = ?';
$where .= generate_query_values(array_keys((array)$valid['vrf']), 'vrf_name', '!=');
$where .= generate_query_values_and(array_keys((array)$valid['vrf']), 'vrf_name', '!=');
if ($count = dbFetchCell("SELECT COUNT(*) FROM `vrfs` WHERE $where", [ $device['device_id'] ])) {
$GLOBALS['module_stats'][$module]['deleted'] = $count;
dbDelete('vrfs', $where, [ $device['device_id'] ]);
@ -60,7 +60,7 @@ if (!$config['enable_vrfs']) {
}
print_debug_vars($vrf_ports);
$where = '`device_id` = ? AND `ifVrf` IS NOT NULL';
$where .= generate_query_values($vrf_ports, 'port_id', '!=');
$where .= generate_query_values_and($vrf_ports, 'port_id', '!=');
if ($count = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE $where", [ $device['device_id'] ])) {
//$GLOBALS['module_stats'][$module]['deleted'] = $count;
dbUpdate([ 'ifVrf' => [ 'NULL' ] ], 'ports', $where, [ $device['device_id'] ]);

View File

@ -6,13 +6,14 @@
*
* @package observium
* @subpackage entities
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Include entity specific functions
require_once($config['install_dir'] . "/includes/entities/device.inc.php");
require_once($config['install_dir'] . "/includes/entities/port.inc.php");
require_once($config['install_dir'] . "/includes/entities/storage.inc.php");
require_once($config['install_dir'] . "/includes/entities/sensor.inc.php");
require_once($config['install_dir'] . "/includes/entities/status.inc.php");
require_once($config['install_dir'] . "/includes/entities/counter.inc.php");
@ -70,11 +71,13 @@ function get_entity_attribs($entity_type, $entity_id, $refresh = FALSE) {
$device_id = $entity_id['device_id'];
// Pre-check if entity attribs for device exist
if ($refresh || !isset($GLOBALS['cache']['devices_attribs'][$device_id][$entity_type])) {
$GLOBALS['cache']['devices_attribs'][$device_id][$entity_type] = dbExist('entity_attribs', '`entity_type` = ? AND `device_id` = ?', [ $entity_type, $device_id ]);
}
cache_device_attribs_exist($device_id, $refresh);
// if ($refresh || !isset($GLOBALS['cache']['devices_attribs'][$device_id][$entity_type])) {
// $GLOBALS['cache']['devices_attribs'][$device_id][$entity_type] = dbExist('entity_attribs', '`entity_type` = ? AND `device_id` = ?', [ $entity_type, $device_id ]);
// }
// Speedup queries, when not exist attribs
if (!$GLOBALS['cache']['devices_attribs'][$device_id][$entity_type]) {
if (!isset($GLOBALS['cache']['devices_attribs'][$device_id][$entity_type]) ||
!$GLOBALS['cache']['devices_attribs'][$device_id][$entity_type]) {
return [];
}
}
@ -245,7 +248,7 @@ function get_device_entities_attribs($device_id, $entity_types = NULL)
$query = "SELECT * FROM `entity_attribs` WHERE `device_id` = ?";
if ($entity_types)
{
$query .= generate_query_values($entity_types, 'entity_type');
$query .= generate_query_values_and($entity_types, 'entity_type');
}
foreach (dbFetchRows($query, array($device_id)) as $entry)
@ -748,10 +751,6 @@ function get_entity_by_id_cache($entity_type, $entity_id) {
}
break;
case "port":
$entity = get_port_by_id($entity_id);
break;
default:
$sql = 'SELECT * FROM `'.$translate['table'].'`';
@ -793,6 +792,67 @@ function get_entity_by_id_cache($entity_type, $entity_id) {
return FALSE;
}
function cache_entities_by_id($entity_type, $entity_ids) {
global $cache;
$translate = entity_type_translate_array($entity_type);
//print_vars($translate);
foreach($entity_ids as $key => $entity_id)
{
// Skip non-numeric values and already cached entities
if(!is_numeric($entity_id) || is_array($cache[$entity_type][$entity_id])) { unset($entity_ids[$key]); }
}
if(safe_count($entity_ids) == 0) { return; } // Nothing to do
switch($entity_type) {
default:
$sql = 'SELECT * FROM `'.$translate['table'].'`';
if (isset($translate['state_table'])) {
$sql .= ' LEFT JOIN `'.$translate['state_table'].'` USING (`'.$translate['id_field'].'`)';
}
if (isset($translate['parent_table'])) {
$sql .= ' LEFT JOIN `'.$translate['parent_table'].'` USING (`'.$translate['parent_id_field'].'`)';
}
//$sql .= ' WHERE `'.$translate['table'].'`.`'.$translate['id_field'].'` IN ?';
//$sql .= ' WHERE `'.$translate['table'].'`.`'.$translate['id_field'].'` IN ('.implode(',', $entity_ids).')';
$sql .= ' WHERE 1 '.generate_query_values_and($entity_ids, '`'.$translate['table'].'`.`'.$translate['id_field'].'`');
//print_r($entity_type);
//print_r($entity_ids);
//print_r($translate);
//print_r($sql.PHP_EOL);
$entities = dbFetchRows($sql);
//print_r($entities);
//print_r(dbError());
break;
}
if (is_array($entities)) {
foreach ($entities as $entity) {
if (function_exists('humanize_' . $entity_type)) {
$do = 'humanize_' . $entity_type;
$do($entity);
}
else if (isset($translate['humanize_function']) && function_exists($translate['humanize_function'])) {
$do = $translate['humanize_function'];
$do($entity);
}
entity_rewrite($entity_type, $entity);
$entity_id = $entity[$translate['id_field']];
$cache[$entity_type][$entity_id] = $entity;
}
}
return TRUE;
}
/* Network/ARP/MAC specific entity functions */
/**
@ -874,7 +934,7 @@ function get_entity_ids_ip_by_network($entity_type, $network, $add_where = '') {
$params[] = $network_array['network_end_binary'];
} else {
// Match IP addresses by part of string
$where .= generate_query_values($network_array['address'], 'ipv4_address', $network_array['query_type']);
$where .= generate_query_values_and($network_array['address'], 'ipv4_address', $network_array['query_type']);
}
break;
case 'ipv6':
@ -890,8 +950,8 @@ function get_entity_ids_ip_by_network($entity_type, $network, $add_where = '') {
$params[] = $network_array['network_end_binary'];
} else {
// Match IP addresses by part of string
$where .= ' AND (' . generate_query_values($network_array['address'], 'ipv6_address', $network_array['query_type'], FALSE) .
' OR ' . generate_query_values($network_array['address'], 'ipv6_compressed', $network_array['query_type'], FALSE) . ')';
$where .= ' AND (' . generate_query_values_ng($network_array['address'], 'ipv6_address', $network_array['query_type']) .
' OR ' . generate_query_values_ng($network_array['address'], 'ipv6_compressed', $network_array['query_type']) . ')';
}
break;
}
@ -1198,7 +1258,7 @@ function entity_descr_definition($entity_type, $definition, $descr_entry, $count
function entity_measured_match_definition($device, $definition, $entity = [], $entity_type = NULL) {
// $entity_type unused currently
$options = array();
$options = [];
// Just append label for sorting and grouping
if (isset($definition['measured_label'])) {
@ -1210,6 +1270,10 @@ function entity_measured_match_definition($device, $definition, $entity = [], $e
$definition['measured_match'] = $definition['entity_match'];
}
if (!isset($definition['measured_match'])) {
if (isset($definition['measured']) && in_array($definition['measured'], [ 'port', 'outlet' ], TRUE)) {
// Currently for outlets
$options['measured_class'] = $definition['measured'];
}
return $options;
}
@ -1234,6 +1298,8 @@ function entity_measured_match_definition($device, $definition, $entity = [], $e
}
// Associate defined entity type
//$sql_options = [ 'no_leading_and' ];
$sql_options = [];
switch($rule['entity_type']) {
case 'entity':
// Generic entities
@ -1242,9 +1308,9 @@ function entity_measured_match_definition($device, $definition, $entity = [], $e
case 'name':
case 'label':
$sql_rules = [];
$sql_rules[] = generate_query_values($rule['match'], 'entity_descr', $sql_condition, FALSE);
$sql_rules[] = generate_query_values_ng($rule['match'], 'entity_descr', $sql_condition, $sql_options);
if (!safe_empty($rule['class'])) {
$sql_rules[] = generate_query_values($rule['match'], 'entity_class', $sql_condition, FALSE);
$sql_rules[] = generate_query_values_ng($rule['match'], 'entity_class', $sql_condition, $sql_options);
}
$sql_rule = implode(' AND ', $sql_rules);
$sql = "SELECT * FROM `entities` WHERE `device_id` = ? AND ($sql_rule) AND `deleted` = ? LIMIT 1";
@ -1262,9 +1328,9 @@ function entity_measured_match_definition($device, $definition, $entity = [], $e
case 'index':
$sql_rules = [];
$sql_rules[] = generate_query_values($rule['match'], 'entity_index', $sql_condition, FALSE);
$sql_rules[] = generate_query_values_ng($rule['match'], 'entity_index', $sql_condition, $sql_options);
if (!safe_empty($rule['class'])) {
$sql_rules[] = generate_query_values($rule['match'], 'entity_class', $sql_condition, FALSE);
$sql_rules[] = generate_query_values_ng($rule['match'], 'entity_class', $sql_condition, $sql_options);
}
$sql_rule = implode(' AND ', $sql_rules);
$sql = "SELECT * FROM `entities` WHERE `device_id` = ? AND ($sql_rule) AND `deleted` = ? LIMIT 1";
@ -1289,10 +1355,10 @@ function entity_measured_match_definition($device, $definition, $entity = [], $e
case 'ifname':
case 'label':
$sql_rules = [];
$sql_rules[] = generate_query_values($rule['match'], 'ifDescr', $sql_condition, FALSE);
$sql_rules[] = generate_query_values($rule['match'], 'ifName', $sql_condition, FALSE);
$sql_rules[] = generate_query_values($rule['match'], 'port_label', $sql_condition, FALSE);
$sql_rules[] = generate_query_values($rule['match'], 'port_label_short', $sql_condition, FALSE);
$sql_rules[] = generate_query_values_ng($rule['match'], 'ifDescr', $sql_condition, $sql_options);
$sql_rules[] = generate_query_values_ng($rule['match'], 'ifName', $sql_condition, $sql_options);
$sql_rules[] = generate_query_values_ng($rule['match'], 'port_label', $sql_condition, $sql_options);
$sql_rules[] = generate_query_values_ng($rule['match'], 'port_label_short', $sql_condition, $sql_options);
$sql_rule = implode(' OR ', $sql_rules);
$sql = "SELECT * FROM `ports` WHERE `device_id` = ? AND ($sql_rule) AND `deleted` = ? LIMIT 1";
$params = [ $device['device_id'], 0 ];
@ -1308,7 +1374,7 @@ function entity_measured_match_definition($device, $definition, $entity = [], $e
break;
case 'ifalias':
$sql_rule = generate_query_values($rule['match'], 'ifAlias', $sql_condition, FALSE);
$sql_rule = generate_query_values_ng($rule['match'], 'ifAlias', $sql_condition, $sql_options);
$sql = "SELECT * FROM `ports` WHERE `device_id` = ? AND $sql_rule AND `deleted` = ? LIMIT 1";
$params = [ $device['device_id'], 0 ];
if ($measured = dbFetchRow($sql, $params)) {
@ -1688,49 +1754,38 @@ function entity_type_translate_array($entity_type)
/**
* Returns TRUE if the logged in user is permitted to view the supplied entity.
*
* @param $entity_id
* @param $entity_type
* @param $device_id
* @param $permissions Permissions array, by default used global var $permissions generated by permissions_cache()
* @param string|integer $entity_id
* @param string $entity_type
* @param string|mixed $device_id
* @param array $permissions Permissions array, by default used global var $permissions generated by permissions_cache()
*
* @return bool
*/
// TESTME needs unit testing
function is_entity_permitted($entity_id, $entity_type, $device_id = NULL, $permissions = NULL)
{
if (is_null($permissions) && isset($GLOBALS['permissions']))
{
function is_entity_permitted($entity_id, $entity_type, $device_id = NULL, $permissions = NULL) {
if (is_null($permissions) && isset($GLOBALS['permissions'])) {
// Note, pass permissions array by param used in permissions_cache()
$permissions = $GLOBALS['permissions'];
$permissions = (array)$GLOBALS['permissions'];
}
if (!is_numeric($device_id)) { $device_id = get_device_id_by_entity_id($entity_id, $entity_type); }
if ($_SESSION['userlevel'] >= 5)
{
if ($_SESSION['userlevel'] >= 5) {
// User not limited (userlevel >= 5)
$allowed = TRUE;
}
else if (is_numeric($device_id) && device_permitted($device_id))
{
} elseif (is_numeric($device_id) && device_permitted($device_id)) {
$allowed = TRUE;
}
else if (isset($permissions[$entity_type][$entity_id]) && $permissions[$entity_type][$entity_id])
{
} elseif (isset($permissions[$entity_type][$entity_id]) && $permissions[$entity_type][$entity_id]) {
$allowed = TRUE;
}
else if (isset($GLOBALS['auth']) && is_graph())
{
} elseif (isset($GLOBALS['auth']) && is_graph()) {
$allowed = $GLOBALS['auth'];
} else {
$allowed = FALSE;
}
if (OBS_DEBUG)
{
$debug_msg = "PERMISSIONS CHECK. Entity type: $entity_type, Entity ID: $entity_id, Device ID: ".($device_id ? $device_id : 'NULL').", Allowed: ".($allowed ? 'TRUE' : 'FALSE').".";
if (isset($GLOBALS['notifications']))
{
if (OBS_DEBUG) {
$debug_msg = "PERMISSIONS CHECK. Entity type: $entity_type, Entity ID: $entity_id, Device ID: ".($device_id ?: 'NULL') . ", Allowed: " . ($allowed ? 'TRUE' : 'FALSE') . ".";
if (isset($GLOBALS['notifications'])) {
$GLOBALS['notifications'][] = array('text' => $debug_msg, 'severity' => 'debug');
} else {
print_debug($debug_msg);
@ -1742,46 +1797,37 @@ function is_entity_permitted($entity_id, $entity_type, $device_id = NULL, $permi
/**
* Returns TRUE if the logged in user is permitted to view the supplied entity.
*
* @param $entity_id
* @param $entity_type
* @param $device_id
* @param $permissions Permissions array, by default used global var $permissions generated by permissions_cache()
* @param string|integer $entity_id
* @param string $entity_type
* @param string|mixed $device_id
* @param array $permissions Permissions array, by default used global var $permissions generated by permissions_cache()
*
* @return bool
*/
// TESTME needs unit testing
function is_entity_write_permitted($entity_id, $entity_type, $device_id = NULL, $permissions = NULL)
{
if (is_null($permissions) && isset($GLOBALS['permissions']))
{
function is_entity_write_permitted($entity_id, $entity_type, $device_id = NULL, $permissions = NULL) {
if (is_null($permissions) && isset($GLOBALS['permissions'])) {
// Note, pass permissions array by param used in permissions_cache()
$permissions = $GLOBALS['permissions'];
$permissions = (array)$GLOBALS['permissions'];
}
if (!is_numeric($device_id)) { $device_id = get_device_id_by_entity_id($entity_id, $entity_type); }
if ($_SESSION['userlevel'] >= 9)
{
if ($_SESSION['userlevel'] >= 9) {
// User has global device/entity write permissions
$allowed = TRUE;
}
else if (is_numeric($device_id) && isset($permissions['device'][$device_id]) && $permissions['device'][$device_id] == "rw")
{
} elseif (is_numeric($device_id) && isset($permissions['device'][$device_id]) && $permissions['device'][$device_id] === "rw") {
// User has device write permissions
$allowed = TRUE;
}
else if (isset($permissions[$entity_type][$entity_id]) && $permissions[$entity_type][$entity_id] == "rw")
{
} elseif (isset($permissions[$entity_type][$entity_id]) && $permissions[$entity_type][$entity_id] === "rw") {
$allowed = TRUE;
} else {
$allowed = FALSE;
}
if (OBS_DEBUG)
{
$debug_msg = "WRITE PERMISSIONS CHECK. Entity type: $entity_type, Entity ID: $entity_id, Device ID: ".($device_id ? $device_id : 'NULL').", Allowed: ".($allowed ? 'TRUE' : 'FALSE').".";
if (isset($GLOBALS['notifications']))
{
if (OBS_DEBUG) {
$debug_msg = "WRITE PERMISSIONS CHECK. Entity type: $entity_type, Entity ID: $entity_id, Device ID: ".($device_id ?: 'NULL') . ", Allowed: " . ($allowed ? 'TRUE' : 'FALSE') . ".";
if (isset($GLOBALS['notifications'])) {
$GLOBALS['notifications'][] = array('text' => $debug_msg, 'severity' => 'debug');
} else {
print_debug($debug_msg);

View File

@ -23,7 +23,7 @@
* @return array
*/
function build_initial_device_array($hostname, $snmp_community, $snmp_version, $snmp_port = 161, $snmp_transport = 'udp', $options = []) {
$device = array();
$device = [];
$device['hostname'] = $hostname;
$device['snmp_port'] = $snmp_port;
$device['snmp_transport'] = $snmp_transport;
@ -46,6 +46,11 @@ function build_initial_device_array($hostname, $snmp_community, $snmp_version, $
}
}
// Append SNMPable OIDs if passed
if (isset($options['snmpable']) && strlen($options['snmpable'])) {
$device['snmpable'] = $options['snmpable'];
}
// Append SNMP context if passed
if (isset($options['snmp_context']) && strlen($options['snmp_context'])) {
$device['snmp_context'] = $options['snmp_context'];
@ -71,7 +76,7 @@ function add_device_vars($vars) {
// Add device to remote poller,
// only validate vars and add to pollers_actions
if (is_intnum($vars['poller_id']) && $vars['poller_id'] != $config['poller_id']) {
print_message("Requested add device with hostname '$hostname' to remote Poller [${vars['poller_id']}].");
print_message("Requested add device with hostname '$hostname' to remote Poller [{$vars['poller_id']}].");
if (!(is_valid_hostname($hostname) || get_ip_version($hostname))) {
// Failed DNS lookup
print_error("Hostname '$hostname' is not valid.");
@ -94,8 +99,8 @@ function add_device_vars($vars) {
}
if (function_exists('add_action_queue') &&
$action_id = add_action_queue('device_add', $hostname, $vars)) {
print_message("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [${vars['poller_id']}].");
log_event("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [${vars['poller_id']}].", NULL, 'info', NULL, 7);
print_message("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [{$vars['poller_id']}].");
log_event("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [{$vars['poller_id']}].", NULL, 'info', NULL, 7);
return TRUE;
}
print_error("Device with hostname '$hostname' not added. Incorrect addition to actions queue.");
@ -106,6 +111,25 @@ function add_device_vars($vars) {
$config_snmp = $config['snmp'];
$config_rrd = $config['rrd_override'];
$snmp_oids = [];
if (isset($vars['snmpable']) && !empty($vars['snmpable'])) {
foreach (explode(' ', $vars['snmpable']) as $oid) {
if (preg_match(OBS_PATTERN_SNMP_OID_NUM, $oid)) {
// Valid Numeric OID
$snmp_oids[] = $oid;
} elseif (str_contains($oid, '::') && $oid_num = snmp_translate($oid)) {
// Named MIB::Oid which we can translate
$snmp_oids[] = $oid_num;
} else {
print_warning("Invalid or unknown OID: ".$oid);
}
}
if (empty($snmp_oids)) {
print_error("Incorrect or not numeric OIDs passed for check device availability.");
return FALSE;
}
}
// Default snmp port
if (is_valid_param($vars['snmp_port'], 'port')) {
$snmp_port = (int)$vars['snmp_port'];
@ -124,10 +148,10 @@ function add_device_vars($vars) {
case 'v2c':
case 'v1':
if (strlen($vars['snmp_community'])) {
if (!safe_empty($vars['snmp_community'])) {
// Hrm, I not sure why strip_tags
$snmp_community = strip_tags($vars['snmp_community']);
$config['snmp']['community'] = array($snmp_community);
$config['snmp']['community'] = [ $snmp_community ];
}
$snmp_version = $vars['snmp_version'];
@ -137,15 +161,15 @@ function add_device_vars($vars) {
case 'v3':
if (strlen($vars['snmp_authlevel'])) {
$snmp_v3 = array (
if (!safe_empty($vars['snmp_authlevel'])) {
$snmp_v3 = [
'authlevel' => $vars['snmp_authlevel'],
'authname' => $vars['snmp_authname'],
'authpass' => $vars['snmp_authpass'],
'authalgo' => $vars['snmp_authalgo'],
'cryptopass' => $vars['snmp_cryptopass'],
'cryptoalgo' => $vars['snmp_cryptoalgo'],
);
];
array_unshift($config['snmp']['v3'], $snmp_v3);
}
@ -164,7 +188,7 @@ function add_device_vars($vars) {
$config['rrd_override'] = TRUE;
}
$snmp_options = array();
$snmp_options = [];
if (get_var_true($vars['ping_skip'])) {
$snmp_options['ping_skip'] = TRUE;
}
@ -182,6 +206,11 @@ function add_device_vars($vars) {
$snmp_options['snmp_maxrep'] = trim($vars['snmp_maxrep']);
}
// Optional SNMPable OIDs
if ($snmp_oids) {
$snmp_options['snmpable'] = implode(' ', $snmp_oids);
}
// Optional SNMP Context
if (trim($vars['snmp_context']) !== '') {
$snmp_options['snmp_context'] = trim($vars['snmp_context']);
@ -213,7 +242,7 @@ function add_device_vars($vars) {
* @return mixed Returns $device_id number if added, 0 (zero) if device not accessible with current auth and FALSE if device complete not accessible by network. When testing, returns -1 if the device is available.
*/
// TESTME needs unit testing
function add_device($hostname, $snmp_version = array(), $snmp_port = 161, $snmp_transport = 'udp', $options = array(), $flags = OBS_DNS_ALL) {
function add_device($hostname, $snmp_version = [], $snmp_port = 161, $snmp_transport = 'udp', $options = [], $flags = OBS_DNS_ALL) {
global $config;
// If $options['break'] set as TRUE, break recursive function execute
@ -315,6 +344,11 @@ function add_device($hostname, $snmp_version = array(), $snmp_port = 161, $snmp_
}
}
// Append SNMPable oids if passed
if (isset($options['snmpable']) && strlen($options['snmpable'])) {
$snmp['snmpable'] = $options['snmpable'];
}
// Append SNMP context if passed
if (isset($options['snmp_context']) && strlen($options['snmp_context'])) {
$snmp['snmp_context'] = $options['snmp_context'];
@ -371,6 +405,11 @@ function add_device($hostname, $snmp_version = array(), $snmp_port = 161, $snmp_
}
}
// Append SNMPable oids if passed
if (isset($options['snmpable']) && strlen($options['snmpable'])) {
$snmp['snmpable'] = $options['snmpable'];
}
// Append SNMP context if passed
if (isset($options['snmp_context']) && strlen($options['snmp_context'])) {
$snmp['snmp_context'] = $options['snmp_context'];
@ -384,6 +423,9 @@ function add_device($hostname, $snmp_version = array(), $snmp_port = 161, $snmp_
print_message("Trying $snmp_version community $snmp_community ...");
}
//r($options);
//r($snmp);
//r($device);
if (isSNMPable($device)) {
if (!check_device_duplicated($device)) {
if (isset($options['test']) && $options['test']) {
@ -920,6 +962,11 @@ function create_device($hostname, $snmp = []) {
}
}
// Append SNMPable oids if passed
if (isset($snmp['snmpable'])) {
$device['snmpable'] = $snmp['snmpable'];
}
// Local poller id (for distributed system)
$poller_id = $GLOBALS['config']['poller_id']; // $config['poller_id'] sets in sql-config.php
if (isset($GLOBALS['config']['poller_name']) &&
@ -1014,7 +1061,7 @@ function delete_device($id, $delete_rrd = FALSE) {
$deleted_entities = array();
foreach (get_device_entities($id) as $entity_type => $entity_ids) {
foreach ($config['entity_tables'] as $table) {
$where = '`entity_type` = ?' . generate_query_values($entity_ids, 'entity_id');
$where = '`entity_type` = ?' . generate_query_values_and($entity_ids, 'entity_id');
$table_status = dbDelete($table, $where, array($entity_type));
if ($table_status) { $deleted_entities[$entity_type] = 1; }
}
@ -1072,14 +1119,15 @@ function device_status_array(&$device) {
$flags |= OBS_PING_SKIP; // Add skip ping flag
}
$device['pingable'] = is_pingable($device['hostname'], $flags);
if ($device['pingable']) {
$device['snmpable'] = isSNMPable($device);
if ($device['snmpable']) {
$ping_msg = ($attribs['ping_skip'] ? '' : 'PING (' . $device['pingable'] . 'ms) and ');
$device['status_pingable'] = is_pingable($device['hostname'], $flags);
$device['pingable'] = $device['status_pingable']; // Compat
if ($device['status_pingable']) {
$device['status_snmpable'] = isSNMPable($device);
if ($device['status_snmpable']) {
$ping_msg = ($attribs['ping_skip'] ? '' : 'PING (' . $device['status_pingable'] . 'ms) and ');
//print_cli_data("Device status", "Device is reachable by " . $ping_msg . "SNMP (".$device['snmpable']."ms)", 1);
$status_message = "Device is reachable by " . $ping_msg . "SNMP (".$device['snmpable']."ms)";
//print_cli_data("Device status", "Device is reachable by " . $ping_msg . "SNMP (".$device['status_snmpable']."ms)", 1);
$status_message = "Device is reachable by " . $ping_msg . "SNMP (".$device['status_snmpable']."ms)";
$status = "1";
$status_type = 'ok';
} else {
@ -1094,6 +1142,7 @@ function device_status_array(&$device) {
$status = "0";
//print_vars(get_status_var('ping_dns'));
if (isset_status_var('ping_dns') && get_status_var('ping_dns') !== 'ok') {
$status_message = "Device hostname is not resolved";
$status_type = 'dns';
} else {
$status_type = 'ping';
@ -1103,6 +1152,48 @@ function device_status_array(&$device) {
return [ 'status' => $status, 'status_type' => $status_type, 'message' => $status_message ];
}
/**
* Return device name based on default hostname setting, ie purpose, descr, sysname
* @param array $device Device array
* @param integer $max_len Maximum length for returned name.
*
* @return string
*/
function device_name($device, $max_len = FALSE) {
global $config;
switch (strtolower($config['web_device_name'])) {
case 'sysname':
$name_field = 'sysName';
break;
case 'purpose':
case 'descr':
case 'description':
$name_field = 'purpose';
break;
default:
$name_field = 'hostname';
}
if ($max_len && !is_intnum($max_len)) {
$max_len = $config['short_hostname']['length'];
}
if ($name_field !== 'hostname' && !safe_empty($device[$name_field])) {
if ($name_field === 'sysName' && $max_len && $max_len > 3) {
// short sysname when is valid hostname (do not escape here)
return short_hostname($device[$name_field], $max_len, FALSE);
}
return $device[$name_field];
}
if ($max_len && $max_len > 3) {
// short hostname (do not escape here)
return short_hostname($device['hostname'], $max_len, FALSE);
}
return $device['hostname'];
}
/**
* Return device hostname or ip address, based on setting $config['use_ip']
*
@ -1195,52 +1286,58 @@ function get_device_id_by_entity_id($entity_id, $entity_type) {
// DOCME needs phpdoc block
// TESTME needs unit testing
function device_by_id_cache($device_id, $refresh = 0)
{
function device_by_id_cache($device_id, $refresh = FALSE) {
global $cache;
if (!$refresh && isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id]))
{
if (!$refresh &&
isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id])) {
$device = $cache['devices']['id'][$device_id];
// Note, cached $device can be not humanized (by cache-data)
$refresh = !isset($device['humanized']);
} else {
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", [ $device_id ]);
$refresh = TRUE; // Set refresh
}
if (!empty($device))
{
if (!empty($device) && $refresh) {
humanize_device($device);
if ($refresh || !isset($device['graphs']))
{
// Fetch device graphs
$device['graphs'] = dbFetchRows("SELECT * FROM `device_graphs` WHERE `device_id` = ?", array($device_id));
}
$cache['devices']['id'][$device_id] = $device;
get_device_graphs($device);
return $device;
} else {
return FALSE;
// Add to memory cache
$cache['devices']['id'][$device_id] = $device;
}
return $device;
}
function get_device_graphs(&$device) {
//if ($refresh || !isset($device['graphs']))
//{
// Fetch device graphs
foreach(dbFetchRows("SELECT * FROM `device_graphs` WHERE `device_id` = ?", [ $device['device_id'] ]) as $graph) {
$device['graphs'][$graph['graph']] = $graph;
}
//}
}
// DOCME needs phpdoc block
// TESTME needs unit testing
function get_device_id_by_hostname($hostname)
{
function get_device_id_by_hostname($hostname) {
global $cache;
if (isset($cache['devices']['hostname'][$hostname]))
{
if (isset($cache['devices']['hostname'][$hostname])) {
$id = $cache['devices']['hostname'][$hostname];
} else {
$id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `hostname` = ?", array($hostname));
$id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `hostname` = ?", [ $hostname ]);
}
if (is_numeric($id))
{
if (is_numeric($id)) {
return $id;
} else {
return FALSE;
}
return FALSE;
}
// DOCME needs phpdoc block
@ -1517,7 +1614,7 @@ function poll_device_mib_metatypes($device, $metatypes, &$poll_device = []) {
}
// if test not required, use first entry (as getnext)
$value = $values[$entry['oid']];
$full_oid = "$mib::${entry['oid']}.$index";
$full_oid = "$mib::{$entry['oid']}.$index";
break;
}
} elseif (isset($entry['oid_num'])) { // Use numeric OID if set, otherwise fetch text based string
@ -1526,15 +1623,15 @@ function poll_device_mib_metatypes($device, $metatypes, &$poll_device = []) {
} elseif (isset($entry['oid_next'])) {
// If Oid passed without index part use snmpgetnext (see FCMGMT-MIB definitions)
$value = snmp_getnext_oid($device, $entry['oid_next'], $mib, NULL, $flags);
$full_oid = "$mib::${entry['oid_next']}";
$full_oid = "$mib::{$entry['oid_next']}";
} elseif (isset($entry['oid_count'])) {
// This is special type of get data by snmpwalk and count entries
$data = snmpwalk_values($device, $entry['oid_count'], $mib);
$value = is_array($data) ? count($data) : '';
$full_oid = str_starts($entry['oid_count'], '.') ? $entry['oid_count'] : "$mib::${entry['oid_count']}";
$full_oid = str_starts($entry['oid_count'], '.') ? $entry['oid_count'] : "$mib::{$entry['oid_count']}";
} else {
$value = snmp_get_oid($device, $entry['oid'], $mib, NULL, $flags);
$full_oid = "$mib::${entry['oid']}";
$full_oid = "$mib::{$entry['oid']}";
}
if (snmp_status() && !safe_empty($value)) {
@ -1559,6 +1656,13 @@ function poll_device_mib_metatypes($device, $metatypes, &$poll_device = []) {
if ($metatype === 'version' && preg_match('/^[\d\.]+$/', $value)) {
// version -> xxx.y.z
$value .= '.' . implode('.', $extra);
} elseif ($metatype === 'sysname') {
$tmp = $value . '.' . implode('.', $extra);
if (is_valid_hostname($tmp, TRUE)) {
// Ie: ALLOT-MIB
$value = $tmp;
}
unset($tmp);
} else {
// others -> xxx (y, z)
$value .= ' (' . implode(', ', $extra) . ')';
@ -1594,6 +1698,9 @@ function poll_device_mib_metatypes($device, $metatypes, &$poll_device = []) {
//$uptimes['message'] = 'Using device MIB poller '.$metatype.': ' . $uptimes['message'];
print_debug("Added System Uptime from SNMP definition fetch: 'device_uptime' = '$value'");
// Continue for other possible sysUpTime and use maximum value
// but from different MIBs when valid time found (example UBNT-UniFi-MIB)
continue 2;
}
// Continue for other possible sysUpTime and use maximum value
continue;
@ -1649,7 +1756,7 @@ function poll_device_unix_packages($device, $metatypes, $defs = []) {
// by unix-agent packages
//$sql = 'SELECT * FROM `packages` WHERE `device_id` = ? AND `status` = ? AND `name` IN (?, ?, ?)';
$sql = 'SELECT * FROM `packages` WHERE `device_id` = ? AND `status` = ?';
$sql .= generate_query_values(array_keys($package_defs), 'name');
$sql .= generate_query_values_and(array_keys($package_defs), 'name');
$params = [ $device['device_id'], 1 ];
if ($package = dbFetchRow($sql, $params)) {
//$name = $package['name'];
@ -1759,8 +1866,33 @@ function poll_device_unix_packages($device, $metatypes, $defs = []) {
return $data;
}
function cache_device_attribs_exist($device, $refresh = FALSE) {
if (is_array($device)) {
$device_id = $device['device_id'];
} else {
$device_id = $device;
}
// Pre-check if entity attribs for device exist
if ($refresh || !isset($GLOBALS['cache']['devices_attribs'][$device_id])) {
$GLOBALS['cache']['devices_attribs'][$device_id] = [];
foreach (dbFetchColumn('SELECT DISTINCT `entity_type` FROM `entity_attribs` WHERE `device_id` = ?', [ $device_id ]) as $entity_type) {
$GLOBALS['cache']['devices_attribs'][$device_id][$entity_type] = TRUE;
}
//r($GLOBALS['cache']['devices_attribs'][$device_id]);
//$GLOBALS['cache']['devices_attribs'][$device_id][$entity_type] = dbExist('entity_attribs', '`entity_type` = ? AND `device_id` = ?', [ $entity_type, $device_id ]);
}
}
/* OBSOLETE, BUT STILL USED FUNCTIONS */
// CLEANME remove when all function calls will be deleted
function get_dev_attrib($device, $attrib_type)
{
// Call to new function
return get_entity_attrib('device', $device, $attrib_type);
}
// CLEANME remove when all function calls will be deleted
function get_dev_attribs($device_id)
{

View File

@ -278,7 +278,7 @@ function get_ip_prefix($entry) {
$net = Net_IPv4::parseAddress($entry['ip'].'/'.$prefix);
if (Net_IPv4::ipInNetwork($entry['gateway'], $net->network.'/'.$prefix)) {
// Gateway IP in network, stop loop
print_debug("Prefix '$prefix' detected by IP '${entry['ip']}' and Gateway '${entry['gateway']}'.");
print_debug("Prefix '$prefix' detected by IP '{$entry['ip']}' and Gateway '{$entry['gateway']}'.");
break;
}
$prefix++;
@ -291,7 +291,7 @@ function get_ip_prefix($entry) {
if (Net_IPv4::ipInNetwork($entry['gateway'], $net->network.'/'.$tmp_prefix)) {
// Gateway IP in network, stop loop
$prefix = $tmp_prefix;
print_debug("Prefix '$prefix' detected by IP '${entry['ip']}' and Gateway '${entry['gateway']}'.");
print_debug("Prefix '$prefix' detected by IP '{$entry['ip']}' and Gateway '{$entry['gateway']}'.");
break;
}
$tmp_prefix--;
@ -313,7 +313,7 @@ function get_ip_prefix($entry) {
}
// Incorrect IP
print_debug("Incorrect: ${entry['ip']}");
print_debug("Incorrect: {$entry['ip']}");
return NULL;
}

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage entities
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -87,21 +87,24 @@ function get_port_id_by_ip_cache($device, $ip)
// DOCME needs phpdoc block
// TESTME needs unit testing
function get_port_id_by_mac($device, $mac)
{
if (is_array($device) && isset($device['device_id']))
{
function get_port_id_by_mac($device, $mac) {
if (is_array($device) && isset($device['device_id'])) {
$device_id = $device['device_id'];
}
elseif (is_numeric($device))
{
} elseif (is_numeric($device)) {
$device_id = $device;
} else {
return FALSE;
}
$remote_mac = mac_zeropad($mac);
if ($remote_mac && $remote_mac != '000000000000')
{
return dbFetchCell("SELECT `port_id` FROM `ports` WHERE `deleted` = '0' AND `ifPhysAddress` = ? AND `device_id` = ? LIMIT 1", [ $remote_mac, $device_id ]);
if ($remote_mac && $remote_mac !== '000000000000' &&
$ids = dbFetchColumn("SELECT `port_id` FROM `ports` WHERE `ifPhysAddress` = ? AND `device_id` = ? AND `deleted` = ?", [ $remote_mac, $device_id, 0 ])) {
if (count($ids) > 1) {
print_debug("WARNING. Found multiple ports [".count($ids)."] with same MAC address $mac on device ($device_id).");
}
return $ids[0];
//return dbFetchCell("SELECT `port_id` FROM `ports` WHERE `deleted` = '0' AND `ifPhysAddress` = ? AND `device_id` = ? LIMIT 1", [ $remote_mac, $device_id ]);
}
return FALSE;
@ -507,14 +510,14 @@ function get_port_id_by_customer($customer)
{
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'type':
case 'descr':
case 'circuit':
case 'speed':
case 'notes':
$where .= generate_query_values($value, 'port_descr_'.$var);
$where .= generate_query_values_and($value, 'port_descr_'.$var);
break;
}
}
@ -573,17 +576,17 @@ function get_device_ids_by_customer($type, $customer)
{
case 'device':
case 'device_id':
$where .= generate_query_values($customer, 'device_id');
$where .= generate_query_values_and($customer, 'device_id');
break;
case 'type':
case 'descr':
case 'circuit':
case 'speed':
case 'notes':
$where .= generate_query_values($customer, 'port_descr_'.$type);
$where .= generate_query_values_and($customer, 'port_descr_'.$type);
break;
default:
$where .= generate_query_values($customer, 'port_descr_descr');
$where .= generate_query_values_and($customer, 'port_descr_descr');
}
$query = 'SELECT DISTINCT `device_id` FROM `ports` ' . $where;
@ -808,7 +811,7 @@ function delete_port($int_id, $delete_rrd = TRUE) {
$deleted_entities = array();
foreach ($config['entity_tables'] as $table)
{
$where = '`entity_type` = ?' . generate_query_values($int_id, 'entity_id');
$where = '`entity_type` = ?' . generate_query_values_and($int_id, 'entity_id');
$table_status = dbDelete($table, $where, array('port'));
if ($table_status) { $deleted_entities['port'] = 1; }
}
@ -910,6 +913,11 @@ function get_port_rrdindex($port)
return $this_port_identifier;
}
// DOCME needs phpdoc block
function humanspeed($speed) {
return safe_empty($speed) ? '-' : formatRates($speed);
}
// CLEANME DEPRECATED
function get_port_rrdfilename($port, $suffix = NULL, $fullpath = FALSE)
{

View File

@ -223,7 +223,14 @@ function get_bgp_localas_array($device) {
// append this mib to entries, ie HUAWEI-BGP-VPN-MIB, CUMULUS-BGPUN-MIB
snmp_getnext_oid($device, $def['oids']['PeerRemoteAs']['oid'], $mib);
if (snmp_status()) {
$entries[] = [ 'mib' => $mib ];
$entry = [ 'mib' => $mib ];
if ($mib === 'CUMULUS-BGPUN-MIB' && $local_as = snmp_get_oid($device, 'bgpLocalAs', $mib)) {
// Cumulus OS not always return LocalAs
$entry['oid'] = 'bgpLocalAs';
$entry['LocalAs'] = snmp_dewrap32bit($local_as); // .1.3.6.1.4.1.40310.4.2 = INTEGER: 64732
}
$entries[] = $entry;
unset($entry);
}
}
@ -552,6 +559,37 @@ function parse_bgp_peer_index(&$peer, $index, $mib = 'BGP4V2-MIB') {
if (get_ip_version($peer_ip)) {
$peer['os10bgp4V2PeerRemoteAddr'] = $peer_ip;
}
// Uptimes really reported with x100 multiplier
if (isset($peer['os10bgp4V2PeerFsmEstablishedTime'])) {
$peer['os10bgp4V2PeerFsmEstablishedTime'] *= 0.01;
}
if (isset($peer['os10bgp4V2PeerInUpdatesElapsedTime'])) {
$peer['os10bgp4V2PeerInUpdatesElapsedTime'] *= 0.01;
}
// It seems as firmware issue, always report as halted
// See: https://jira.observium.org/browse/OBS-4134
if ($peer['os10bgp4V2PeerAdminStatus'] === 'halted' && $peer['os10bgp4V2PeerState'] !== 'idle') {
// running: established, connect, active (not sure about opensent, openconfirm)
print_debug("Fixed Dell OS10 issue, DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus always report halted");
$peer['os10bgp4V2PeerAdminStatus'] = 'running';
} elseif ($peer['os10bgp4V2PeerAdminStatus'] === 'running' && $peer['os10bgp4V2PeerState'] === 'idle') {
// See: https://jira.observium.org/browse/OBS-4280
/*
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus.1.ipv4."255.79.16.154" = INTEGER: halted(1)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus.1.ipv4."255.118.129.119" = INTEGER: running(2)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus.1.ipv4."254.145.182.212" = INTEGER: halted(1)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus.1.ipv4."254.145.182.214" = INTEGER: halted(1)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerState.1.ipv4."255.79.16.154" = INTEGER: established(6)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerState.1.ipv4."255.118.129.119" = INTEGER: idle(1)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerState.1.ipv4."254.145.182.212" = INTEGER: established(6)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerState.1.ipv4."254.145.182.214" = INTEGER: established(6)
*/
print_debug("Fixed Dell OS10 issue, DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus report running for shutdown");
$peer['os10bgp4V2PeerAdminStatus'] = 'halted';
}
break;
case 'FORCE10-BGP4-V2-MIB':
@ -625,6 +663,24 @@ function parse_bgp_peer_index(&$peer, $index, $mib = 'BGP4V2-MIB') {
$peer['bgpBgpNeighborAdminState'] = in_array($peer['bgpBgpNeighborState'], [ 'clearing', 'deleted' ]) ? 'stop' : 'start';
}
break;
case 'FIREBRICK-BGP-MIB':
$peer_type = array_shift($index_parts);
if (isset($address_types[$peer_type])) {
$peer['fbBgpPeerAddressType'] = $address_types[$peer_type];
}
$ip_len = array_shift($index_parts);
$peer_ip = implode('.', $index_parts);
if ((int)$ip_len === 16) {
$peer_ip = snmp2ipv6($peer_ip);
}
$peer['fbBgpPeerAddress'] = $peer_ip;
if (!isset($peer['fbBgpPeerAdminState'])) {
// Always set this Oid to start, while not really exist and while peer entry exist in this table
$peer['fbBgpPeerAdminState'] = in_array($peer['fbBgpPeerState'], [ 'clearing', 'deleted' ]) ? 'stop' : 'start';
}
break;
}
}

View File

@ -6,42 +6,36 @@
*
* @package observium
* @subpackage entities
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
/// MOVEME. states.inc.php
function get_bits_state_array($hex, $mib = NULL, $object = NULL, $bits_def = NULL)
{
function get_bits_state_array($hex, $mib = NULL, $object = NULL, $bits_def = NULL) {
global $config;
// Fetch validate BITS definition
if (is_array($bits_def))
{
if (!empty($bits_def) && is_array($bits_def)) {
// Use passed bits definitions
$def = $bits_def;
}
else if (strlen($mib) && strlen($object) &&
isset($config['mibs'][$mib]['states_bits'][$object]))
{
} elseif (!safe_empty($mib) && !safe_empty($object) &&
isset($config['mibs'][$mib]['states_bits'][$object])) {
$def = $config['mibs'][$mib]['states_bits'][$object];
}
if (empty($def))
{
if (empty($def) || !is_array($def)) {
print_debug("Incorrect BITS state definition passed.");
return NULL;
return [];
}
print_debug_vars($def);
//print_debug_vars($def);
//$bit_array = array_reverse(str_split(hex2binmap($hex)));
$bit_array = str_split(hex2binmap($hex));
print_debug_vars($bit_array);
//print_debug_vars($bit_array);
$state_array = [];
foreach ($bit_array as $bit => $value)
{
if ($value)
{
foreach ($bit_array as $bit => $set) {
if ($set) {
$state_array[$bit] = $def[$bit]['name'];
}
}
@ -736,7 +730,7 @@ function poll_status($device, &$oid_cache)
if (isset($old_state_array['discovery']) && is_module_enabled($device, $old_state_array['discovery'], 'discovery'))
{
force_discovery($device, $old_state_array['discovery']);
print_debug("Module ${old_state_array['discovery']} force for discovery by changed status type ${status_db['status_mib']}::${status_db['status_object']}");
print_debug("Module {$old_state_array['discovery']} force for discovery by changed status type {$status_db['status_mib']}::{$status_db['status_object']}");
}
}
} else {

View File

@ -0,0 +1,478 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage entities
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
function discover_storage_definition($device, $mib, $entry, $object) {
$entry['found'] = FALSE;
$entry['object'] = $object;
echo($object . ' [');
// Just append mib name to definition entry, for simple pass to external functions
if (empty($entry['mib'])) {
$entry['mib'] = $mib;
}
// Check that types listed in skip_if_valid_exist have already been found
if (discovery_check_if_type_exist($entry, 'storage')) { echo '!]'; return; }
// Check array requirements list
if (discovery_check_requires_pre($device, $entry, 'storage')) { echo '!]'; return; }
// oid_*_hc and oid_*_high/oid_*_low used with storage_hc flag
$table_oids = [ 'oid_total', 'oid_total_hc', 'oid_total_high', 'oid_total_low',
'oid_used', 'oid_used_hc', 'oid_used_high', 'oid_used_low',
'oid_free', 'oid_free_hc', 'oid_free_high', 'oid_free_low',
'oid_perc', 'oid_descr', 'oid_scale', 'oid_unit',
'oid_type', 'oid_online', 'oid_extra',
//'oid_limit_low', 'oid_limit_low_warn', 'oid_limit_high_warn', 'oid_limit_high',
//'oid_limit_nominal', 'oid_limit_delta_warn', 'oid_limit_delta', 'oid_limit_scale'
];
$storage_array = discover_fetch_oids($device, $mib, $entry, $table_oids);
// FIXME - generify description generation code and just pass it template and OID array.
$i = 1; // Used in descr as %i%
$storage_count = count($storage_array);
foreach ($storage_array as $index => $storage_entry) {
$options = [];
//$oid_num = $entry['oid_num'] . '.' . $index;
// Storage Type
if (isset($entry['oid_type']) && $storage_entry[$entry['oid_type']]) {
$storage_entry['type'] = $storage_entry[$entry['oid_type']];
} elseif (isset($entry['type'])) {
$storage_entry['type'] = $entry['type'];
} else {
// Compat (incorrect)
$storage_entry['type'] = $object;
}
$options['storage_type'] = $storage_entry['type'];
// Generate storage description
$storage_entry['i'] = $i;
$storage_entry['index'] = $index;
foreach (explode('.', $index) as $k => $i) {
$storage_entry['index'.$k] = $i; // Index parts
}
$descr = entity_descr_definition('storage', $entry, $storage_entry, $storage_count);
// Check valid exist with entity tags
if (discovery_check_if_type_exist($entry, 'storage', $storage_entry)) { continue; }
// Check array requirements list
if (discovery_check_requires($device, $entry, $storage_entry, 'storage')) { continue; }
// Init
$used = NULL;
$total = NULL;
$free = NULL;
$perc = NULL;
$hc = isset($entry['hc']) && $entry['hc'];
// Convert strings '3.40 TB' to value
// See QNAP NAS-MIB or HIK-DEVICE-MIB
$unit = !isset($entry['unit']) ? NULL : $entry['unit'];
// Fetch used, total, free and percentage values, if OIDs are defined for them
if (!safe_empty($entry['total'])) {
// Prefer hardcoded total over SNMP OIDs
$total = $entry['total'];
} else {
if (isset($entry['oid_total_high'], $entry['oid_total_low'])) {
$high = snmp_fix_numeric($storage_entry[$entry['oid_total_high']]);
$low = snmp_fix_numeric($storage_entry[$entry['oid_total_low']]);
if ($total = snmp_size64_high_low($high, $low)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($total) && isset($entry['oid_total_hc']) &&
$total = snmp_fix_numeric($storage_entry[$entry['oid_total_hc']], $unit)) {
$hc = TRUE; // set HC flag
}
if (!is_numeric($total) && isset($entry['oid_total'])) {
$total = snmp_fix_numeric($storage_entry[$entry['oid_total']], $unit);
}
}
if (isset($entry['oid_used_high'], $entry['oid_used_low'])) {
$high = snmp_fix_numeric($storage_entry[$entry['oid_used_high']]);
$low = snmp_fix_numeric($storage_entry[$entry['oid_used_low']]);
$used = snmp_size64_high_low($high, $low);
if (is_numeric($used)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($used) && isset($entry['oid_used_hc'])) {
$used = snmp_fix_numeric($storage_entry[$entry['oid_used_hc']], $unit);
if (is_numeric($used)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($used) && isset($entry['oid_used'])) {
$used = snmp_fix_numeric($storage_entry[$entry['oid_used']], $unit);
}
if (isset($entry['oid_free_high'], $entry['oid_free_low'])) {
$high = snmp_fix_numeric($storage_entry[$entry['oid_free_high']]);
$low = snmp_fix_numeric($storage_entry[$entry['oid_free_low']]);
$free = snmp_size64_high_low($high, $low);
if (is_numeric($free)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($free) && isset($entry['oid_free_hc'])) {
$free = snmp_fix_numeric($storage_entry[$entry['oid_free_hc']], $unit);
if (is_numeric($free)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($free) && isset($entry['oid_free'])) {
$free = snmp_fix_numeric($storage_entry[$entry['oid_free']], $unit);
}
if (isset($entry['oid_perc'])) {
$perc = snmp_fix_numeric($storage_entry[$entry['oid_perc']]);
}
// Scale
$scale = entity_scale_definition($device, $entry, $storage_entry);
// HC
if ($hc) {
$options['storage_hc'] = 1;
}
// Oper status / Ignore (see NIMBLE-MIB)
if (isset($entry['oid_online'], $storage_entry[$entry['oid_online']])) {
$options['storage_ignore'] = get_var_false($storage_entry[$entry['oid_online']]);
}
// Extrapolate all values from the ones we have.
$storage = calculate_mempool_properties($scale, $used, $total, $free, $perc, $entry);
print_debug_vars([ $scale, $used, $total, $free, $perc, $options ]);
print_debug_vars($storage_entry);
print_debug_vars($storage);
//print_debug_vars([ is_numeric($storage['used']), is_numeric($storage['total']) ]);
// If we have valid used and total, discover the storage
$entry['found'] = discover_storage_ng($device, $mib, $object, $index, $descr, $scale, $storage, $options);
$i++;
}
echo '] ';
}
function discover_storage_ng($device, $storage_mib, $storage_object, $storage_index, $storage_descr, $storage_units, $storage, $options = []) {
global $valid;
// options && limits
$option = 'storage_hc';
$$option = (isset($options[$option]) && $options[$option]) ? 1 : 0;
$option = 'storage_ignore';
$$option = (isset($options[$option]) && $options[$option]) ? 1 : 0;
if (isset($options['limit_high'])) { $storage_crit_limit = $options['limit_high']; }
if (isset($options['limit_high_warn'])) { $storage_warn_limit = $options['limit_high_warn']; }
// FIXME. Ignore 0 storage size?
$storage_size = $storage['total'];
$storage_used = $storage['used'];
$storage_free = $storage['free'];
$storage_perc = $storage['perc'];
$storage_type = isset($options['storage_type']) ? $options['storage_type'] : $object;
print_debug($device['device_id']." -> $storage_index, $storage_object, $storage_mib, $storage_descr, $storage_units, $storage_size, $storage_used, $storage_hc");
if (!is_numeric($storage['total']) || !is_numeric($storage['used'])) {
print_debug("Skipped by not numeric storage values.");
return FALSE;
}
if (isset($storage['valid']) && !$storage['valid']) {
print_debug("Skipped by empty storage Size [$storage_size] or invalid Percent [$storage_perc] values.");
return FALSE;
}
// Check storage ignore filters
if (entity_descr_check($storage_descr, 'storage')) { return FALSE; }
// Search duplicates for same mib/descr
if (in_array($storage_descr, array_values((array)$valid['storage'][$storage_mib]))) {
print_debug("Skipped by already exist: $storage_descr ");
return FALSE;
}
$params = [ 'storage_index', 'storage_mib', 'storage_object', 'storage_type', 'storage_descr',
'storage_hc', 'storage_ignore', 'storage_units', 'storage_crit_limit', 'storage_warn_limit' ];
// This is changeable params, not required for update
$params_state = [ 'storage_size', 'storage_used', 'storage_free', 'storage_perc' ];
$device_id = $device['device_id'];
$storage_db = dbFetchRow("SELECT * FROM `storage` WHERE `device_id` = ? AND `storage_index` = ? AND `storage_mib` = ?", [ $device_id, $storage_index, $storage_mib ]);
if (!isset($storage_db['storage_id'])) {
$update = [ 'device_id' => $device_id ];
foreach (array_merge($params, $params_state) as $param) {
$update[$param] = ($$param === NULL ? [ 'NULL' ] : $$param);
}
$id = dbInsert($update, 'storage');
$GLOBALS['module_stats']['storage']['added']++; //echo('+');
log_event("Storage added: index $storage_index, mib $storage_mib, descr $storage_descr", $device, 'storage', $id);
} else {
$update = [];
foreach ($params as $param) {
if ($$param != $storage_db[$param] ) { $update[$param] = ($$param === NULL ? [ 'NULL' ] : $$param); }
}
if (count($update)) {
//if (isset($update['storage_descr']))
//{
// // Rename storage rrds, because its filename based on description
// $old_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/' . safename('storage-' . $storage_db['storage_mib'] . '-' . $storage_db['storage_descr'] . '.rrd');
// $new_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/' . safename('storage-' . $storage_db['storage_mib'] . '-' . $storage_descr . '.rrd');
// if (is_file($old_rrd) && !is_file($new_rrd)) { rename($old_rrd, $new_rrd); print_warning("Moved RRD"); }
//}
dbUpdate($update, 'storage', '`storage_id` = ?', array($storage_db['storage_id']));
$GLOBALS['module_stats']['storage']['updated']++; //echo('U');
log_event("Storage updated: index $storage_index, mib $storage_mib, descr $storage_descr", $device, 'storage', $storage_db['storage_id']);
} else {
$GLOBALS['module_stats']['storage']['unchanged']++; //echo('.');
}
}
print_debug_vars($update);
if ($storage_ignore) {
$GLOBALS['module_stats']['storage']['ignored']++;
}
$valid['storage'][$storage_mib][$storage_index] = $storage_descr;
return TRUE;
}
function poll_storage_definition($device, $entry, &$storage, $cache_storage) {
// Fetch used, total, free and percentage values, if OIDs are defined for them
if (!safe_empty($entry['total'])) {
// Prefer hardcoded total over SNMP OIDs
$total = $entry['total'];
} else {
$total = get_storage_value($device, 'total', $entry, $storage, $cache_storage);
}
$used = get_storage_value($device, 'used', $entry, $storage, $cache_storage);
$free = get_storage_value($device, 'free', $entry, $storage, $cache_storage);
$perc = get_storage_value($device, 'perc', $entry, $storage, $cache_storage);
if (isset($entry['oid_online'])) {
$mib = $storage['storage_mib'];
$index = $storage['storage_index'];
if (isset($cache_storage[$mib][$index][$entry['oid_online']])) {
$value = $cache_storage[$mib][$index][$entry['oid_online']];
} else {
$value = snmp_get_oid($device, $entry['oid_online'].'.'.$index, $mib);
}
// FIXME, probably need additional field for storages like OperStatus up/down
$ignore = get_var_false($value) ? 1 : 0;
if ($storage['storage_ignore'] != $ignore) {
force_discovery($device, 'storage');
}
}
// Merge calculated used/total/free/perc array keys into $storage variable (with additional options)
$storage = array_merge($storage, calculate_mempool_properties($storage['storage_units'], $used, $total, $free, $perc, $entry));
$storage['size'] = $storage['total'];
}
function get_storage_value($device, $param, $entry, $storage, $cache_storage = []) {
$mib = $storage['storage_mib'];
$index = $storage['storage_index'];
$hc = $storage['storage_hc'];
// Convert strings '3.40 TB' to value
// See QNAP NAS-MIB or HIK-DEVICE-MIB
$unit = ($param !== 'perc' && isset($entry['unit'])) ? $entry['unit'] : NULL;
$value = NULL;
if (isset($entry['oid_'.$param.'_high'], $entry['oid_'.$param.'_low'])) {
// High+Low set of values
if (isset($cache_storage[$mib][$index][$entry['oid_'.$param.'_high']])) {
// Cached
$high = $cache_storage[$mib][$index][$entry['oid_'.$param.'_high']];
$low = $cache_storage[$mib][$index][$entry['oid_'.$param.'_low']];
} elseif ($hc) {
if (isset($entry['oid_'.$param.'_high_num'])) { $high = snmp_get_oid($device, $entry['oid_'.$param.'_high_num'].'.'.$index); }
elseif (isset($entry['oid_'.$param.'_high'])) { $high = snmp_get_oid($device, $entry['oid_'.$param.'_high'].'.'.$index, $mib); }
if (isset($entry['oid_'.$param.'_low_num'])) { $low = snmp_get_oid($device, $entry['oid_'.$param.'_low_num'].'.'.$index); }
elseif (isset($entry['oid_'.$param.'_low'])) { $low = snmp_get_oid($device, $entry['oid_'.$param.'_low'].'.'.$index, $mib); }
}
$high = snmp_fix_numeric($high);
$low = snmp_fix_numeric($low);
$value = snmp_size64_high_low($high, $low);
}
if ($hc && isset($entry['oid_'.$param.'_hc']) && !is_numeric($value)) {
// Common HC value
if (isset($cache_storage[$mib][$index][$entry['oid_'.$param.'_hc']])) {
$value = snmp_fix_numeric($cache_storage[$mib][$index][$entry['oid_'.$param.'_hc']], $unit);
} else {
if (isset($entry['oid_'.$param.'_hc_num'])) { $value = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_'.$param.'_hc_num'].'.'.$index), $unit); }
elseif (isset($entry['oid_'.$param.'_hc'])) { $value = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_'.$param.'_hc'].'.'.$index, $mib), $unit); }
}
}
if (!is_numeric($value) && isset($entry['oid_'.$param])) {
// Common value
if (isset($cache_storage[$mib][$index][$entry['oid_'.$param]])) {
$value = snmp_fix_numeric($cache_storage[$mib][$index][$entry['oid_'.$param]], $unit);
} else {
if (isset($entry['oid_'.$param.'_num'])) { $value = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_'.$param.'_num'].'.'.$index), $unit); }
elseif (isset($entry['oid_'.$param])) { $value = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_'.$param].'.'.$index, $mib), $unit); }
}
}
return $value;
}
/**
* Poll and cache entity _NUMERIC_ Oids,
* need for cross cache between different entities, ie status and sensors
*
* @param $device
* @param $oid_cache
*
* @return bool
*/
function poll_cache_storage($device, &$oid_cache) {
global $config;
$mib_walk_option = 'storage_walk'; // ie: $config['mibs'][$mib]['storage_walk']
//$snmp_flags = OBS_SNMP_ALL_NUMERIC; // Numeric Oids by default
// CLEANME. Compatibility with old (incorrect) field
$object_field = get_db_version() > 468 ? 'storage_object' : 'storage_type';
// Walk query
$walk_query = "SELECT `storage_mib`, `$object_field`, `storage_hc`, GROUP_CONCAT(`storage_index` SEPARATOR ?) AS `indexes` FROM `storage` WHERE `device_id` = ? GROUP BY `storage_mib`, `$object_field`, `storage_hc`";
$walk_params = [ ',', $device['device_id'] ];
$oid_to_cache = [];
foreach (dbFetchRows($walk_query, $walk_params, TRUE) as $entry) {
if (!isset($config['mibs'][$entry['storage_mib']]['storage'][$entry[$object_field]])) {
// Cache only definition based
continue;
}
$def = $config['mibs'][$entry['storage_mib']]['storage'][$entry[$object_field]];
$hc = $entry['storage_hc'];
// Explode indexes from GROUP_CONCAT()
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['indexes'] = explode(',', $entry['indexes']);
// Storage need only this oids in poller
$total = FALSE;
$used = FALSE;
$free = FALSE;
if ($hc) {
// HC oids
if (isset($def['oid_total_high'], $def['oid_total_low'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_total_high'];
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_total_low'];
$total = TRUE;
} elseif (isset($def['oid_total_hc'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_total_hc'];
$total = TRUE;
}
if (isset($def['oid_used_high'], $def['oid_used_low'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_used_high'];
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_used_low'];
$used = TRUE;
} elseif (isset($def['oid_used_hc'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_used_hc'];
$used = TRUE;
}
if (isset($def['oid_free_high'], $def['oid_free_low'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_free_high'];
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_free_low'];
$free = TRUE;
} elseif (isset($def['oid_free_hc'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_free_hc'];
$free = TRUE;
}
}
if (!$total && isset($def['oid_total'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_total'];
}
if (!$used && isset($def['oid_used'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_used'];
}
if (!$free && isset($def['oid_free'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_free'];
}
if (isset($def['oid_perc'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_perc'];
}
if (isset($def['oid_online'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_online'];
}
}
foreach ($oid_to_cache as $mib => $object_array) {
foreach ($object_array as $object => $entry) {
//$def = $config['mibs'][$mib]['storage'][$type];
if (isset($config['mibs'][$mib][$mib_walk_option]) &&
!$config['mibs'][$mib][$mib_walk_option]) {
// MIB not support walk (by definition)
$use_walk = FALSE;
} else {
// Walk on multiple indexes
$use_walk = count($entry['indexes']) > 1;
}
if ($use_walk) {
// SNMP walk
if (isset($GLOBALS['cache']['snmp_object_polled'][$mib][$object])) {
print_debug("MIB/Type ($mib::$object) already polled.");
continue;
}
print_debug("Caching storage snmpwalk by $mib");
foreach ($entry['oids'] as $oid) {
$oid_cache[$mib] = snmpwalk_multipart_oid($device, $oid, $oid_cache[$mib], $mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
}
$GLOBALS['cache']['snmp_object_polled'][$mib][$object] = 1;
} else {
// SNMP multiget
print_debug("Caching storage snmpget by $mib");
$oids = [];
foreach ($entry['oids'] as $oid) {
foreach ($entry['indexes'] as $index) {
$oids[] = $oid . '.' . $index;
}
}
$oid_cache[$mib] = snmp_get_multi_oid($device, $oids, $oid_cache[$mib], $mib);
}
}
}
print_debug_vars($oid_to_cache);
print_debug_vars($oid_cache);
return !empty($oid_to_cache);
}
// EOF

View File

@ -13,10 +13,11 @@
//MOVEME. to includes/entities/wifi.inc.php
// Discover an entity by populating/updating a database table and returning an id
/* I think this is still experimental by adama, pls see discover_entity_definition() common as other entities
function discover_entity($device_id, $entity_type, $data)
{
return FALSE;
if (is_array($GLOBALS['config']['entities'][$entity_type])) {
$def = $GLOBALS['config']['entities'][$entity_type];
@ -26,8 +27,6 @@ function discover_entity($device_id, $entity_type, $data)
if (isset($params['table_fields']['index']) && is_array())
{
} elseif (isset($params['table_fields']['index'])) {
} else {
@ -89,7 +88,6 @@ function discover_entity($device_id, $entity_type, $data)
return $id;
}
*/
/**
* Discover WIFI Access Point. Returns ap_id.

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage functions
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -63,7 +63,8 @@ function messagebus_send($message)
function get_var_true($var, $true = NULL) {
return $var === '1' || $var === 1 ||
$var === 'on' || $var === 'yes' ||
$var === 'on' || $var === 'yes' || $var === 'YES' ||
$var === 'true' || $var === 'TRUE' ||
$var === TRUE ||
// allow extra param for true, ie confirm
(!empty($true) && $var === $true);
@ -71,7 +72,8 @@ function get_var_true($var, $true = NULL) {
function get_var_false($var, $false = NULL) {
return $var === '0' || $var === 0 ||
$var === 'off' || $var === 'no' ||
$var === 'off' || $var === 'no' || $var === 'NO' ||
$var === 'false' || $var === 'FALSE' ||
$var === FALSE || $var === NULL ||
// allow extra param for false, ie confirm
(!empty($false) && $var === $false);
@ -1545,9 +1547,20 @@ function isSNMPable($device) {
$device['ip'] = get_status_var('dns_ip');
}
if (isset($device['os'][0]) && isset($GLOBALS['config']['os'][$device['os']]['snmpable']) && $device['os'] !== 'generic') {
if (isset($device['snmpable']) && !empty($device['snmpable'])) {
// Custom OID for check snmpable (can be multiple OIDs by space)
$oids = [];
foreach (explode(' ', $device['snmpable']) as $oid) {
if (preg_match(OBS_PATTERN_SNMP_OID_NUM, $oid)) {
$oids[] = $oid;
}
}
$pos = snmp_get_multi_oid($device, $oids, [], 'SNMPv2-MIB', NULL, OBS_SNMP_ALL_NUMERIC);
//$err = snmp_error_code();
$count = safe_count($pos);
} elseif (isset($device['os'][0], $GLOBALS['config']['os'][$device['os']]['snmpable']) && $device['os'] !== 'generic') {
// Known device os, and defined custom snmpable OIDs
$pos = snmp_get_multi_oid($device, $GLOBALS['config']['os'][$device['os']]['snmpable'], array(), 'SNMPv2-MIB', NULL, OBS_SNMP_ALL_NUMERIC);
$pos = snmp_get_multi_oid($device, $GLOBALS['config']['os'][$device['os']]['snmpable'], [], 'SNMPv2-MIB', NULL, OBS_SNMP_ALL_NUMERIC);
//$err = snmp_error_code();
$count = safe_count($pos);
} else {
@ -1575,8 +1588,8 @@ function isSNMPable($device) {
if ($GLOBALS['snmp_status'] && $count > 0) {
// SNMP response time in milliseconds.
$time_snmp = $GLOBALS['exec_status']['runtime'] * 1000;
$time_snmp = number_format($time_snmp, 2, '.', '');
return $time_snmp;
return number_format($time_snmp, 2, '.', '');
}
return 0;
@ -2432,8 +2445,7 @@ function load_sqlconfig(&$config) {
foreach ($config_defined as $key => $definition) {
//if (is_null($config['definitions_whitelist'])) { print_error("NULL on $key"); } else { print_warning("ARRAY on $key"); }
if (in_array($key, $GLOBALS['config']['definitions_whitelist']) && // Always use global config here!
is_array($definition) && is_array($config[$key]))
{
is_array($definition) && is_array($config[$key])) {
/* Fix mib definitions for dumb users, who copied old defaults.php
where mibs was just MIB => 1,
This definition should be array */
@ -3070,8 +3082,7 @@ function print_cli_table($table_rows, $table_header = array(), $descr = NULL, $o
/**
* Prints Observium banner containing ASCII logo and version information for use in CLI utilities.
*/
function print_cli_banner()
{
function print_cli_banner() {
if (OBS_QUIET || !is_cli()) { return; } // Silent exit if not cli or quiet
print_message("%W
@ -3085,8 +3096,7 @@ function print_cli_banner()
str_pad(OBSERVIUM_URL , 59, " ", STR_PAD_LEFT)."%N\n", 'color');
// One time alert about deprecated (eol) php version
if (version_compare(PHP_VERSION, OBS_MIN_PHP_VERSION, '<'))
{
if (version_compare(PHP_VERSION, OBS_MIN_PHP_VERSION, '<')) {
$php_version = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
print_message("
@ -3104,6 +3114,27 @@ function print_cli_banner()
str_pad(OBSERVIUM_DOCS_URL . '/software_requirements/' , 56, ' ')."%n|
| |
+---------------------------------------------------------+
", 'color');
}
// Same for MySQL/MariaDB
$versions = get_versions();
if ($versions['mysql_old']) {
$mysql_recommented = $versions['mysql_name'] === 'MariaDB' ? OBS_MIN_MARIADB_VERSION : OBS_MIN_MYSQL_VERSION;
print_message("
+---------------------------------------------------------+
| |
| %rDANGER! ACHTUNG! BHUMAHUE!%n |
| |
".
str_pad("| %WYour ".$versions['mysql_name']." version is old (%r".$versions['mysql_version']."%W),", 64, ' ')."%n|
| %WCurrently recommended version(s): >=%g".$mysql_recommented."%n |
| |
| See additional information here: |
| %c".
str_pad(OBSERVIUM_DOCS_URL . '/software_requirements/' , 56, ' ')."%n|
| |
+---------------------------------------------------------+
", 'color');
}
}
@ -3257,13 +3288,14 @@ function calculate_mempool_properties($scale, $used, $total, $free, $perc = NULL
$free = 100 - $perc;
//$scale = 1; // Reset scale for percentage-only
}
$valid = ($total > 0) && ($perc >= 0) && ($perc <= 100);
if (OBS_DEBUG && ($perc < 0 || $perc > 100)) {
print_error('Incorrect scales or passed params to function ' . __FUNCTION__ . '()');
}
print_debug_vars([ 'used' => $used, 'total' => $total, 'free' => $free, 'perc' => $perc, 'units' => $scale, 'scale' => $scale ], 1);
return [ 'used' => $used, 'total' => $total, 'free' => $free, 'perc' => $perc, 'units' => $scale, 'scale' => $scale ];
return [ 'used' => $used, 'total' => $total, 'free' => $free, 'perc' => $perc, 'units' => $scale, 'scale' => $scale, 'valid' => $valid ];
}
function discovery_check_if_type_exist($entry, $entity_type, $entity = []) {

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage housekeeping
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -17,7 +17,7 @@ if ($cutoff) {
// Prevent delete billed ports
if ($bill_ports = dbFetchColumn('SELECT `entity_id` FROM `bill_entities` WHERE `entity_type` = ?', [ 'port' ])) {
$where .= generate_query_values($bill_ports, 'port_id', '!=');
$where .= generate_query_values_and($bill_ports, 'port_id', '!=');
}
$ports = dbFetchRows("SELECT `port_id` FROM `ports` WHERE $where");

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage housekeeping
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -95,7 +95,7 @@ if (dbExist('autodiscovery', '`remote_device_id` IS NOT NULL AND `remote_device_
/*
* Probably not the best idea to remove user-generated configuration like this, this very occasionally seems to delete billing ports
*
$where = " WHERE " . generate_query_values([ 'bill', 'group' ], 'entity_type', '!=', FALSE); // Exclude pseudo-entities from permissions checks
$where = " WHERE " . generate_query_values_ng([ 'bill', 'group' ], 'entity_type', '!='); // Exclude pseudo-entities from permissions checks
foreach ($config['entity_tables'] as $table) {
$query = "SELECT DISTINCT `entity_type` FROM `$table` $where";
foreach (dbFetchColumn($query, NULL, $test) as $entity_type) {
@ -113,7 +113,7 @@ foreach ($config['entity_tables'] as $table) {
// Remove stale entries
print_debug("Database cleanup for table '$table': deleted $count '$entity_type' entities");
if (!$test) {
$table_status = dbDelete($table, "`entity_type` = ? ".generate_query_values($ids, 'entity_id'), [ $entity_type ]);
$table_status = dbDelete($table, "`entity_type` = ? ".generate_query_values_and($ids, 'entity_id'), [ $entity_type ]);
logfile("housekeeping.log", "Database cleanup for table '$table': deleted $count '$entity_type' entities");
}
} elseif ($prompt) {

View File

@ -55,7 +55,9 @@ $bgp4_peers = snmpwalk_cache_oid($device, $def['oids']['PeerInUpdateElapsedTime'
//$bgp4_peers = snmpwalk_cache_oid($device, $def['oids']['PeerIdentifier']['oid'], $bgp4_peers, $mib);
// Collect founded peers
$bgp_peers = []; // need rewrite array for fix incorrect indexes
if (!is_array($bgp_peers)) {
$bgp_peers = []; // need rewrite array for fix incorrect indexes
}
foreach ($bgp4_peers as $index => $bgp4_entry) {
$index_parts = explode('.', $index);
if (safe_count($index_parts) > 4) {

View File

@ -45,7 +45,9 @@ $bgp4_peers = snmpwalk_cache_oid($device, $def['oids']['PeerInUpdateElapsedTime'
//$bgp4_peers = snmpwalk_cache_oid($device, $def['oids']['PeerIdentifier']['oid'], $bgp4_peers, $mib);
// Collect founded peers
$bgp_peers = []; // need rewrite array for fix incorrect indexes
if (!is_array($bgp_peers)) {
$bgp_peers = []; // need rewrite array for fix incorrect indexes
}
foreach ($bgp4_peers as $index => $bgp4_entry) {
$peer_ip = $index;
$peer_as = snmp_dewrap32bit($bgp4_entry['bgpPeerRemoteAs']); // Dewrap for 32bit ASN

View File

@ -349,20 +349,28 @@ foreach ($fdbs_db as $vlan => $fdb_macs) {
$table_row = [];
$table_row[] = $vlan;
$table_row[] = $mac;
//$table_row[] = $data['port_label_short'];
$table_row[] = "Port {$data['port_index']}";
$table_row[] = $data['port_id'];
//$table_row[] = $fdb_port;
//$table_row[] = $data['ifIndex'];
$table_row[] = '%rdeleted%n';
$table_rows[] = $table_row;
//echo(str_pad($vlan, 8) . ' | ' . str_pad($mac,12) . ' | ' . str_pad($data['port_id'],25) .' | '. str_pad($data['fdb_status'],16));
//echo("-\n");
if (isset($data['fdb_id'])) {
// Multi delete (for faster loop)
$fdb_delete[] = $data['fdb_id'];
//print_debug_vars($data);
if ($data['deleted']) {
// Do not poke db change when already deleted
$table_row[] = '%ydeleted '.format_unixtime($data['fdb_last_change']).'%n';
} else {
$table_row[] = '%rdeleted%n';
$fdb_delete[] = $data['fdb_id'];
}
} else {
// CLEANME. After r12500
$table_row[] = '%rdeleted%n';
dbDelete('vlans_fdb', '`device_id` = ? AND `vlan_id` = ? AND `mac_address` = ?', [ $device['device_id'], $vlan, $mac ]);
}
$table_rows[] = $table_row;
}
}
@ -370,8 +378,8 @@ foreach ($fdbs_db as $vlan => $fdb_macs) {
if (safe_count($fdb_delete)) {
print_debug_vars($fdb_delete);
// do not delete, set deleted flag
dbUpdate([ 'fdb_last_change' => $polled, 'deleted' => 1 ], 'vlans_fdb', generate_query_values($fdb_delete, 'fdb_id', NULL, FALSE));
//dbDelete('vlans_fdb', generate_query_values($fdb_delete, 'fdb_id', NULL, FALSE));
dbUpdate([ 'fdb_last_change' => $polled, 'deleted' => 1 ], 'vlans_fdb', generate_query_values_ng($fdb_delete, 'fdb_id'));
//dbDelete('vlans_fdb', generate_query_values_ng($fdb_delete, 'fdb_id'));
}
/* MultiInsert new fdb entries

View File

@ -6,11 +6,10 @@
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
/**
* Poll and cache entity _NUMERIC_ Oids,
* need for cross cache between different entities, ie status and sensors
@ -21,8 +20,7 @@
*
* @return bool
*/
function poll_cache_oids($device, $entity_type, &$oid_cache)
{
function poll_cache_oids($device, $entity_type, &$oid_cache) {
global $config;
$use_walk = FALSE; // Use multi get by default
@ -37,8 +35,7 @@ function poll_cache_oids($device, $entity_type, &$oid_cache)
$deleted_field = $translate['deleted_field'];
$device_field = $translate['device_id_field'];
switch ($entity_type)
{
switch ($entity_type) {
case 'sensor':
case 'status':
case 'counter':
@ -52,11 +49,17 @@ function poll_cache_oids($device, $entity_type, &$oid_cache)
// Walk query
$walk_query = "SELECT DISTINCT `$mib_field`, `$object_field` FROM `$table` WHERE `$device_field` = ? AND `$deleted_field` = ? AND `poller_type` = ?";
$walk_query .= " AND `$mib_field` != ? AND `$object_field` != ?";
$walk_params = [$device['device_id'], '0', 'snmp', '', ''];
$walk_params = [ $device['device_id'], '0', 'snmp', '', '' ];
// Multi-get query
$get_query = "SELECT DISTINCT `$oid_field` FROM `$table` WHERE `$device_field` = ? AND `$deleted_field` = ? AND `poller_type` = ?";
$get_params = [$device['device_id'], '0', 'snmp'];
$get_params = [ $device['device_id'], '0', 'snmp' ];
break;
case 'storage':
return poll_cache_storage($device, $oid_cache);
break;
@ -65,8 +68,8 @@ function poll_cache_oids($device, $entity_type, &$oid_cache)
return FALSE;
}
if ($use_walk)
{
// This seems actual only for sensor/status/counter
if ($use_walk) {
// Walk by mib & object
$oid_to_cache = dbFetchRows($walk_query, $walk_params);
print_debug_vars($oid_to_cache);
@ -202,28 +205,28 @@ function poll_device($device, $options) {
$device['status_type'] = $status_type;
}
rrdtool_update_ng($device, 'status', array('status' => $status));
rrdtool_update_ng($device, 'status', [ 'status' => $status ]);
//print_vars(rrdtool_export_ng($device, 'status'));
if (!$attribs['ping_skip']) {
// Ping response RRD database.
rrdtool_update_ng($device, 'ping', array('ping' => ($device['pingable'] ?: 'U')));
rrdtool_update_ng($device, 'ping', [ 'ping' => ($device['status_pingable'] ?: 'U') ]);
}
// SNMP response RRD database.
rrdtool_update_ng($device, 'ping_snmp', array('ping_snmp' => ($device['snmpable'] ?: 'U')));
rrdtool_update_ng($device, 'ping_snmp', [ 'ping_snmp' => ($device['status_snmpable'] ?: 'U') ]);
$alert_metrics['device_status'] = $status;
$alert_metrics['device_status_type'] = $status_type;
$alert_metrics['device_ping'] = $device['pingable']; // FIXME, when ping skipped, here always 0.001
$alert_metrics['device_snmp'] = $device['snmpable'];
$alert_metrics['device_ping'] = $device['status_pingable']; // FIXME, when ping skipped, here always 0.001
$alert_metrics['device_snmp'] = $device['status_snmpable'];
if ($status == "1") {
// Arrays for store and check enabled/disabled graphs
$graphs = array();
$graphs_db = array();
$graphs_insert = array();
$graphs_delete = array();
$graphs = [];
$graphs_db = [];
$graphs_insert = [];
$graphs_delete = [];
foreach (dbFetchRows("SELECT * FROM `device_graphs` WHERE `device_id` = ?", array($device['device_id'])) as $entry) {
// Not know how empty was here
if (empty($entry['graph'])) {
@ -369,7 +372,7 @@ function poll_device($device, $options) {
dbInsertMulti($graphs_insert, 'device_graphs');
}
if (safe_count($graphs_delete)) {
dbDelete('device_graphs', generate_query_values($graphs_delete, 'device_graph_id', NULL, FALSE));
dbDelete('device_graphs', generate_query_values_ng($graphs_delete, 'device_graph_id'));
}
// Print graphs stats

View File

@ -21,11 +21,11 @@ $table_defs['TERADICI-PCOIPv2-MIB']['pcoipGenStatsTable'] = array (
'graphs' => array('pcoip-net-packets'),
'ds_rename' => array('pcoipGenStats' => ''),
'oids' => array(
'pcoipGenStatsPacketsSent' => array('numeric' => '2', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.2', 'descr' => 'Packets sent'),
'pcoipGenStatsBytesSent' => array('numeric' => '3', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.3', 'descr' => 'Bytes sent'),
'pcoipGenStatsPacketsReceived' => array('numeric' => '4', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.4', 'descr' => 'Packets received'),
'pcoipGenStatsBytesReceived' => array('numeric' => '5', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.5', 'descr' => 'Bytes received'),
'pcoipGenStatsTxPacketsLost' => array('numeric' => '6', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.6', 'descr' => 'Packets lost', 'ds_type' => 'GAUGE')
'pcoipGenStatsPacketsSent' => array('numeric' => '2', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.2', 'descr' => 'Packets sent'),
'pcoipGenStatsBytesSent' => array('numeric' => '3', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.3', 'descr' => 'Bytes sent'),
'pcoipGenStatsPacketsReceived' => array('numeric' => '4', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.4', 'descr' => 'Packets received'),
'pcoipGenStatsBytesReceived' => array('numeric' => '5', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.5', 'descr' => 'Bytes received'),
'pcoipGenStatsTxPacketsLost' => array('numeric' => '6', 'index'=>'1', 'oid'=>'.1.3.6.1.4.1.25071.1.2.1.1.1.6', 'descr' => 'Packets lost', 'ds_type' => 'GAUGE')
)
);

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -33,9 +33,19 @@ if ($ipmi['host'] = get_dev_attrib($device,'ipmi_hostname')) {
$ipmi['interface'] = 'lan';
}
$own_hostname = $config['own_hostname'] ?: get_localhost();
$remote = '';
if ($config['own_hostname'] !== $device['hostname'] && $ipmi['host'] !== 'localhost' && $ipmi['host'] !== '127.0.0.1') {
$remote = " -I " . escapeshellarg($ipmi['interface']) . " -p " . $ipmi['port'] . " -H " . escapeshellarg($ipmi['host']) . " -L " . escapeshellarg($ipmi['userlevel']) . " -U " . escapeshellarg($ipmi['user']) . " -P " . escapeshellarg($ipmi['password']);
if ($own_hostname !== $device['hostname'] &&
!in_array($ipmi['host'], [ 'localhost', '127.0.0.1', '::1' ], TRUE)) {
$remote = " -I " . escapeshellarg($ipmi['interface']) . " -p " . $ipmi['port'] . " -H " .
escapeshellarg($ipmi['host']) . " -L " . escapeshellarg($ipmi['userlevel']) .
" -U " . escapeshellarg($ipmi['user']) . " -P " . escapeshellarg($ipmi['password']);
}
if(is_numeric($device['ipmi_ciper']) && $device['ipmi_ciper'] == '17')
{
$remote .= " -C ".$device['ipmi_cipher'];
}
$results = external_exec($config['ipmitool'] . $remote . " sensor 2>/dev/null");

View File

@ -1,13 +1,12 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -64,7 +63,7 @@ foreach (dbFetchRows($query, array($device['device_id'])) as $lsp)
foreach (array('uptime', 'total_uptime', 'primary_uptime') as $ds)
{
$rrd_ds .= "DS:" . $ds . ":GAUGE:600:0:U ";
$uptime_values[] = $lsp["lsp_${ds}"];
$uptime_values[] = $lsp["lsp_{$ds}"];
}
if (count($uptime_values))
{
@ -80,7 +79,7 @@ foreach (dbFetchRows($query, array($device['device_id'])) as $lsp)
foreach (array('transitions', 'path_changes') as $ds)
{
$rrd_ds .= "DS:" . $ds . ":COUNTER:600:0:U ";
$stats_values[] = $lsp["lsp_${ds}"];
$stats_values[] = $lsp["lsp_{$ds}"];
}
if (count($stats_values))
{
@ -97,7 +96,7 @@ foreach (dbFetchRows($query, array($device['device_id'])) as $lsp)
foreach (array('octets', 'packets') as $ds)
{
$rrd_ds .= "DS:" . $ds . ":COUNTER:600:0:" . $config['max_port_speed'] . ' ';
$lsp_values[] = $lsp["lsp_${ds}"];
$lsp_values[] = $lsp["lsp_{$ds}"];
}
if (count($lsp_values))
{

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -16,7 +15,10 @@
// ALVARION-DOT11-WLAN-MIB::brzaccVLUnitType.0 = INTEGER: auSA(2)
// ALVARION-DOT11-WLAN-TST-MIB::brzLighteOemProjectNameString.0 = STRING: "BreezeACCESS VL"
$unit_type = snmp_get($device, 'brzaccVLUnitType.0', '-OQv', 'ALVARION-DOT11-WLAN-MIB');
$features = rewrite_breeze_type($unit_type);
if ($unit_type = snmp_get_oid($device, 'brzaccVLUnitType.0', 'ALVARION-DOT11-WLAN-MIB')) {
$features = rewrite_breeze_type($unit_type);
}
unset($unit_type);
// EOF

View File

@ -6,16 +6,15 @@
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
if (is_device_mib($device, 'CISCO-CONFIG-MAN-MIB'))
{
if (is_device_mib($device, 'CISCO-CONFIG-MAN-MIB')) {
// Check Cisco configuration age
$oids = 'sysUpTime.0 ccmHistoryRunningLastChanged.0 ccmHistoryRunningLastSaved.0 ccmHistoryStartupLastChanged.0';
$data = snmp_get_multi_oid($device, $oids, array(), 'SNMPv2-MIB:CISCO-CONFIG-MAN-MIB', NULL, OBS_SNMP_ALL_TIMETICKS);
$data = snmp_get_multi_oid($device, $oids, [], 'SNMPv2-MIB:CISCO-CONFIG-MAN-MIB', NULL, OBS_SNMP_ALL_TIMETICKS);
$config_age = $data[0];
foreach ($config_age as $key => $val)
@ -42,102 +41,92 @@ if (is_device_mib($device, 'CISCO-CONFIG-MAN-MIB'))
$sysDescr = preg_replace('/\s+/', ' ', $poll_device['sysDescr']); // Replace all spaces and newline to single space
// Generic IOS/IOS-XE/IES/IOS-XR sysDescr
if (preg_match('/^Cisco IOS Software(?: \[\S+?\])?, .+? Software \((?:[^\-]+-(\w+)-\w|\w+_IOSXE)\),.+?Version ([^,\s]+)/', $sysDescr, $matches))
{
//Cisco IOS Software, Catalyst 4500 L3 Switch Software (cat4500e-ENTSERVICESK9-M), Version 15.2(1)E3, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2014 by Cisco Systems, Inc. Compiled Mon 05-May-14 07:56 b
//Cisco IOS Software, IOS-XE Software (PPC_LINUX_IOSD-IPBASEK9-M), Version 15.2(2)S, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc. Compiled Mon 26-Mar-12 15:23 by mcpre
//Cisco IOS Software, IES Software (IES-LANBASEK9-M), Version 12.2(52)SE1, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by Cisco Systems, Inc. Compiled Tue 09-Feb-10 03:17 by prod_rel_team
//Cisco IOS Software [Gibraltar], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 16.11.1, RELEASE SOFTWARE (fc3) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2019 by Cisco Systems, Inc. Compiled Thu 28-Mar-19 09:42 by mcpre
//Cisco IOS Software [Fuji], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 16.8.1a, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2018 by Cisco Systems, Inc. Compiled Tue 03-Apr-18 18:49 by mcpre
$features = $matches[1];
$version = $matches[2];
}
elseif (preg_match('/^Cisco Internetwork Operating System Software IOS \(tm\) [^ ]+ Software \([^\-]+-(\w+)-\w\),.+?Version ([^, ]+)/', $sysDescr, $matches))
{
//Cisco Internetwork Operating System Software IOS (tm) 7200 Software (UBR7200-IK8SU2-M), Version 12.3(17b)BC8, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2007 by cisco Systems, Inc. Compiled Fri 29-Ju
//Cisco Internetwork Operating System Software IOS (tm) C1700 Software (C1700-Y-M), Version 12.2(4)YA2, EARLY DEPLOYMENT RELEASE SOFTWARE (fc1) Synched to technology version 12.2(5.4)T TAC Support: http://www.cisco.com/tac Copyright (c) 1986-2002 by ci
$features = $matches[1];
$version = $matches[2];
}
elseif (preg_match('/^Cisco IOS XR Software \(Cisco ([^\)]+)\), Version ([^\[]+)\[([^\]]+)\]/', $sysDescr, $matches))
{
//Cisco IOS XR Software (Cisco 12816/PRP), Version 4.3.2[Default] Copyright (c) 2014 by Cisco Systems, Inc.
//Cisco IOS XR Software (Cisco 12404/PRP), Version 3.6.0[00] Copyright (c) 2007 by Cisco Systems, Inc.
//Cisco IOS XR Software (Cisco ASR9K Series), Version 5.1.2[Default] Copyright (c) 2014 by Cisco Systems, Inc.
//$hardware = $matches[1];
$features = $matches[3];
$version = $matches[2];
}
elseif (preg_match('/^Cisco NX-OS(?:\(tm\))? (?<hw1>\S+?), Software \((?<hw2>.+?)\),.+?Version (?<version>[^, ]+)/', $sysDescr, $matches))
{
//Cisco NX-OS(tm) n7000, Software (n7000-s2-dk9), Version 6.2(8b), RELEASE SOFTWARE Copyright (c) 2002-2013 by Cisco Systems, Inc.
//Cisco NX-OS(tm) n1000v, Software (n1000v-dk9), Version 5.2(1)SV3(1.2), RELEASE SOFTWARE Copyright (c) 2002-2011 by Cisco Systems, Inc. Device Manager Version nms.sro not found, Compiled 11/11/2014 15:00:00
//Cisco NX-OS(tm) n5000, Software (n5000-uk9), Version 6.0(2)N2(7), RELEASE SOFTWARE Copyright (c) 2002-2012 by Cisco Systems, Inc. Device Manager Version 6.2(1), Compiled 4/28/2015 5:00:00
//Cisco NX-OS(tm) n7000, Software (n7000-s2-dk9), Version 6.2(8a), RELEASE SOFTWARE Copyright (c) 2002-2013 by Cisco Systems, Inc. Compiled 5/15/2014 20:00:00
//Cisco NX-OS(tm) n3000, Software (n3000-uk9), Version 6.0(2)U2(2), RELEASE SOFTWARE Copyright (c) 2002-2012 by Cisco Systems, Inc. Device Manager Version nms.sro not found, Compiled 2/12/2014 8:00:00
//Cisco NX-OS(tm) ucs, Software (ucs-6100-k9-system), Version 5.0(3)N2(3.13a), RELEASE SOFTWARE Copyright (c) 2002-2013 by Cisco Systems, Inc. Compiled 4/25/2017 7:00:00
//Cisco NX-OS(tm) aci, Software (aci-n9000-system), Version 12.0(1q), RELEASE SOFTWARE Copyright (c) 2002-2015 by Cisco Systems, Inc. Compiled 2016/08/18 14:20:16
//Cisco NX-OS(tm) nxos.9.2.3.bin, Software (nxos), Version 9.2(3), RELEASE SOFTWARE Copyright (c) 2002-2019 by Cisco Systems, Inc. Compiled 2/17/2019 4:00:00
//Cisco NX-OS n6000, Software (n6000-uk9), Version 7.3(2)N1(1), RELEASE SOFTWARE Copyright (c) 2002-2012, 2016-2017 by Cisco Systems, Inc. Device Manager Version 6.0(2)N1(1),Compiled 5/12/2017 23:00:00
list(, $features) = explode('-', $matches['hw2'], 2);
$version = $matches['version'];
}
elseif (preg_match('/Software \(\w+-(?<features>\w+)-\w\),.+?Version (?<version>[^, ]+),(?:[\w ]+)? RELEASE SOFTWARE/', $sysDescr, $matches))
{
//C800 Software (C800-UNIVERSALK9-M), Version 15.2(2)T2, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Compiled Thu 02-Aug-12 02:09 by prod_rel_team
//Cisco IOS Software, Catalyst 4500 L3 Switch Software (cat4500e-ENTSERVICESK9-M), Version 15.2(1)E3, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2014 by Cisco Systems, Inc. Compiled Mon 05-May-14 07:56 b
//Cisco IOS Software, ASR900 Software (PPC_LINUX_IOSD-UNIVERSALK9_NPE-M), Version 15.5(1)S, RELEASE SOFTWARE (fc5) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2014 by Cisco Systems, Inc. Compiled Thu 20-Nov-14 18:16 by mcpre
//Cisco IOS Software, IOS-XE Software (PPC_LINUX_IOSD-IPBASEK9-M), Version 15.2(2)S, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc. Compiled Mon 26-Mar-12 15:23 by mcpre
//Cisco IOS Software, IES Software (IES-LANBASEK9-M), Version 12.2(52)SE1, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by Cisco Systems, Inc. Compiled Tue 09-Feb-10 03:17 by prod_rel_team
//Cisco Internetwork Operating System Software IOS (tm) 7200 Software (UBR7200-IK8SU2-M), Version 12.3(17b)BC8, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2007 by cisco Systems, Inc. Compiled Fri 29-Ju
//Cisco Internetwork Operating System Software IOS (tm) C1700 Software (C1700-Y-M), Version 12.2(4)YA2, EARLY DEPLOYMENT RELEASE SOFTWARE (fc1) Synched to technology version 12.2(5.4)T TAC Support: http://www.cisco.com/tac Copyright (c) 1986-2002 by ci
if (preg_match('/^Cisco IOS Software(?: \[\S+?\])?, .+? Software \((?:[^\-]+\-(?<features>\w+)\-\w|\w+_IOSXE(?:\-\w+)?)\),.+?Version (?<version>[^,\s]+)/', $sysDescr, $matches)) {
// Cisco IOS Software, Catalyst 4500 L3 Switch Software (cat4500e-ENTSERVICESK9-M), Version 15.2(1)E3, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2014 by Cisco Systems, Inc. Compiled Mon 05-May-14 07:56 b
// Cisco IOS Software, IOS-XE Software (PPC_LINUX_IOSD-IPBASEK9-M), Version 15.2(2)S, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc. Compiled Mon 26-Mar-12 15:23 by mcpre
// Cisco IOS Software, IES Software (IES-LANBASEK9-M), Version 12.2(52)SE1, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by Cisco Systems, Inc. Compiled Tue 09-Feb-10 03:17 by prod_rel_team
// Cisco IOS Software [Gibraltar], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 16.11.1, RELEASE SOFTWARE (fc3) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2019 by Cisco Systems, Inc. Compiled Thu 28-Mar-19 09:42 by mcpre
// Cisco IOS Software [Fuji], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 16.8.1a, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2018 by Cisco Systems, Inc. Compiled Tue 03-Apr-18 18:49 by mcpre
// Cisco IOS Software [Amsterdam], C9800 Software (C9800_IOSXE-K9), Version 17.3.5a, RELEASE SOFTWARE (fc2) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2022 by Cisco Systems, Inc. Compiled Mon 28-Feb-22 19:09 by mcpre
$features = $matches['features'];
$version = $matches['version'];
}
elseif (preg_match('/Software, Version (?<version>\d[\d\.\(\)]+)/', $sysDescr, $matches))
{
//Cisco Systems WS-C6509-E Cisco Catalyst Operating System Software, Version 8.4(3) Copyright (c) 1995-2005 by Cisco Systems
//Cisco Systems, Inc. WS-C2948 Cisco Catalyst Operating System Software, Version 4.5(9) Copyright (c) 1995-2000 by Cisco Systems, Inc.
//Cisco Systems, Inc. WS-C2948G-GE-TX Cisco Catalyst Operating System Software, Version 8.4(5)GLX Copyright (c) 1995-2005 by Cisco Systems, Inc.
//Cisco Systems, Inc. WS-C4912 Cisco Catalyst Operating System Software, Version 7.2(2) Copyright (c) 1995-2002 by Cisco Systems, Inc.
} elseif (preg_match('/^Cisco Internetwork Operating System Software IOS \(tm\) [^ ]+ Software \([^\-]+\-(?<features>\w+)\-\w\),.+?Version (?<version>[^, ]+)/', $sysDescr, $matches)) {
// Cisco Internetwork Operating System Software IOS (tm) 7200 Software (UBR7200-IK8SU2-M), Version 12.3(17b)BC8, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2007 by cisco Systems, Inc. Compiled Fri 29-Ju
// Cisco Internetwork Operating System Software IOS (tm) C1700 Software (C1700-Y-M), Version 12.2(4)YA2, EARLY DEPLOYMENT RELEASE SOFTWARE (fc1) Synched to technology version 12.2(5.4)T TAC Support: http://www.cisco.com/tac Copyright (c) 1986-2002 by ci
$features = $matches['features'];
$version = $matches['version'];
} elseif (preg_match('/^Cisco IOS XR Software \(Cisco (?<hardware>[^\)]+)\), Version (?<version>[^\[]+)\[(?<features>[^\]]+)\]/', $sysDescr, $matches)) {
// Cisco IOS XR Software (Cisco 12816/PRP), Version 4.3.2[Default] Copyright (c) 2014 by Cisco Systems, Inc.
// Cisco IOS XR Software (Cisco 12404/PRP), Version 3.6.0[00] Copyright (c) 2007 by Cisco Systems, Inc.
// Cisco IOS XR Software (Cisco ASR9K Series), Version 5.1.2[Default] Copyright (c) 2014 by Cisco Systems, Inc.
//$hardware = $matches['hardware'];
$features = $matches['features'];
$version = $matches['version'];
} elseif (preg_match('/^Cisco NX-OS(?:\(tm\))? (?<hw1>\S+?)( (?<hardware>[\w\-]+) chassis)?, Software \((?<hw2>.+?)\),.+?Version (?<version>[^, ]+)/', $sysDescr, $matches)) {
// Cisco NX-OS(tm) n7000, Software (n7000-s2-dk9), Version 6.2(8b), RELEASE SOFTWARE Copyright (c) 2002-2013 by Cisco Systems, Inc.
// Cisco NX-OS(tm) n1000v, Software (n1000v-dk9), Version 5.2(1)SV3(1.2), RELEASE SOFTWARE Copyright (c) 2002-2011 by Cisco Systems, Inc. Device Manager Version nms.sro not found, Compiled 11/11/2014 15:00:00
// Cisco NX-OS(tm) n5000, Software (n5000-uk9), Version 6.0(2)N2(7), RELEASE SOFTWARE Copyright (c) 2002-2012 by Cisco Systems, Inc. Device Manager Version 6.2(1), Compiled 4/28/2015 5:00:00
// Cisco NX-OS(tm) n7000, Software (n7000-s2-dk9), Version 6.2(8a), RELEASE SOFTWARE Copyright (c) 2002-2013 by Cisco Systems, Inc. Compiled 5/15/2014 20:00:00
// Cisco NX-OS(tm) n3000, Software (n3000-uk9), Version 6.0(2)U2(2), RELEASE SOFTWARE Copyright (c) 2002-2012 by Cisco Systems, Inc. Device Manager Version nms.sro not found, Compiled 2/12/2014 8:00:00
// Cisco NX-OS(tm) ucs, Software (ucs-6100-k9-system), Version 5.0(3)N2(3.13a), RELEASE SOFTWARE Copyright (c) 2002-2013 by Cisco Systems, Inc. Compiled 4/25/2017 7:00:00
// Cisco NX-OS(tm) aci, Software (aci-n9000-system), Version 12.0(1q), RELEASE SOFTWARE Copyright (c) 2002-2015 by Cisco Systems, Inc. Compiled 2016/08/18 14:20:16
// Cisco NX-OS(tm) nxos.9.2.3.bin, Software (nxos), Version 9.2(3), RELEASE SOFTWARE Copyright (c) 2002-2019 by Cisco Systems, Inc. Compiled 2/17/2019 4:00:00
// Cisco NX-OS n6000, Software (n6000-uk9), Version 7.3(2)N1(1), RELEASE SOFTWARE Copyright (c) 2002-2012, 2016-2017 by Cisco Systems, Inc. Device Manager Version 6.0(2)N1(1),Compiled 5/12/2017 23:00:00
// Cisco NX-OS(tm) Nexus9000 C93180YC-EX chassis, Software (NXOS 32-bit), Version 9.3(9), RELEASE SOFTWARE Copyright (c) 2002-2022 by Cisco Systems, Inc. Compiled 2/4/2022 7:00:00
if (str_contains($matches['hw2'], ' ')) {
// NXOS 32-bit -> 32-bit
list(, $features) = explode(' ', $matches['hw2'], 2);
} elseif (str_contains($matches['hw2'], '-')) {
// n7000-s2-dk9 -> s2-dk9
list(, $features) = explode('-', $matches['hw2'], 2);
}
$version = $matches['version'];
} elseif (preg_match('/Software \(\w+-(?<features>\w+)-\w\),.+?Version (?<version>[^, ]+),(?:[\w ]+)? RELEASE SOFTWARE/', $sysDescr, $matches)) {
// C800 Software (C800-UNIVERSALK9-M), Version 15.2(2)T2, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Compiled Thu 02-Aug-12 02:09 by prod_rel_team
// Cisco IOS Software, Catalyst 4500 L3 Switch Software (cat4500e-ENTSERVICESK9-M), Version 15.2(1)E3, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2014 by Cisco Systems, Inc. Compiled Mon 05-May-14 07:56 b
// Cisco IOS Software, ASR900 Software (PPC_LINUX_IOSD-UNIVERSALK9_NPE-M), Version 15.5(1)S, RELEASE SOFTWARE (fc5) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2014 by Cisco Systems, Inc. Compiled Thu 20-Nov-14 18:16 by mcpre
// Cisco IOS Software, IOS-XE Software (PPC_LINUX_IOSD-IPBASEK9-M), Version 15.2(2)S, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc. Compiled Mon 26-Mar-12 15:23 by mcpre
// Cisco IOS Software, IES Software (IES-LANBASEK9-M), Version 12.2(52)SE1, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by Cisco Systems, Inc. Compiled Tue 09-Feb-10 03:17 by prod_rel_team
// Cisco Internetwork Operating System Software IOS (tm) 7200 Software (UBR7200-IK8SU2-M), Version 12.3(17b)BC8, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2007 by cisco Systems, Inc. Compiled Fri 29-Ju
// Cisco Internetwork Operating System Software IOS (tm) C1700 Software (C1700-Y-M), Version 12.2(4)YA2, EARLY DEPLOYMENT RELEASE SOFTWARE (fc1) Synched to technology version 12.2(5.4)T TAC Support: http://www.cisco.com/tac Copyright (c) 1986-2002 by ci
$features = $matches['features'];
$version = $matches['version'];
} elseif (preg_match('/Software( \([\w\- ]+\))?, Version (?<version>\d[\w\.\(\)]+)/', $sysDescr, $matches)) {
// Cisco Systems WS-C6509-E Cisco Catalyst Operating System Software, Version 8.4(3) Copyright (c) 1995-2005 by Cisco Systems
// Cisco Systems, Inc. WS-C2948 Cisco Catalyst Operating System Software, Version 4.5(9) Copyright (c) 1995-2000 by Cisco Systems, Inc.
// Cisco Systems, Inc. WS-C2948G-GE-TX Cisco Catalyst Operating System Software, Version 8.4(5)GLX Copyright (c) 1995-2005 by Cisco Systems, Inc.
// Cisco Systems, Inc. WS-C4912 Cisco Catalyst Operating System Software, Version 7.2(2) Copyright (c) 1995-2002 by Cisco Systems, Inc.
//$features = $matches['features'];
$version = $matches['version'];
}
// All other Cisco devices
if (is_array($entPhysical))
{
if (is_module_enabled($device, 'inventory', 'discovery'))
{
if ($entPhysical['entPhysicalClass'] === 'stack')
{
if (is_array($entPhysical)) {
if (is_module_enabled($device, 'inventory', 'discovery')) {
if ($entPhysical['entPhysicalClass'] === 'stack') {
// If it's stacked device try get chassis instead
$chassis = dbFetchRow('SELECT * FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalClass` = ? AND `entPhysicalContainedIn` = ? AND `deleted` IS NULL', array($device['device_id'], 'chassis', '1'));
if ($chassis['entPhysicalModelName'])
{
if ($chassis['entPhysicalModelName']) {
$entPhysical = $chassis;
}
}
elseif (empty($entPhysical['entPhysicalModelName']) || $entPhysical['entPhysicalModelName'] === 'MIDPLANE')
{
} elseif ($entPhysical['entPhysicalModelName'] === 'MIDPLANE' || safe_empty($entPhysical['entPhysicalModelName'])) {
// F.u. Cisco.. for some platforms (4948/4900M) they store correct model and version not in chassis
$hw_module = dbFetchRow('SELECT * FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalClass` = ? AND `entPhysicalContainedIn` = ? AND `deleted` IS NULL', array($device['device_id'], 'module', '2'));
if ($hw_module['entPhysicalModelName'])
{
if ($hw_module['entPhysicalModelName']) {
$entPhysical = $hw_module;
}
}
elseif (empty($entPhysical['entPhysicalSoftwareRev']))
{
} elseif (safe_empty($entPhysical['entPhysicalSoftwareRev'])) {
// 720X, try again get correct serial/version
$hw_module = dbFetchRow('SELECT * FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalClass` = ? AND `entPhysicalContainedIn` = ? AND `entPhysicalSerialNum` != ? AND `deleted` IS NULL', array($device['device_id'], 'module', '1', ''));
if ($hw_module['entPhysicalSoftwareRev'])
{
if ($device['os'] === 'iosxe')
{
if ($hw_module['entPhysicalSoftwareRev']) {
if ($device['os'] === 'iosxe') {
// For IOS-XE fix only version
$entPhysical['entPhysicalSoftwareRev'] = $hw_module['entPhysicalSoftwareRev'];
} else {
@ -147,14 +136,11 @@ if (is_array($entPhysical))
}
}
if (in_array($entPhysical['entPhysicalContainedIn'], [ '0', '1', '2' ]) || $entPhysical['entPhysicalClass'] === 'chassis')
{
if ((empty($version) || $device['os'] === 'iosxe') && !empty($entPhysical['entPhysicalSoftwareRev']))
{
if ($entPhysical['entPhysicalClass'] === 'chassis' || in_array($entPhysical['entPhysicalContainedIn'], [ '0', '1', '2' ])) {
if ((safe_empty($version) || $device['os'] === 'iosxe') && !empty($entPhysical['entPhysicalSoftwareRev'])) {
$version = $entPhysical['entPhysicalSoftwareRev'];
}
if (!empty($entPhysical['entPhysicalModelName']))
{
if (!empty($entPhysical['entPhysicalModelName'])) {
if (preg_match('/ (rev|dev)/', $entPhysical['entPhysicalModelName']) || // entPhysicalModelName = "73-7036-1 rev 80 dev 0"
preg_match('/^\.+$/', $entPhysical['entPhysicalModelName'])) // entPhysicalModelName = "..."
{
@ -167,8 +153,7 @@ if (is_array($entPhysical))
} else {
$hardware = str_replace(' chassis', '', $entPhysical['entPhysicalName']);
}
if (!empty($entPhysical['entPhysicalSerialNum']))
{
if (!empty($entPhysical['entPhysicalSerialNum'])) {
$serial = $entPhysical['entPhysicalSerialNum'];
}
}
@ -182,20 +167,17 @@ if (is_array($entPhysical))
// entPhysicalModelName: WS-C2960-48TC-S
// sysObjectID [.1.3.6.1.4.1.9.1.1208]: cat29xxStack
// entPhysicalModelName: WS-C2960S-F48TS-L
if (empty($hardware) && $poll_device['sysObjectID'])
{
if (empty($hardware) && $poll_device['sysObjectID']) {
// Try translate instead duplicate get sysObjectID
$hardware = snmp_translate($poll_device['sysObjectID'], 'SNMPv2-MIB:CISCO-PRODUCTS-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB');
}
if (empty($hardware))
{
if (empty($hardware)) {
// If translate false, try get sysObjectID again
$hardware = snmp_get_oid($device, 'sysObjectID.0', 'SNMPv2-MIB:CISCO-PRODUCTS-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB');
}
// Some cisco specific hardware rewrites
if ($hardware)
{
if ($hardware) {
$cisco_replace = [
'/^[Cc]isco\s*(\d)/' => '\1', // Cisco 7604 -> 7604
'/^cisco([a-z])/i' => '\1', // ciscoASR9010 -> ASR9010

View File

@ -1,34 +1,52 @@
<?php
/**
* Observium
*
* This file is part of Observium.
* This file is part of Observium.
*
* @package observium
* @package observium
* @subpackage poller
* @copyright (C) 2006-2015 Adam Armstrong
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
# PowerWalker/BlueWalker UPS (Tested with BlueWalked VFI 2000 LCD (EPPC-MIB) sysDescr.0 = STRING: Network Management Card for UPS
if (str_contains($poll_device['sysDescr'], 'Network Management Card for UPS')) {
// EPPC-MIB::upsEIdentityManufacturer.0 = STRING: EPPC
// EPPC-MIB::upsEIdentityModel.0 = STRING: ON-LINE
// EPPC-MIB::upsEIdentityUPSFirmwareVerison.0 = STRING: 06.00
// EPPC-MIB::upsEIndentityUPSSerialNumber.0 = STRING:
// EPPC-MIB::upsEIdentityDescription.0 = STRING:
// EPPC-MIB::upsEIdentityAgentSoftwareVerison.0 = STRING: 3.0.0.2
// EPPC-MIB::upsEIdentityAttachedDevices.0 = STRING:
if ($data = snmp_get_multi_oid($device, 'upsEIdentityManufacturer.0 upsESystemConfigOutputVA.0 upsEIdentityModel.0', [], 'EPPC-MIB')) {
if ($data[0]['upsEIdentityManufacturer'] === 'EPPC') {
// FIXME. Not sure, see: https://jira.observium.org/browse/OBS-4314
$vendor = 'Eaton';
//} elseif ($data[0]['upsEIdentityManufacturer']) {
// $vendor = $data[0]['upsEIdentityManufacturer'];
} else {
$vendor = 'PowerWalker';
}
if ($poll_device['sysObjectID'] == '.1.3.6.1.4.1.935.10.1') // BlueWalker
{
if ($poll_device['sysDescr'] == 'Network Management Card for UPS')
{
$hardware = snmp_get($device, 'upsEIdentityManufacturer.0', '-OQv', 'EPPC-MIB') . ' (' .
snmp_get($device, 'upsESystemConfigOutputVA.0', '-OQv', 'EPPC-MIB') . 'VA ' . snmp_get($device, 'upsEIdentityModel.0', '-OQv', 'EPPC-MIB') . ')';
$upsEIdentityDescription = snmp_get($device, 'upsEIdentityDescription.0', '-OQv', 'EPPC-MIB');
$version = $upsEIdentityDescription + ' UPS: ' .
snmp_get($device, 'upsEIdentityUPSFirmwareVerison.0', '-OQv', 'EPPC-MIB') . ' Firmware: ' . snmp_get($device, 'upsIdentAgentSoftwareVersion.0', '-OQv', 'EPPC-MIB');
$status = snmp_get($device, 'upsESystemStatus.0', '-OQv', 'EPPC-MIB') . ' ' . snmp_get($device, 'upsEBatteryTestResult.0', '-OQv', 'EPPC-MIB');
$hardware = $data[0]['upsEIdentityModel'];
if ($data[0]['upsESystemConfigOutputVA'] > 0) {
$hardware .= '('.$data[0]['upsESystemConfigOutputVA'].'VA)';
}
$features = 'Status: ' . strtoupper($status);
}
else {
$hardware = 'EPPC - Unknown NMC Card';
if ($data = snmp_get_multi_oid($device, 'upsEIdentityDescription.0 upsEIdentityUPSFirmwareVerison.0 upsIdentAgentSoftwareVersion.0', [], 'EPPC-MIB')) {
$version = $data[0]['upsEIdentityDescription'] . ' UPS: ' .
$data[0]['upsEIdentityUPSFirmwareVerison'] . ' Firmware: ' . $data[0]['upsIdentAgentSoftwareVersion'];
}
//if ($data = snmp_get_multi_oid($device, 'upsESystemStatus.0 upsEBatteryTestResult.0', [], 'EPPC-MIB')) {
// $features = 'Status: ' . strtoupper($data[0]['upsESystemStatus'] . ' ' . $data[0]['upsEBatteryTestResult']);
//}
} else {
$hardware = 'EPPC - Unknown NMC Card';
}
// EOF

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,18 +6,19 @@
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
if (!$hardware)
{
$hardware = rewrite_definition_hardware($device, $poll_device['sysObjectID']);
if ($fn_hw = rewrite_definition_hardware($device, $poll_device['sysObjectID'])) {
// Prefer defined hardware
$hardware = $fn_hw;
$fn_type = rewrite_definition_type($device, $poll_device['sysObjectID']);
if (!empty($fn_type))
{
if (!empty($fn_type)) {
$type = $fn_type;
}
} elseif (str_contains($hardware, 'WiFi')) {
$type = 'wireless';
}
// EOF

View File

@ -6,22 +6,20 @@
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
switch ($device['os']) {
case 'aix':
list($hardware,,$os_detail,) = explode("\n", $poll_device['sysDescr']);
if (preg_match('/: 0*(\d+\.)0*(\d+\.)0*(\d+\.)(\d+)/', $os_detail, $matches))
{
if (preg_match('/: 0*(\d+\.)0*(\d+\.)0*(\d+\.)(\d+)/', $os_detail, $matches)) {
// Base Operating System Runtime AIX version: 05.03.0012.0001
$version = $matches[1] . $matches[2] . $matches[3] . $matches[4];
}
$hardware_model = snmp_get_oid($device, 'aixSeMachineType.0', 'IBM-AIX-MIB');
if ($hardware_model)
{
if ($hardware_model) {
list(,$hardware_model) = explode(',', $hardware_model);
$serial = snmp_get_oid($device, 'aixSeSerialNumber.0', 'IBM-AIX-MIB');
@ -32,8 +30,9 @@ switch ($device['os']) {
break;
case 'freebsd':
preg_match('/FreeBSD ([\d\.]+\-[\w\-]+)/i', $poll_device['sysDescr'], $matches);
$kernel = $matches[1];
if (preg_match('/FreeBSD ([\d\.]+\-[\w\-]+)/i', $poll_device['sysDescr'], $matches)) {
$kernel = $matches[1];
}
$hardware = rewrite_unix_hardware($poll_device['sysDescr']);
break;
@ -58,7 +57,9 @@ switch ($device['os']) {
case 'monowall':
case 'pfsense':
list(,,$version,,, $kernel) = explode(' ', $poll_device['sysDescr']);
if (safe_empty($kernel)) {
list(, , $version, , , $kernel) = explode(' ', $poll_device['sysDescr']);
}
$distro = $device['os'];
$hardware = rewrite_unix_hardware($poll_device['sysDescr']);
break;
@ -103,8 +104,7 @@ switch ($device['os']) {
case 'ipso':
// IPSO Bastion-1 6.2-GA039 releng 1 04.14.2010-225515 i386
// IP530 rev 00, IPSO ruby.infinity-insurance.com 3.9-BUILD035 releng 1515 05.24.2005-013334 i386
if (preg_match('/IPSO [^ ]+ ([^ ]+) /', $poll_device['sysDescr'], $matches))
{
if (preg_match('/IPSO [^ ]+ ([^ ]+) /', $poll_device['sysDescr'], $matches)) {
$version = $matches[1];
}
@ -121,8 +121,7 @@ switch ($device['os']) {
// EMBEDDED-NGX-MIB::swLicenseProductName.0 = "Safe@Office 500, 25 nodes"
// EMBEDDED-NGX-MIB::swFirmwareRunning.0 = "8.2.26x"
$data = snmp_get_multi_oid($device, 'swHardwareVersion.0 swHardwareType.0 swLicenseProductName.0 swFirmwareRunning.0', array(), 'EMBEDDED-NGX-MIB');
if (isset($data[0]))
{
if (isset($data[0])) {
list($hw) = explode(',', $data[0]['swLicenseProductName']);
$hardware = $hw . ' ' . $data[0]['swHardwareType'] . ' ' . $data[0]['swHardwareVersion'];
$version = $data[0]['swFirmwareRunning'];
@ -153,18 +152,13 @@ switch ($device['os']) {
// zur: 3 first letter from the location / city name
// acc: optional or sub-segment, like dns and mep
// 1: Device number in the same clusters for High availability
if (preg_match('/^Linux\ +\w+\-(?<hw>(?<hw1>[a-z]+)0*\d+)\-\w+\-\w+\-(?:(?<hw2>\w+)\-)?\d+/', $poll_device['sysDescr'], $matches))
{
switch ($matches['hw1'])
{
if (preg_match('/^Linux\ +\w+\-(?<hw>(?<hw1>[a-z]+)0*\d+)\-\w+\-\w+\-(?:(?<hw2>\w+)\-)?\d+/', $poll_device['sysDescr'], $matches)) {
switch ($matches['hw1']) {
case 'sg':
if (isset($matches['hw2']) && $matches['hw2'] === 'dns')
{
if (isset($matches['hw2']) && $matches['hw2'] === 'dns') {
$hw = 'DNS Server';
$type = 'server';
}
elseif (isset($matches['hw2']) && $matches['hw2'] === 'mep')
{
} elseif (isset($matches['hw2']) && $matches['hw2'] === 'mep') {
$hw = 'Mobile Entry Point';
$type = 'network';
} else {
@ -240,14 +234,18 @@ switch ($device['os']) {
}
}
if (empty($hw))
{
if (empty($hw)) {
$hw = 'OSAG Hardware';
}
//$hardware = $hw . ' (' . strtoupper($matches['hw']) . ')';
$hardware = rewrite_unix_hardware($poll_device['sysDescr'], $hw);
break;
case 'unitrends-backup':
// Prevent Distro/kernel/packages polling
// But keep other unix group features
return;
// case 'linux':
// case 'endian':
// case 'ddwrt':
@ -345,148 +343,146 @@ if (isset($agent_data['distro']) && isset($agent_data['distro']['SCRIPTVER'])) {
}
// Detect some distro by kernel strings
if (!isset($distro) && $poll_device['sysObjectID'] === '.1.3.6.1.4.1.8072.3.2.10' &&
str_starts($poll_device['sysDescr'], 'Linux ')) {
// * Ubuntu (old):
// Linux hostname 3.11.0-13-generic #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013 x86_64
// * Ubuntu 16.04:
// Linux hostname 4.4.0-77-generic #98-Ubuntu SMP Wed Apr 26 08:34:02 UTC 2017 x86_64
// Linux hostname 4.4.0-201-generic #233-Ubuntu SMP Thu Jan 14 06:10:28 UTC 2021 x86_64
// * Ubuntu 18.04:
// Linux hostname 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64
// Linux hostname 4.15.0-129-generic #132-Ubuntu SMP Thu Dec 10 14:02:26 UTC 2020 x86_64
// * Ubuntu 20.04
// Linux hostname 5.10.4-051004-generic #202012301142 SMP Wed Dec 30 11:44:55 UTC 2020 x86_64
// Linux hostname 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64
if (preg_match('/ \d[\.\d]+(\-\d+)?(\-[a-z]+)? #(\d+\-Ubuntu|\d{12}) /', $poll_device['sysDescr'])) {
$distro = 'Ubuntu';
}
// * Debian 9
// Linux hostname 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64
// Linux hostname 4.9.0-14-amd64 #1 SMP Debian 4.9.240-2 (2020-10-30) x86_64
elseif (preg_match('/ Debian \d[\.\d]+(\-\d+)?([\+\-]\w+)? /', $poll_device['sysDescr'])) {
$distro = 'Debian';
}
// * Proxmox (Debian)
// Linux hostname 5.11.22-2-pve #1 SMP PVE 5.11.22-4 (Tue, 20 Jul 2021 21:40:02 +0200) x86_64
// Linux hostname 5.4.78-2-pve #1 SMP PVE 5.4.78-2 (Thu, 03 Dec 2020 14:26:17 +0100) x86_64
// Linux hostname 5.4.44-1-pve #1 SMP PVE 5.4.44-1 (Fri, 12 Jun 2020 08:18:46 +0200) x86_64
// Linux hostname 5.0.21-5-pve #1 SMP PVE 5.0.21-10 (Wed, 13 Nov 2019 08:27:10 +0100) x86_64
// Linux hostname 4.4.128-1-pve #1 SMP PVE 4.4.128-111 (Wed, 23 May 2018 14:00:02 +0000) x86_64
// Linux hostname 4.4.8-1-pve #1 SMP Tue May 31 07:12:32 CEST 2016 x86_64
elseif (preg_match('/\d\-pve | PVE /', $poll_device['sysDescr'])) {
$distro = 'Debian';
}
// * Raspbian (Debian)
// Linux hostname 5.10.17-v7+ #1403 SMP Mon Feb 22 11:29:51 GMT 2021 armv7l
// Linux hostname 5.4.51-v7l+ #1333 SMP Mon Aug 10 16:51:40 BST 2020 armv7l
// Linux hostname 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l
// Linux hostname 4.14.43+ #1115 Fri May 25 13:54:20 BST 2018 armv6l
// Linux hostname 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l
// Linux hostname 3.12.33+ #724 PREEMPT Wed Nov 26 17:55:23 GMT 2014 armv6l
elseif (preg_match('/ \d[\.\d]+(\-v\d+\w*)?\+ #\d+ .* arm/', $poll_device['sysDescr'])) {
$distro = 'Raspbian';
}
// * Armbian (Ubuntu)
// Linux hostname 5.10.60-sunxi #21.08.2 SMP Tue Sep 14 16:28:44 UTC 2021 armv7l
elseif (preg_match('/^Linux \S+ \d\S+\d+(\-\w+)?\-sunxi #(?<distro_ver>\d+\.\d+(\.\d+)?) .* arm/', $poll_device['sysDescr'], $matches)) {
$distro = 'Armbian';
$distro_ver = $matches['distro_ver'];
}
// * Arch Linux
// Linux hostname 2.6.37-ARCH #1 SMP PREEMPT Sat Jan 29 20:00:33 CET 2011 x86_64
// Linux hostname 4.19.86-1-ARCH #1 SMP PREEMPT Sat Nov 30 18:56:30 UTC 2019 armv6l
// Linux hostname 5.10.27-2-ARCH #1 SMP Fri Apr 9 21:08:37 UTC 2021 armv6l
// Linux hostname 5.10.79-2-raspberrypi-ARCH #1 SMP Tue Nov 16 20:32:00 UTC 2021 armv6l GNU/Linux
elseif (preg_match('/^Linux \S+ \d\S+\d+(\-\w+)?\-ARCH #\d/', $poll_device['sysDescr'])) {
$distro = 'Arch Linux';
}
// * CentOS 5:
// Linux hostname 2.6.18-274.12.1.el5 #1 SMP Tue Nov 29 13:37:46 EST 2011 x86_64
// * OracleLinux 6:
// Linux hostname 2.6.32-131.0.15.el6.x86_64 #1 SMP Fri May 20 15:04:03 EDT 2011 x86_64
// * CentOS 7:
// Linux hostname 3.10.0-327.4.5.el7.x86_64 #1 SMP Mon Jan 25 22:07:14 UTC 2016 x86_64
// * RedHat EL:
// Linux hostname 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 29 17:29:29 EDT 2015 x86_64
// Linux hostname 3.10.0-229.20.1.el7.x86_64 #1 SMP Thu Sep 24 12:23:56 EDT 2015 x86_64
// Linux hostname 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Mar 25 14:36:04 EDT 2021 x86_64
elseif (preg_match('/ \d[\.\d]+(\-\d+[\.\d]*\.el(?<distro_ver>\d+(_\d+)?))/', $poll_device['sysDescr'], $matches)) {
// Detect distro by packages
$distro_def = [
// redhat-release-server-6Server-6.7.0.3.el6
// redhat-release-8.3-1.0.el8
[ 'name' => 'redhat-release', 'regex' => '/^redhat\-release[\-_](?<version>\d.*)/', 'distro' => 'RedHat',
'transform' => [ [ 'action' => 'preg_replace', 'from' => '/^(\d+[\.\-]\d+).*/', 'to' => '$1' ],
[ 'action' => 'replace', 'from' => '-', 'to' => '.' ] ] ],
// centos-release-6-3.el6.centos.9
// centos-release-6-9.el6.12.3
// centos-release-7-6.1810.2.el7.centos
[ 'name' => 'centos-release', 'regex' => '/^centos\-release[\-_](?<version>\d.*)/', 'distro' => 'CentOS',
'transform' => [ [ 'action' => 'preg_replace', 'from' => '/^(\d+[\.\-]\d+).*/', 'to' => '$1' ],
[ 'action' => 'replace', 'from' => '-', 'to' => '.' ] ] ],
// rocky-release-8.5-3.el8
[ 'name' => 'rocky-release', 'regex' => '/^rocky\-release[\-_](?<version>\d.*)/', 'distro' => 'Rocky',
'transform' => [ [ 'action' => 'preg_replace', 'from' => '/^(\d+[\.\-]\d+).*/', 'to' => '$1' ],
[ 'action' => 'replace', 'from' => '-', 'to' => '.' ] ] ],
// oraclelinux-release-6Server-1.0.2
// fixme. need more examples
];
$metatypes = [ 'distro', 'distro_ver' ];
foreach (poll_device_unix_packages($device, $metatypes, $distro_def) as $metatype => $value) {
$$metatype = $value;
if (!isset($distro)) {
if ($poll_device['sysObjectID'] === '.1.3.6.1.4.1.8072.3.2.10' && str_starts($poll_device['sysDescr'], 'Linux ')) {
// * Ubuntu (old):
// Linux hostname 3.11.0-13-generic #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013 x86_64
// * Ubuntu 16.04:
// Linux hostname 4.4.0-77-generic #98-Ubuntu SMP Wed Apr 26 08:34:02 UTC 2017 x86_64
// Linux hostname 4.4.0-201-generic #233-Ubuntu SMP Thu Jan 14 06:10:28 UTC 2021 x86_64
// * Ubuntu 18.04:
// Linux hostname 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64
// Linux hostname 4.15.0-129-generic #132-Ubuntu SMP Thu Dec 10 14:02:26 UTC 2020 x86_64
// * Ubuntu 20.04
// Linux hostname 5.10.4-051004-generic #202012301142 SMP Wed Dec 30 11:44:55 UTC 2020 x86_64
// Linux hostname 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64
if (preg_match('/ \d[\.\d]+(\-\d+)?(\-[a-z]+)? #(\d+\-Ubuntu|\d{12}) /', $poll_device['sysDescr'])) {
$distro = 'Ubuntu';
}
if (safe_empty($distro)) {
// there no way for split RedHat vs CentOS..
//$distro = 'CentOS';
$distro = 'RedHat'; // FIXME. no way for correctly detect redhat or centos, probably by packages?..
$distro_ver = str_replace('_', '.', $matches['distro_ver']);
// * Debian 9
// Linux hostname 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64
// Linux hostname 4.9.0-14-amd64 #1 SMP Debian 4.9.240-2 (2020-10-30) x86_64
elseif (preg_match('/ Debian \d[\.\d]+(\-\d+)?([\+\-]\w+)? /', $poll_device['sysDescr'])) {
$distro = 'Debian';
}
// * Proxmox (Debian)
// Linux hostname 5.11.22-2-pve #1 SMP PVE 5.11.22-4 (Tue, 20 Jul 2021 21:40:02 +0200) x86_64
// Linux hostname 5.4.78-2-pve #1 SMP PVE 5.4.78-2 (Thu, 03 Dec 2020 14:26:17 +0100) x86_64
// Linux hostname 5.4.44-1-pve #1 SMP PVE 5.4.44-1 (Fri, 12 Jun 2020 08:18:46 +0200) x86_64
// Linux hostname 5.0.21-5-pve #1 SMP PVE 5.0.21-10 (Wed, 13 Nov 2019 08:27:10 +0100) x86_64
// Linux hostname 4.4.128-1-pve #1 SMP PVE 4.4.128-111 (Wed, 23 May 2018 14:00:02 +0000) x86_64
// Linux hostname 4.4.8-1-pve #1 SMP Tue May 31 07:12:32 CEST 2016 x86_64
elseif (preg_match('/\d\-pve | PVE /', $poll_device['sysDescr'])) {
$distro = 'Debian';
}
// * Raspbian (Debian)
// Linux hostname 5.10.17-v7+ #1403 SMP Mon Feb 22 11:29:51 GMT 2021 armv7l
// Linux hostname 5.4.51-v7l+ #1333 SMP Mon Aug 10 16:51:40 BST 2020 armv7l
// Linux hostname 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l
// Linux hostname 4.14.43+ #1115 Fri May 25 13:54:20 BST 2018 armv6l
// Linux hostname 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l
// Linux hostname 3.12.33+ #724 PREEMPT Wed Nov 26 17:55:23 GMT 2014 armv6l
elseif (preg_match('/ \d[\.\d]+(\-v\d+\w*)?\+ #\d+ .* arm/', $poll_device['sysDescr'])) {
$distro = 'Raspbian';
}
// * Armbian (Ubuntu)
// Linux hostname 5.10.60-sunxi #21.08.2 SMP Tue Sep 14 16:28:44 UTC 2021 armv7l
elseif (preg_match('/^Linux \S+ \d\S+\d+(\-\w+)?\-sunxi #(?<distro_ver>\d+\.\d+(\.\d+)?) .* arm/', $poll_device['sysDescr'], $matches)) {
$distro = 'Armbian';
$distro_ver = $matches['distro_ver'];
}
// * Arch Linux
// Linux hostname 2.6.37-ARCH #1 SMP PREEMPT Sat Jan 29 20:00:33 CET 2011 x86_64
// Linux hostname 4.19.86-1-ARCH #1 SMP PREEMPT Sat Nov 30 18:56:30 UTC 2019 armv6l
// Linux hostname 5.10.27-2-ARCH #1 SMP Fri Apr 9 21:08:37 UTC 2021 armv6l
// Linux hostname 5.10.79-2-raspberrypi-ARCH #1 SMP Tue Nov 16 20:32:00 UTC 2021 armv6l GNU/Linux
elseif (preg_match('/^Linux \S+ \d\S+\d+(\-\w+)?\-ARCH #\d/', $poll_device['sysDescr'])) {
$distro = 'Arch Linux';
}
// * CentOS 5:
// Linux hostname 2.6.18-274.12.1.el5 #1 SMP Tue Nov 29 13:37:46 EST 2011 x86_64
// * OracleLinux 6:
// Linux hostname 2.6.32-131.0.15.el6.x86_64 #1 SMP Fri May 20 15:04:03 EDT 2011 x86_64
// * CentOS 7:
// Linux hostname 3.10.0-327.4.5.el7.x86_64 #1 SMP Mon Jan 25 22:07:14 UTC 2016 x86_64
// * RedHat EL:
// Linux hostname 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 29 17:29:29 EDT 2015 x86_64
// Linux hostname 3.10.0-229.20.1.el7.x86_64 #1 SMP Thu Sep 24 12:23:56 EDT 2015 x86_64
// Linux hostname 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Mar 25 14:36:04 EDT 2021 x86_64
elseif (preg_match('/ \d[\.\d]+(\-\d+[\.\d]*\.el(?<distro_ver>\d+(_\d+)?))/', $poll_device['sysDescr'], $matches)) {
// Detect distro by packages
$distro_def = [
// redhat-release-server-6Server-6.7.0.3.el6
// redhat-release-8.3-1.0.el8
[ 'name' => 'redhat-release', 'regex' => '/^redhat\-release[\-_](?<version>\d.*)/', 'distro' => 'RedHat',
'transform' => [ [ 'action' => 'preg_replace', 'from' => '/^(\d+[\.\-]\d+).*/', 'to' => '$1' ],
[ 'action' => 'replace', 'from' => '-', 'to' => '.' ] ] ],
// centos-release-6-3.el6.centos.9
// centos-release-6-9.el6.12.3
// centos-release-7-6.1810.2.el7.centos
[ 'name' => 'centos-release', 'regex' => '/^centos\-release[\-_](?<version>\d.*)/', 'distro' => 'CentOS',
'transform' => [ [ 'action' => 'preg_replace', 'from' => '/^(\d+[\.\-]\d+).*/', 'to' => '$1' ],
[ 'action' => 'replace', 'from' => '-', 'to' => '.' ] ] ],
// rocky-release-8.5-3.el8
[ 'name' => 'rocky-release', 'regex' => '/^rocky\-release[\-_](?<version>\d.*)/', 'distro' => 'Rocky',
'transform' => [ [ 'action' => 'preg_replace', 'from' => '/^(\d+[\.\-]\d+).*/', 'to' => '$1' ],
[ 'action' => 'replace', 'from' => '-', 'to' => '.' ] ] ],
// oraclelinux-release-6Server-1.0.2
// fixme. need more examples
];
$metatypes = [ 'distro', 'distro_ver' ];
foreach (poll_device_unix_packages($device, $metatypes, $distro_def) as $metatype => $value) {
$$metatype = $value;
}
if (safe_empty($distro)) {
// there no way for split RedHat vs CentOS..
//$distro = 'CentOS';
$distro = 'RedHat'; // FIXME. no way for correctly detect redhat or centos, probably by packages?..
$distro_ver = str_replace('_', '.', $matches['distro_ver']);
}
}
// * Slackware:
// Linux hostname 2.6.21.5-smp #2 SMP Tue Jun 19 14:58:11 CDT 2007 i686
} elseif ($poll_device['sysObjectID'] === '.1.3.6.1.4.1.8072.3.2.8' && str_starts($poll_device['sysDescr'], 'FreeBSD ')) {
// * HardenedBSD
if (preg_match('/\-HBSD /', $poll_device['sysDescr'], $matches)) {
$distro = 'HardenedBSD';
}
}
// * Slackware:
// Linux hostname 2.6.21.5-smp #2 SMP Tue Jun 19 14:58:11 CDT 2007 i686
if (isset($distro)) {
print_debug("Linux Distro was set by sysDescr string.");
}
}
// Hardware/vendor "extend" support
if (is_device_mib($device, 'UCD-SNMP-MIB'))
{
if (is_device_mib($device, 'UCD-SNMP-MIB')) {
$hw = snmp_get_oid($device, '.1.3.6.1.4.1.2021.7890.2.3.1.1.8.104.97.114.100.119.97.114.101', 'UCD-SNMP-MIB');
if (strlen($hw))
{
if (strlen($hw)) {
$hardware = rewrite_unix_hardware($poll_device['sysDescr'], $hw);
$vendor = snmp_get_oid($device, '.1.3.6.1.4.1.2021.7890.3.3.1.1.6.118.101.110.100.111.114', 'UCD-SNMP-MIB');
if (!snmp_status())
{
if (!snmp_status()) {
// Alternative with manufacturer
$vendor = snmp_get_oid($device, '.1.3.6.1.4.1.2021.7890.3.3.1.1.12.109.97.110.117.102.97.99.116.117.114.101.114', 'UCD-SNMP-MIB');
}
$serial = snmp_get_oid($device, '.1.3.6.1.4.1.2021.7890.4.3.1.1.6.115.101.114.105.97.108', 'UCD-SNMP-MIB');
//if (str_contains_array($serial, 'denied') || str_starts($serial, [ '0123456789', '..', 'Not Specified' ]))
if (!is_valid_param($serial, 'serial'))
{
if (!is_valid_param($serial, 'serial')) {
unset($serial);
}
}
}
// Use 'os' script virt output, if virt-what agent is not used
if (!isset($agent_data['virt']['what']) && isset($virt))
{
if (!isset($agent_data['virt']['what']) && isset($virt)) {
$agent_data['virt']['what'] = $virt;
}
// Use agent virt-what data if available
if (isset($agent_data['virt']['what']))
{
if (isset($agent_data['virt']['what'])) {
// We cycle through every line here, the previous one is overwritten.
// This is OK, as virt-what prints general-to-specific order and we want most specific.
foreach (explode("\n", $agent_data['virt']['what']) as $virtwhat)
{
if (isset($config['virt-what'][$virtwhat]))
{
foreach (explode("\n", $agent_data['virt']['what']) as $virtwhat) {
if (isset($config['virt-what'][$virtwhat])) {
//$hardware = $config['virt-what'][$virtwhat];
$hardware = rewrite_unix_hardware($poll_device['sysDescr'], $config['virt-what'][$virtwhat]);
$vendor = ''; // Always reset vendor for VMs, while this doesn't make sense
@ -494,8 +490,7 @@ if (isset($agent_data['virt']['what']))
}
}
if (!$features && isset($distro))
{
if (!$features && isset($distro)) {
$features = trim("$distro $distro_ver");
}

View File

@ -0,0 +1,27 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// WISI-GTMODULES-MIB::gtThisModuleSlot.0 = 7
$gtThisModuleSlot = snmp_get_oid($device, 'gtThisModuleSlot.0', 'WISI-GTMODULES-MIB');
if (!safe_empty($gtThisModuleSlot)) {
$data = snmp_get_multi_oid($device, [ 'gtModuleFWID.'.$gtThisModuleSlot, 'gtModuleSerNo.'.$gtThisModuleSlot, 'gtModuleName.'.$gtThisModuleSlot ], [], 'WISI-GTMODULES-MIB');
$version = $data[$gtThisModuleSlot]['gtModuleFWID'];
$serial = $data[$gtThisModuleSlot]['gtModuleSerNo'];
$hardware = $data[$gtThisModuleSlot]['gtModuleName'];
}
unset($gtThisModuleSlot, $data);
// EOF

View File

@ -6,404 +6,50 @@
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
/// FIXME. Rewrite (clean), clean stale entries (after disable)
// Pre-polling checks
if (!$config['enable_ospf'] || !is_device_mib($device, 'OSPF-MIB'))
{
// OSPF not enabled or MIB excluded
if (!$config['enable_ospf']) {
// OSPF not enabled
return;
}
/*
OSPF-MIB::ospfRouterId.0 = IpAddress: 1.185.1.113
OSPF-MIB::ospfAdminStat.0 = INTEGER: enabled(1)
OSPF-MIB::ospfVersionNumber.0 = INTEGER: version2(2)
OSPF-MIB::ospfAreaBdrRtrStatus.0 = INTEGER: false(2)
OSPF-MIB::ospfASBdrRtrStatus.0 = INTEGER: true(1)
OSPF-MIB::ospfExternLsaCount.0 = Gauge32: 104
OSPF-MIB::ospfExternLsaCksumSum.0 = INTEGER: 3322892
OSPF-MIB::ospfTOSSupport.0 = INTEGER: false(2)
OSPF-MIB::ospfOriginateNewLsas.0 = Counter32: 11993
OSPF-MIB::ospfRxNewLsas.0 = Counter32: 553365
OSPF-MIB::ospfExtLsdbLimit.0 = INTEGER: -1
OSPF-MIB::ospfMulticastExtensions.0 = INTEGER: 0
OSPF-MIB::ospfExitOverflowInterval.0 = INTEGER: 0
OSPF-MIB::ospfDemandExtensions.0 = INTEGER: false(2)
*/
$ospf_instance_count = 0;
$ospf_port_count = 0;
$ospf_area_count = 0;
$ospf_nbr_count = 0;
$ospf_stats = [
'instances' => 0,
'ports' => 0,
'areas' => 0,
'neighbours' => 0
];
$set_ospf = FALSE;
// This module not have discovery (only mibs discovery)
$mib_exist = FALSE;
foreach ([ 'OSPF-MIB', 'OSPFV3-MIB' ] as $mib) {
if (is_device_mib($device, $mib)) {
$ospf_enabled = FALSE; // TRUE, when ospf enabled
$ospf_oids_db = array('ospfRouterId', 'ospfAdminStat', 'ospfVersionNumber', 'ospfAreaBdrRtrStatus', 'ospfASBdrRtrStatus',
'ospfExternLsaCount', 'ospfExternLsaCksumSum', 'ospfTOSSupport', 'ospfOriginateNewLsas', 'ospfRxNewLsas',
'ospfExtLsdbLimit', 'ospfMulticastExtensions', 'ospfExitOverflowInterval', 'ospfDemandExtensions');
// Build array of existing entries
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', array($device['device_id']));
// Pull data from device
$ospf_instance_poll = snmpwalk_cache_oid($device, 'ospfGeneralGroup', array(), 'OSPF-MIB');
if (is_array($ospf_instance_poll[0]))
{
$ospf_instance_poll = $ospf_instance_poll[0];
// Don't bother polling everything if we have no enabled or non-defaulted router ids.
if ($ospf_instance_poll['ospfRouterId'] != '0.0.0.0' ||
$ospf_instance_poll['ospfAdminStat'] != 'disabled')
{
$set_ospf = TRUE;
include $config['install_dir'] . '/includes/polling/ospf/'.strtolower($mib).'.inc.php';
}
}
$ospf_areas_poll = array();
$ospf_ports_poll = array();
$ospf_nbrs_poll = array();
if ($set_ospf)
{
$ospf_areas_poll = snmpwalk_cache_oid($device, 'ospfAreaEntry', $ospf_areas_poll, 'OSPF-MIB');
$ospf_ports_poll = snmpwalk_cache_oid($device, 'ospfIfEntry', $ospf_ports_poll, 'OSPF-MIB');
$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'ospfNbrEntry', $ospf_nbrs_poll, 'OSPF-MIB');
if (!$mib_exist) {
// OSPF MIBs excluded
unset($mib_exist, $ospf_enabled, $ospf_stats);
return;
}
print_cli_data_field('Processes', 2);
// Create device-wide statistics RRD
rrdtool_update_ng($device, 'ospf-statistics', [
'instances' => $ospf_stats['instances'],
'areas' => $ospf_stats['areas'],
'ports' => $ospf_stats['ports'],
'neighbours' => $ospf_stats['neighbours'],
]);
if (empty($ospf_instance_db) && !empty($ospf_instance_poll))
{
dbInsert(array('device_id' => $device['device_id']), 'ospf_instances');
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', array($device['device_id']));
echo('+');
}
else if (!empty($ospf_instance_db) && empty($ospf_instance_poll))
{
dbDelete('ospf_instances', '`device_id` = ?', array($device['device_id']));
echo('-');
}
if (OBS_DEBUG && $set_ospf)
{
echo("\nPolled: ");
print_vars($ospf_instance_poll);
echo('Database: ');
print_vars($ospf_instance_db);
echo("\n");
}
// Loop array of entries and update
if (is_array($ospf_instance_db))
{
$ospf_instance_id = $ospf_instance_db['ospf_instance_id'];
$ospf_instance_update = array();
foreach ($ospf_oids_db as $oid)
{ // Loop the OIDs
if ($ospf_instance_db[$oid] != $ospf_instance_poll[$oid])
{ // If data has changed, build a query
$ospf_instance_update[$oid] = $ospf_instance_poll[$oid];
// log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME
}
}
if ($ospf_instance_update)
{
dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id));
echo('U');
unset($ospf_instance_update);
} else {
echo('.');
}
$ospf_instance_count++; // Really in OSPF-MIB always only 1 instance (process)
}
unset($ospf_instance_poll);
unset($ospf_instance_db);
echo(PHP_EOL);
print_cli_data_field('Areas', 2);
$ospf_area_oids = array('ospfAuthType', 'ospfImportAsExtern', 'ospfSpfRuns', 'ospfAreaBdrRtrCount', 'ospfAsBdrRtrCount',
'ospfAreaLsaCount', 'ospfAreaLsaCksumSum', 'ospfAreaSummary', 'ospfAreaStatus');
// Build array of existing entries
foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ?', array($device['device_id'])) as $entry)
{
$ospf_areas_db[$entry['ospfAreaId']] = $entry;
}
foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area)
{
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
if (!isset($ospf_areas_db[$ospf_area_id]))
{
$insert = array();
$insert['device_id'] = $device['device_id'];
$insert['ospfAreaId'] = $ospf_area_id;
foreach ($ospf_area_oids as $oid)
{ // Loop the OIDs
$insert[$oid] = $ospf_area[$oid];
}
dbInsert($insert, 'ospf_areas');
echo('+');
$ospf_areas_db[$ospf_area_id] = dbFetchRow('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id));
unset($insert);
}
}
if (OBS_DEBUG && $set_ospf)
{
echo("\nPolled: ");
print_vars($ospf_areas_poll);
echo('Database: ');
print_vars($ospf_areas_db);
echo("\n");
}
// Loop array of entries and update
if (is_array($ospf_areas_db))
{
foreach ($ospf_areas_db as $ospf_area_id => $ospf_area_db)
{
if (is_array($ospf_areas_poll[$ospf_area_id]))
{
$ospf_area_poll = $ospf_areas_poll[$ospf_area_db['ospfAreaId']];
foreach ($ospf_area_oids as $oid)
{ // Loop the OIDs
if ($ospf_area_db[$oid] != $ospf_area_poll[$oid])
{ // If data has changed, build a query
$ospf_area_update[$oid] = $ospf_area_poll[$oid];
// log_event("$oid -> ".$this_port[$oid], $device, 'port', $port['port_id']); // FIXME
} else {
// echo($ospf_area_db[$oid] . '=' . $ospf_area_poll[$oid]);
}
}
if ($ospf_area_update)
{
dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id));
echo('U');
unset($ospf_area_update);
} else {
echo('.');
}
$ospf_area_count++;
} else {
dbDelete('ospf_areas', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId']));
echo '-';
}
}
}
unset($ospf_areas_db);
unset($ospf_areas_poll);
echo PHP_EOL;
print_cli_data_field('Ports', 2);
$ospf_port_oids = array('ospfIfIpAddress','port_id','ospfAddressLessIf','ospfIfAreaId','ospfIfType','ospfIfAdminStat','ospfIfRtrPriority','ospfIfTransitDelay','ospfIfRetransInterval','ospfIfHelloInterval','ospfIfRtrDeadInterval','ospfIfPollInterval','ospfIfState','ospfIfDesignatedRouter','ospfIfBackupDesignatedRouter','ospfIfEvents','ospfIfAuthKey','ospfIfStatus','ospfIfMulticastForwarding','ospfIfDemand','ospfIfAuthType');
// Build array of existing entries
foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ?', array($device['device_id'])) as $entry)
{
$ospf_ports_db[$entry['ospf_port_id']] = $entry;
}
foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port)
{
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
if (!isset($ospf_ports_db[$ospf_port_id]))
{
dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id), 'ospf_ports');
echo('+');
$ospf_ports_db[$entry['ospf_port_id']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id));
}
}
if (OBS_DEBUG && $set_ospf)
{
echo("\nPolled: ");
print_vars($ospf_ports_poll);
echo('Database: ');
print_vars($ospf_ports_db);
echo("\n");
}
// Loop array of entries and update
if (is_array($ospf_ports_db))
{
foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db)
{
if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']]))
{
$ospf_port_poll = $ospf_ports_poll[$ospf_port_db['ospf_port_id']];
if ($ospf_port_poll['ospfAddressLessIf']) {
$ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf']));
} else {
//$ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id']));
$ids = get_entity_ids_ip_by_network('port', $ospf_port_poll['ospfIfIpAddress'], generate_query_values($device['device_id'], 'device_id'));
if (safe_count($ids)) {
$ospf_port_poll['port_id'] = current($ids);
}
}
foreach ($ospf_port_oids as $oid)
{ // Loop the OIDs
if ($ospf_port_db[$oid] != $ospf_port_poll[$oid])
{ // If data has changed, build a query
$ospf_port_update[$oid] = $ospf_port_poll[$oid];
// log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME
}
}
if ($ospf_port_update)
{
dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id));
echo('U');
unset($ospf_port_update);
} else {
echo('.');
}
unset($ospf_port_poll);
unset($ospf_port_db);
$ospf_port_count++;
} else {
dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id']));
echo('-');
}
}
}
echo PHP_EOL;
// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98
// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0
// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128
// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2
// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0
// OSPF-MIB::ospfNbrState.172.22.203.98.0 full
// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6
// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1
// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active
// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic
// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false
print_cli_data_field('Neighbours',2);
$ospf_nbr_oids_db = array('ospfNbrIpAddr', 'ospfNbrAddressLessIndex', 'ospfNbrRtrId', 'ospfNbrOptions', 'ospfNbrPriority', 'ospfNbrState', 'ospfNbrEvents', 'ospfNbrLsRetransQLen', 'ospfNbmaNbrStatus', 'ospfNbmaNbrPermanence', 'ospfNbrHelloSuppressed');
$ospf_nbr_oids_rrd = array();
$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd);
// Build array of existing entries
foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ?', array($device['device_id'])) as $nbr_entry)
{
$ospf_nbrs_db[$nbr_entry['ospf_nbr_id']] = $nbr_entry;
}
foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr)
{
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
if (!isset($ospf_nbrs_db[$ospf_nbr_id]))
{
dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id), 'ospf_nbrs');
echo('+');
$entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id));
$ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry;
}
}
if (OBS_DEBUG && $set_ospf)
{
echo("\nPolled: ");
print_vars($ospf_nbrs_poll);
echo('Database: ');
print_vars($ospf_nbrs_db);
echo("\n");
}
// Loop array of entries and update
if (is_array($ospf_nbrs_db))
{
foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db)
{
if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]))
{
$ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']];
//$ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM `ipv4_addresses` AS A, `ospf_nbrs` AS I WHERE A.`ipv4_address` = ? AND I.`port_id` = A.`port_id` AND I.`device_id` = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id']));
$ids = get_entity_ids_ip_by_network('port', $ospf_nbr_poll['ospfNbrIpAddr'], generate_query_values($device['device_id'], 'device_id'));
if (safe_count($ids)) {
$ospf_nbr_poll['port_id'] = current($ids);
} else {
$ospf_nbr_poll['port_id'] = NULL;
}
if ($ospf_nbr_db['port_id'] != $ospf_nbr_poll['port_id']) {
if ($ospf_nbr_poll['port_id']) {
$ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']);
} else {
$ospf_nbr_update = array('port_id' => array('NULL'));
}
}
foreach ($ospf_nbr_oids as $oid)
{ // Loop the OIDs
print_debug($ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]);
if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid])
{ // If data has changed, build a query
$ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid];
// log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME
}
}
if ($ospf_nbr_update)
{
dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id));
echo('U');
unset($ospf_nbr_update);
} else {
echo('.');
}
unset($ospf_nbr_poll);
unset($ospf_nbr_db);
$ospf_nbr_count++;
} else {
dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id']));
echo('-');
}
}
}
echo PHP_EOL;
if ($set_ospf)
{
// Create device-wide statistics RRD
rrdtool_update_ng($device, 'ospf-statistics', array(
'instances' => $ospf_instance_count,
'areas' => $ospf_area_count,
'ports' => $ospf_port_count,
'neighbours' => $ospf_nbr_count,
));
$graphs['ospf_neighbours'] = TRUE;
$graphs['ospf_areas'] = TRUE;
$graphs['ospf_ports'] = TRUE;
}
unset($ospf_ports_db);
unset($ospf_ports_poll);
$graphs['ospf_neighbours'] = TRUE;
$graphs['ospf_areas'] = TRUE;
$graphs['ospf_ports'] = TRUE;
// EOF

View File

@ -0,0 +1,447 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
print_cli_data_field($mib . ' Processes', 2);
/*
OSPF-MIB::ospfRouterId.0 = IpAddress: 1.185.1.113
OSPF-MIB::ospfAdminStat.0 = INTEGER: enabled(1)
OSPF-MIB::ospfVersionNumber.0 = INTEGER: version2(2)
OSPF-MIB::ospfAreaBdrRtrStatus.0 = INTEGER: false(2)
OSPF-MIB::ospfASBdrRtrStatus.0 = INTEGER: true(1)
OSPF-MIB::ospfExternLsaCount.0 = Gauge32: 104
OSPF-MIB::ospfExternLsaCksumSum.0 = INTEGER: 3322892
OSPF-MIB::ospfTOSSupport.0 = INTEGER: false(2)
OSPF-MIB::ospfOriginateNewLsas.0 = Counter32: 11993
OSPF-MIB::ospfRxNewLsas.0 = Counter32: 553365
OSPF-MIB::ospfExtLsdbLimit.0 = INTEGER: -1
OSPF-MIB::ospfMulticastExtensions.0 = INTEGER: 0
OSPF-MIB::ospfExitOverflowInterval.0 = INTEGER: 0
OSPF-MIB::ospfDemandExtensions.0 = INTEGER: false(2)
*/
// Pull data from device
if ($ospf_instance_poll = snmpwalk_cache_oid($device, 'ospfGeneralGroup', [], 'OSPF-MIB')) {
$ospf_instance_poll = $ospf_instance_poll[0];
// Don't bother polling everything if we have no enabled or non-defaulted router ids.
if ($ospf_instance_poll['ospfRouterId'] !== '0.0.0.0' ||
$ospf_instance_poll['ospfAdminStat'] === 'enabled') {
$ospf_enabled = TRUE;
}
}
// Build array of existing entries
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospfVersionNumber` = ?', [ $device['device_id'], 'version2' ]);
if ($ospf_enabled && empty($ospf_instance_db)) {
$ospf_instance_id = dbInsert([ 'device_id' => $device['device_id'], 'ospfVersionNumber' => 'version2' ], 'ospf_instances');
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `ospf_instance_id` = ?', [ $ospf_instance_id ]);
echo('+');
} elseif (!$ospf_enabled && !empty($ospf_instance_db)) {
dbDelete('ospf_instances', '`ospf_instance_id` = ?', [ $ospf_instance_db['instance_id'] ]);
echo('-');
}
if (!$ospf_enabled) {
// OSPF instance not enabled
return;
} elseif (OBS_DEBUG) {
echo("\nPolled: ");
print_vars($ospf_instance_poll);
echo('Database: ');
print_vars($ospf_instance_db);
echo("\n");
}
$ospf_oids_db = [ 'ospfRouterId', 'ospfAdminStat', 'ospfVersionNumber', 'ospfAreaBdrRtrStatus', 'ospfASBdrRtrStatus',
'ospfExternLsaCount', 'ospfExternLsaCksumSum', 'ospfTOSSupport', 'ospfOriginateNewLsas', 'ospfRxNewLsas',
'ospfExtLsdbLimit', 'ospfMulticastExtensions', 'ospfExitOverflowInterval', 'ospfDemandExtensions' ];
// Loop array of entries and update
$ospf_instance_id = $ospf_instance_db['ospf_instance_id'];
if ($ospf_instance_poll['ospfAdminStat'] !== 'enabled') {
$ospf_instance_poll['ospfAdminStat'] = 'disabled';
}
if ($ospf_instance_poll['ospfVersionNumber'] !== 'version2') {
$ospf_instance_poll['ospfVersionNumber'] = 'version2';
}
$ospf_instance_update = [];
foreach ($ospf_oids_db as $oid) {
if (in_array($oid, [ 'ospfAreaBdrRtrStatus', 'ospfASBdrRtrStatus', 'ospfTOSSupport', 'ospfDemandExtensions' ]) &&
!in_array($ospf_instance_poll[$oid], [ 'true', 'false' ])) {
// FIX invalid values
$ospf_instance_poll[$oid] = 'false';
}
// Loop the OIDs
if ($ospf_instance_db[$oid] != $ospf_instance_poll[$oid]) {
// If data has changed, build a query
$ospf_instance_update[$oid] = $ospf_instance_poll[$oid];
// log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME
}
}
if ($ospf_instance_update) {
dbUpdate($ospf_instance_update, 'ospf_instances', '`ospf_instance_id` = ?', [ $ospf_instance_id ]);
echo('U');
} else {
echo('.');
}
$ospf_stats['instances']++; // Really in OSPF-MIB always only 1 instance (process)
unset($ospf_instance_poll, $ospf_instance_db, $ospf_instance_update);
echo(PHP_EOL);
print_cli_data_field($mib.' Areas', 2);
/*
OSPF-MIB::ospfAreaId.0.0.0.0 = IpAddress: 0.0.0.0
OSPF-MIB::ospfAuthType.0.0.0.0 = INTEGER: none(0)
OSPF-MIB::ospfImportAsExtern.0.0.0.0 = INTEGER: importExternal(1)
OSPF-MIB::ospfSpfRuns.0.0.0.0 = Counter32: 5
OSPF-MIB::ospfAreaBdrRtrCount.0.0.0.0 = Gauge32: 0
OSPF-MIB::ospfAsBdrRtrCount.0.0.0.0 = Gauge32: 3
OSPF-MIB::ospfAreaLsaCount.0.0.0.0 = Gauge32: 8
OSPF-MIB::ospfAreaLsaCksumSum.0.0.0.0 = INTEGER: 0
OSPF-MIB::ospfAreaSummary.0.0.0.0 = INTEGER: sendAreaSummary(2)
OSPF-MIB::ospfAreaStatus.0.0.0.0 = INTEGER: active(1)
*/
$ospf_areas_poll = snmpwalk_cache_oid($device, 'ospfAreaEntry', [], 'OSPF-MIB');
$ospf_area_oids = [ 'ospfAuthType', 'ospfImportAsExtern', 'ospfSpfRuns', 'ospfAreaBdrRtrCount', 'ospfAsBdrRtrCount',
'ospfAreaLsaCount', 'ospfAreaLsaCksumSum', 'ospfAreaSummary', 'ospfAreaStatus' ];
// Build array of existing entries
$ospf_areas_db = [];
if (get_db_version() < 477) {
// CLEANME. Remove after CE 23.xx
$sql = 'SELECT * FROM `ospf_areas` WHERE `device_id` = ?';
$params = [ $device['device_id'] ];
} else {
$sql = 'SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfVersionNumber` = ?';
$params = [ $device['device_id'], 'version2' ];
}
foreach (dbFetchRows($sql, $params) as $entry) {
// Skip OSPFV3-MIB entries
if (isset($entry['ospfVersionNumber']) && $entry['ospfVersionNumber'] === 'version3') { continue; }
$ospf_areas_db[$entry['ospfAreaId']] = $entry;
}
if (OBS_DEBUG) {
echo("\nPolled: ");
print_vars($ospf_areas_poll);
echo('Database: ');
print_vars($ospf_areas_db);
echo("\n");
}
foreach ($ospf_areas_poll as $ospf_area_index => $ospf_area_poll) {
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
$insert = [];
if (!isset($ospf_areas_db[$ospf_area_index])) {
$insert['device_id'] = $device['device_id'];
$insert['ospfAreaId'] = $ospf_area_index;
$insert['ospfVersionNumber'] = 'version2';
foreach ($ospf_area_oids as $oid) {
// Loop the OIDs
$insert[$oid] = $ospf_area_poll[$oid];
}
dbInsertRowMulti($insert, 'ospf_areas');
// $ospf_area_id = dbInsert($insert, 'ospf_areas');
echo('+');
// $ospf_areas_db[$ospf_area_index] = dbFetchRow('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ?', [ $device['device_id'], $ospf_area_index ]);
} else {
$ospf_area_db = $ospf_areas_db[$ospf_area_index];
$db_update = FALSE;
$insert['ospf_area_id'] = $ospf_area_db['ospf_area_id'];
foreach ($ospf_area_oids as $oid) {
// Loop the OIDs
$insert[$oid] = $ospf_area_poll[$oid];
if ($ospf_area_db[$oid] != $ospf_area_poll[$oid]) {
$db_update = TRUE;
}
}
if ($db_update) {
$insert['ospfVersionNumber'] = 'version2';
dbUpdateRowMulti($insert, 'ospf_areas', 'ospf_area_id');
echo('U');
} else {
echo('.');
}
unset($ospf_areas_db[$ospf_area_index]);
}
$ospf_stats['areas']++;
unset($insert);
}
// Multi Insert/Update
dbProcessMulti('ospf_areas');
// Clean
$db_delete = [];
foreach ($ospf_areas_db as $ospf_area_db) {
$db_delete[] = $ospf_area_db['ospf_area_id'];
echo '-';
}
// Multi Delete
if (!safe_empty($db_delete)) {
dbDelete('ospf_areas', generate_query_values_ng($db_delete, 'ospf_area_id'));
}
unset($ospf_areas_db, $ospf_areas_poll, $db_delete);
echo PHP_EOL;
print_cli_data_field($mib .' Ports', 2);
/*
OSPF-MIB::ospfIfIpAddress.95.130.232.140.0 = IpAddress: 95.130.232.140
OSPF-MIB::ospfAddressLessIf.95.130.232.140.0 = INTEGER: 0
OSPF-MIB::ospfIfAreaId.95.130.232.140.0 = IpAddress: 0.0.0.0
OSPF-MIB::ospfIfType.95.130.232.140.0 = INTEGER: broadcast(1)
OSPF-MIB::ospfIfAdminStat.95.130.232.140.0 = INTEGER: enabled(1)
OSPF-MIB::ospfIfRtrPriority.95.130.232.140.0 = INTEGER: 10
OSPF-MIB::ospfIfTransitDelay.95.130.232.140.0 = INTEGER: 1 seconds
OSPF-MIB::ospfIfRetransInterval.95.130.232.140.0 = INTEGER: 5 seconds
OSPF-MIB::ospfIfHelloInterval.95.130.232.140.0 = INTEGER: 10 seconds
OSPF-MIB::ospfIfRtrDeadInterval.95.130.232.140.0 = INTEGER: 40 seconds
OSPF-MIB::ospfIfPollInterval.95.130.232.140.0 = INTEGER: 60 seconds
OSPF-MIB::ospfIfState.95.130.232.140.0 = INTEGER: otherDesignatedRouter(7)
OSPF-MIB::ospfIfDesignatedRouter.95.130.232.140.0 = IpAddress: 95.130.232.130
OSPF-MIB::ospfIfBackupDesignatedRouter.95.130.232.140.0 = IpAddress: 95.130.232.190
OSPF-MIB::ospfIfEvents.95.130.232.140.0 = Counter32: 2
OSPF-MIB::ospfIfAuthKey.95.130.232.140.0 = ""
OSPF-MIB::ospfIfStatus.95.130.232.140.0 = INTEGER: active(1)
OSPF-MIB::ospfIfMulticastForwarding.95.130.232.140.0 = INTEGER: blocked(1)
OSPF-MIB::ospfIfDemand.95.130.232.140.0 = INTEGER: false(2)
OSPF-MIB::ospfIfAuthType.95.130.232.140.0 = INTEGER: none(0)
*/
$ospf_ports_poll = snmpwalk_cache_oid($device, 'ospfIfEntry', [], 'OSPF-MIB');
$ospf_port_oids = [ 'ospfIfIpAddress', 'ospfAddressLessIf', 'ospfIfAreaId', 'ospfIfType',
'ospfIfAdminStat', 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval',
'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState',
'ospfIfDesignatedRouter', 'ospfIfBackupDesignatedRouter', 'ospfIfEvents', 'ospfIfAuthKey',
'ospfIfStatus', 'ospfIfMulticastForwarding', 'ospfIfDemand', 'ospfIfAuthType' ];
// Build array of existing entries
// V2 always have 5 part index, ie: 95.130.232.140.0
foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` REGEXP ?',
[ $device['device_id'], '^[[:digit:]]+(\.[[:digit:]]+){4}$' ]) as $entry) {
$ospf_ports_db[$entry['ospf_port_id']] = $entry;
}
if (OBS_DEBUG) {
echo("\nPolled: ");
print_vars($ospf_ports_poll);
echo('Database: ');
print_vars($ospf_ports_db);
echo("\n");
}
foreach ($ospf_ports_poll as $ospf_port_index => $ospf_port_poll) {
$insert = [];
// Get associated port
$insert['port_id'] = 0; // Unknown
if ($ospf_port_poll['ospfAddressLessIf']) {
//$ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', [ $device['device_id'], $ospf_port_poll['ospfAddressLessIf'] ]);
if ($port = get_port_by_index_cache($device, $ospf_port_poll['ospfAddressLessIf'])) {
$insert['port_id'] = $port['port_id'];
}
} else {
$ids = get_entity_ids_ip_by_network('port', $ospf_port_poll['ospfIfIpAddress'], generate_query_values_and($device['device_id'], 'device_id'));
if (safe_count($ids)) {
$insert['port_id'] = current($ids);
}
}
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
if (!isset($ospf_ports_db[$ospf_port_index])) {
$insert['device_id'] = $device['device_id'];
$insert['ospf_port_id'] = $ospf_port_index;
foreach ($ospf_port_oids as $oid) {
// Loop the OIDs
$insert[$oid] = $ospf_port_poll[$oid];
}
dbInsertRowMulti($insert, 'ospf_ports');
echo('+');
} else {
$ospf_port_db = $ospf_ports_db[$ospf_port_index];
$db_update = FALSE;
$insert['ospf_ports_id'] = $ospf_port_db['ospf_ports_id'];
foreach ($ospf_port_oids as $oid) {
// Loop the OIDs
$insert[$oid] = $ospf_port_poll[$oid];
if ($ospf_port_db[$oid] != $ospf_port_poll[$oid]) {
$db_update = TRUE;
}
}
if ($db_update) {
dbUpdateRowMulti($insert, 'ospf_ports', 'ospf_ports_id');
echo('U');
} else {
echo('.');
}
unset($ospf_ports_db[$ospf_port_index]);
}
$ospf_stats['ports']++;
unset($insert);
}
// Multi Insert/Update
dbProcessMulti('ospf_ports');
// Clean
$db_delete = [];
foreach ($ospf_ports_db as $ospf_port_db) {
$db_delete[] = $ospf_port_db['ospf_ports_id'];
echo '-';
}
// Multi Delete
if (!safe_empty($db_delete)) {
dbDelete('ospf_ports', generate_query_values_ng($db_delete, 'ospf_ports_id'));
}
unset($ospf_ports_db, $ospf_ports_poll, $db_delete);
echo PHP_EOL;
print_cli_data_field($mib . ' Neighbours', 2);
/*
OSPF-MIB::ospfNbrIpAddr.95.130.232.130.0 = IpAddress: 95.130.232.130
OSPF-MIB::ospfNbrAddressLessIndex.95.130.232.130.0 = INTEGER: 0
OSPF-MIB::ospfNbrRtrId.95.130.232.130.0 = IpAddress: 185.100.140.1
OSPF-MIB::ospfNbrOptions.95.130.232.130.0 = INTEGER: 2
OSPF-MIB::ospfNbrPriority.95.130.232.130.0 = INTEGER: 10
OSPF-MIB::ospfNbrState.95.130.232.130.0 = INTEGER: full(8)
OSPF-MIB::ospfNbrEvents.95.130.232.130.0 = Counter32: 6
OSPF-MIB::ospfNbrLsRetransQLen.95.130.232.130.0 = Gauge32: 0
OSPF-MIB::ospfNbmaNbrStatus.95.130.232.130.0 = INTEGER: active(1)
OSPF-MIB::ospfNbmaNbrPermanence.95.130.232.130.0 = INTEGER: permanent(2)
OSPF-MIB::ospfNbrHelloSuppressed.95.130.232.130.0 = INTEGER: false(2)
*/
$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'ospfNbrEntry', [], 'OSPF-MIB');
$ospf_nbr_oids = [ 'ospfNbrIpAddr', 'ospfNbrAddressLessIndex', 'ospfNbrRtrId', 'ospfNbrOptions', 'ospfNbrPriority',
'ospfNbrState', 'ospfNbrEvents', 'ospfNbrLsRetransQLen', 'ospfNbmaNbrStatus',
'ospfNbmaNbrPermanence', 'ospfNbrHelloSuppressed' ];
// Build array of existing entries
// V2 always have 5 part index, ie: .95.130.232.130.0
foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` REGEXP ?',
[ $device['device_id'], '^[[:digit:]]+(\.[[:digit:]]+){4}$' ]) as $entry) {
$ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry;
}
if (OBS_DEBUG) {
echo("\nPolled: ");
print_vars($ospf_nbrs_poll);
echo('Database: ');
print_vars($ospf_nbrs_db);
echo("\n");
}
foreach ($ospf_nbrs_poll as $ospf_nbr_index => $ospf_nbr_poll) {
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
$insert = [];
// Get associated port
$insert['port_id'] = NULL; // Unknown
if ($ospf_nbr_poll['ospfNbrAddressLessIndex']) {
if ($port = get_port_by_index_cache($device, $ospf_nbr_poll['ospfNbrAddressLessIndex'])) {
$insert['port_id'] = $port['port_id'];
}
} else {
// FIXME. This is incorrect, need search port by network range:
// 95.130.232.130 -> 95.130.232.140/26 -> port
$ids = get_entity_ids_ip_by_network('port', $ospf_nbr_poll['ospfNbrIpAddr'], generate_query_values_and($device['device_id'], 'device_id'));
if (safe_count($ids)) {
$insert['port_id'] = current($ids);
}
}
if (!isset($ospf_nbrs_db[$ospf_nbr_index])) {
$insert['device_id'] = $device['device_id'];
$insert['ospf_nbr_id'] = $ospf_nbr_index;
if (is_null($insert['port_id'])) {
$insert['port_id'] = [ 'NULL' ];
}
foreach ($ospf_nbr_oids as $oid) {
// Loop the OIDs
$insert[$oid] = $ospf_nbr_poll[$oid];
}
dbInsertRowMulti($insert, 'ospf_nbrs');
echo('+');
} else {
$ospf_nbr_db = $ospf_nbrs_db[$ospf_nbr_index];
$db_update = FALSE;
$insert['ospf_nbrs_id'] = $ospf_nbr_db['ospf_nbrs_id'];
foreach ($ospf_nbr_oids as $oid) {
// Loop the OIDs
$insert[$oid] = $ospf_nbr_poll[$oid];
if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid]) {
$db_update = TRUE;
}
}
if ($ospf_nbr_db['port_id'] != $insert['port_id']) {
$db_update = TRUE;
}
if ($db_update) {
if (is_null($insert['port_id'])) {
$insert['port_id'] = [ 'NULL' ];
}
dbUpdateRowMulti($insert, 'ospf_nbrs', 'ospf_nbrs_id');
echo('U');
} else {
echo('.');
}
unset($ospf_nbrs_db[$ospf_nbr_index]);
}
$ospf_stats['neighbours']++;
unset($insert);
}
// Multi Insert/Update
dbProcessMulti('ospf_nbrs');
// Clean
$db_delete = [];
foreach ($ospf_nbrs_db as $ospf_nbr_db) {
$db_delete[] = $ospf_nbr_db['ospf_nbrs_id'];
echo '-';
}
// Multi Delete
if (!safe_empty($db_delete)) {
dbDelete('ospf_nbrs', generate_query_values_ng($db_delete, 'ospf_nbrs_id'));
}
unset($ospf_nbrs_db, $ospf_nbrs_poll, $db_delete);
echo PHP_EOL;
// EOF

View File

@ -0,0 +1,462 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// CLEANME. Remove after CE 23.xx
if (get_db_version() < 477) {
print_warning("DB schema not updated. OSPFV3-MIB not polled until update.");
return;
}
print_cli_data_field($mib . ' Processes', 2);
/*
OSPFV3-MIB::ospfv3RouterId.0 = Gauge32: 1602414732
OSPFV3-MIB::ospfv3AdminStatus.0 = INTEGER: enabled(1)
OSPFV3-MIB::ospfv3VersionNumber.0 = INTEGER: version3(3)
OSPFV3-MIB::ospfv3AreaBdrRtrStatus.0 = INTEGER: false(2)
OSPFV3-MIB::ospfv3ASBdrRtrStatus.0 = INTEGER: false(2)
OSPFV3-MIB::ospfv3AsScopeLsaCount.0 = Gauge32: 2
OSPFV3-MIB::ospfv3AsScopeLsaCksumSum.0 = Gauge32: 11269
OSPFV3-MIB::ospfv3OriginateNewLsas.0 = Counter32: 0
OSPFV3-MIB::ospfv3RxNewLsas.0 = Counter32: 0
OSPFV3-MIB::ospfv3ExtLsaCount.0 = Gauge32: 2
OSPFV3-MIB::ospfv3ExtAreaLsdbLimit.0 = INTEGER: -1
OSPFV3-MIB::ospfv3ExitOverflowInterval.0 = Gauge32: 0 seconds
OSPFV3-MIB::ospfv3DemandExtensions.0 = INTEGER: 0
*/
// Pull data from device
if ($ospf_instance_poll = snmpwalk_cache_oid($device, 'ospfv3GeneralGroup', [], 'OSPFV3-MIB')) {
$ospf_instance_poll = $ospf_instance_poll[0];
// Don't bother polling everything if we have no enabled or non-defaulted router ids.
if ($ospf_instance_poll['ospfv3RouterId'] !== '0' ||
$ospf_instance_poll['ospfv3AdminStatus'] === 'enabled') {
$ospf_enabled = TRUE;
}
}
// Build array of existing entries
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospfVersionNumber` = ?', [ $device['device_id'], 'version3' ]);
if ($ospf_enabled && empty($ospf_instance_db)) {
$ospf_instance_id = dbInsert([ 'device_id' => $device['device_id'], 'ospfVersionNumber' => 'version3' ], 'ospf_instances');
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `ospf_instance_id` = ?', [ $ospf_instance_id ]);
echo('+');
} elseif (!$ospf_enabled && !empty($ospf_instance_db)) {
dbDelete('ospf_instances', '`ospf_instance_id` = ?', [ $ospf_instance_db['instance_id'] ]);
echo('-');
}
if (!$ospf_enabled) {
// OSPF instance not enabled
return;
} elseif (OBS_DEBUG) {
echo("\nPolled: ");
print_vars($ospf_instance_poll);
echo('Database: ');
print_vars($ospf_instance_db);
echo("\n");
}
$ospf_oids_db = [ 'ospfRouterId' => 'ospfv3RouterId', 'ospfAdminStat' => 'ospfv3AdminStatus',
'ospfVersionNumber' => 'ospfv3VersionNumber', 'ospfAreaBdrRtrStatus' => 'ospfv3AreaBdrRtrStatus',
'ospfASBdrRtrStatus' => 'ospfv3ASBdrRtrStatus', 'ospfExternLsaCount' => 'ospfv3ExtLsaCount',
'ospfExternLsaCksumSum' => '', 'ospfTOSSupport' => '',
'ospfOriginateNewLsas' => 'ospfv3OriginateNewLsas', 'ospfRxNewLsas' => 'ospfv3RxNewLsas',
'ospfExtLsdbLimit' => 'ospfv3ExtAreaLsdbLimit', 'ospfMulticastExtensions' => '',
'ospfExitOverflowInterval' => 'ospfv3ExitOverflowInterval', 'ospfDemandExtensions' => 'ospfv3DemandExtensions' ];
// Loop array of entries and update
$ospf_instance_id = $ospf_instance_db['ospf_instance_id'];
if ($ospf_instance_poll['ospfv3AdminStatus'] !== 'enabled') {
$ospf_instance_poll['ospfv3AdminStatus'] = 'disabled';
}
if ($ospf_instance_poll['ospfv3VersionNumber'] !== 'version3') {
$ospf_instance_poll['ospfv3VersionNumber'] = 'version3';
}
// Not exist in version3:
$ospf_instance_poll['ospfExternLsaCksumSum'] = '0';
$ospf_instance_poll['ospfTOSSupport'] = 'false';
$ospf_instance_poll['ospfMulticastExtensions'] = '0';
$ospf_instance_update = [];
foreach ($ospf_oids_db as $field => $oid) {
if (in_array($field, [ 'ospfAreaBdrRtrStatus', 'ospfASBdrRtrStatus', 'ospfDemandExtensions' ]) &&
!in_array($ospf_instance_poll[$oid], [ 'true', 'false' ])) {
// FIX invalid values
$ospf_instance_poll[$oid] = 'false';
}
// Loop the OIDs
if (empty($oid)) {
// not exist oids in version3
if ($ospf_instance_db[$field] != $ospf_instance_poll[$field]) {
$ospf_instance_update[$field] = $ospf_instance_poll[$field];
}
} elseif ($ospf_instance_db[$field] != $ospf_instance_poll[$oid]) {
// If data has changed, build a query
$ospf_instance_update[$field] = $ospf_instance_poll[$oid];
// log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME
}
}
if ($ospf_instance_update) {
dbUpdate($ospf_instance_update, 'ospf_instances', '`ospf_instance_id` = ?', [ $ospf_instance_id ]);
echo('U');
} else {
echo('.');
}
$ospf_stats['instances']++; // Really in OSPF-MIB always only 1 instance (process)
unset($ospf_instance_poll, $ospf_instance_db, $ospf_instance_update);
echo(PHP_EOL);
print_cli_data_field($mib.' Areas', 2);
/*
OSPFV3-MIB::ospfv3AreaImportAsExtern.0 = INTEGER: importExternal(1)
OSPFV3-MIB::ospfv3AreaSpfRuns.0 = Counter32: 5
OSPFV3-MIB::ospfv3AreaBdrRtrCount.0 = Gauge32: 0
OSPFV3-MIB::ospfv3AreaAsBdrRtrCount.0 = Gauge32: 2
OSPFV3-MIB::ospfv3AreaScopeLsaCount.0 = Gauge32: 16
OSPFV3-MIB::ospfv3AreaScopeLsaCksumSum.0 = Gauge32: 92
OSPFV3-MIB::ospfv3AreaSummary.0 = INTEGER: sendAreaSummary(2)
OSPFV3-MIB::ospfv3AreaRowStatus.0 = INTEGER: active(1)
*/
$ospf_areas_poll = snmpwalk_cache_oid($device, 'ospfv3AreaEntry', [], 'OSPFV3-MIB');
$ospf_area_oids = [ /* 'ospfAuthType' => '', */ 'ospfImportAsExtern' => 'ospfv3AreaImportAsExtern',
'ospfSpfRuns' => 'ospfv3AreaSpfRuns', 'ospfAreaBdrRtrCount' => 'ospfv3AreaBdrRtrCount',
'ospfAsBdrRtrCount' => 'ospfv3AreaAsBdrRtrCount', 'ospfAreaLsaCount' => 'ospfv3AreaScopeLsaCount',
'ospfAreaLsaCksumSum' => 'ospfv3AreaScopeLsaCksumSum', 'ospfAreaSummary' => 'ospfv3AreaSummary',
'ospfAreaStatus' => 'ospfv3AreaRowStatus' ];
// Build array of existing entries
$ospf_areas_db = [];
foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfVersionNumber` = ?', [ $device['device_id'], 'version3' ]) as $entry) {
$ospf_areas_db[$entry['ospfAreaId']] = $entry;
}
if (OBS_DEBUG) {
echo("\nPolled: ");
print_vars($ospf_areas_poll);
echo('Database: ');
print_vars($ospf_areas_db);
echo("\n");
}
foreach ($ospf_areas_poll as $ospf_area_index => $ospf_area_poll) {
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
$insert = [];
if (!isset($ospf_areas_db[$ospf_area_index])) {
$insert['device_id'] = $device['device_id'];
$insert['ospfAreaId'] = $ospf_area_index;
$insert['ospfVersionNumber'] = 'version3';
foreach ($ospf_area_oids as $field => $oid) {
// Loop the OIDs
$insert[$field] = $ospf_area_poll[$oid];
}
dbInsertRowMulti($insert, 'ospf_areas');
echo('+');
} else {
$ospf_area_db = $ospf_areas_db[$ospf_area_index];
$db_update = FALSE;
$insert['ospf_area_id'] = $ospf_area_db['ospf_area_id'];
foreach ($ospf_area_oids as $field => $oid) {
// Loop the OIDs
$insert[$field] = $ospf_area_poll[$oid];
if ($ospf_area_db[$field] != $ospf_area_poll[$oid]) {
$db_update = TRUE;
}
}
if ($db_update) {
$insert['ospfVersionNumber'] = 'version3';
dbUpdateRowMulti($insert, 'ospf_areas', 'ospf_area_id');
echo('U');
} else {
echo('.');
}
unset($ospf_areas_db[$ospf_area_index]);
}
$ospf_stats['areas']++;
unset($insert);
}
// Multi Insert/Update
dbProcessMulti('ospf_areas');
// Clean
$db_delete = [];
foreach ($ospf_areas_db as $ospf_area_db) {
$db_delete[] = $ospf_area_db['ospf_area_id'];
echo '-';
}
// Multi Delete
if (!safe_empty($db_delete)) {
dbDelete('ospf_areas', generate_query_values_ng($db_delete, 'ospf_area_id'));
}
unset($ospf_areas_db, $ospf_areas_poll, $db_delete);
echo PHP_EOL;
print_cli_data_field($mib .' Ports', 2);
/*
OSPFV3-MIB::ospfv3IfAreaId.6.0 = Gauge32: 0
OSPFV3-MIB::ospfv3IfType.6.0 = INTEGER: broadcast(1)
OSPFV3-MIB::ospfv3IfAdminStatus.6.0 = INTEGER: enabled(1)
OSPFV3-MIB::ospfv3IfRtrPriority.6.0 = INTEGER: 1
OSPFV3-MIB::ospfv3IfTransitDelay.6.0 = Gauge32: 1 seconds
OSPFV3-MIB::ospfv3IfRetransInterval.6.0 = Gauge32: 5 seconds
OSPFV3-MIB::ospfv3IfHelloInterval.6.0 = INTEGER: 10 seconds
OSPFV3-MIB::ospfv3IfRtrDeadInterval.6.0 = Gauge32: 40 seconds
OSPFV3-MIB::ospfv3IfState.6.0 = INTEGER: otherDesignatedRouter(7)
OSPFV3-MIB::ospfv3IfDesignatedRouter.6.0 = Gauge32: 1602414732
OSPFV3-MIB::ospfv3IfBackupDesignatedRouter.6.0 = Gauge32: 0
OSPFV3-MIB::ospfv3IfEvents.6.0 = Counter32: 4
OSPFV3-MIB::ospfv3IfRowStatus.6.0 = INTEGER: active(1)
OSPFV3-MIB::ospfv3IfDemand.6.0 = INTEGER: false(2)
OSPFV3-MIB::ospfv3IfMetricValue.6.0 = INTEGER: 200
OSPFV3-MIB::ospfv3IfLinkScopeLsaCount.6.0 = Gauge32: 1
OSPFV3-MIB::ospfv3IfLinkLsaCksumSum.6.0 = Gauge32: 40843
*/
$ospf_ports_poll = snmpwalk_cache_oid($device, 'ospfv3IfEntry', [], 'OSPFV3-MIB');
$ospf_port_oids = [ 'ospfIfIpAddress' => 'ospfIfIpAddress', 'ospfAddressLessIf' => 'ospfAddressLessIf', // not really exist
'ospfIfAreaId' => 'ospfv3IfAreaId', 'ospfIfType' => 'ospfv3IfType',
'ospfIfAdminStat' => 'ospfv3IfAdminStatus', 'ospfIfRtrPriority' => 'ospfv3IfRtrPriority',
'ospfIfTransitDelay' => 'ospfv3IfTransitDelay', 'ospfIfRetransInterval' => 'ospfv3IfRetransInterval',
'ospfIfHelloInterval' => 'ospfv3IfHelloInterval', 'ospfIfRtrDeadInterval' => 'ospfv3IfRtrDeadInterval',
'ospfIfState' => 'ospfv3IfState', 'ospfIfDesignatedRouter' => 'ospfv3IfDesignatedRouter',
'ospfIfBackupDesignatedRouter' => 'ospfv3IfBackupDesignatedRouter', 'ospfIfEvents' => 'ospfv3IfEvents',
'ospfIfStatus' => 'ospfv3IfRowStatus', 'ospfIfDemand' => 'ospfv3IfDemand',
/* 'ospfIfPollInterval', 'ospfIfAuthKey', 'ospfIfMulticastForwarding', 'ospfIfAuthType' */ ];
// Build array of existing entries
// V3 always have 2 part index, ie: 6.0
foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` REGEXP ?',
[ $device['device_id'], '^[[:digit:]]+\.[[:digit:]]+$' ]) as $entry) {
$ospf_ports_db[$entry['ospf_port_id']] = $entry;
}
if (OBS_DEBUG) {
echo("\nPolled: ");
print_vars($ospf_ports_poll);
echo('Database: ');
print_vars($ospf_ports_db);
echo("\n");
}
foreach ($ospf_ports_poll as $ospf_port_index => $ospf_port_poll) {
$insert = [];
// Get associated port
list($ospf_ifIndex, $ospf_inst) = explode('.', $ospf_port_index);
$ospf_port_poll['ospfAddressLessIf'] = $ospf_ifIndex;
$ospf_port_poll['ospfIfIpAddress'] = '::';
$insert['port_id'] = 0; // Unknown
if ($ospf_port_poll['ospfAddressLessIf'] &&
$port = get_port_by_index_cache($device, $ospf_port_poll['ospfAddressLessIf'])) {
$insert['port_id'] = $port['port_id'];
// Get IPv6 address when possible
if ($ospf_ip = dbFetchCell('SELECT `ipv6_address` FROM `ipv6_addresses` WHERE `port_id` = ?', [ $port['port_id'] ])) {
$ospf_port_poll['ospfIfIpAddress'] = $ospf_ip;
}
}
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
if (!isset($ospf_ports_db[$ospf_port_index])) {
$insert['device_id'] = $device['device_id'];
$insert['ospf_port_id'] = $ospf_port_index;
foreach ($ospf_port_oids as $field => $oid) {
// Loop the OIDs
$insert[$field] = $ospf_port_poll[$oid];
}
dbInsertRowMulti($insert, 'ospf_ports');
echo('+');
} else {
$ospf_port_db = $ospf_ports_db[$ospf_port_index];
$db_update = FALSE;
$insert['ospf_ports_id'] = $ospf_port_db['ospf_ports_id'];
foreach ($ospf_port_oids as $field => $oid) {
// Loop the OIDs
$insert[$field] = $ospf_port_poll[$oid];
if ($ospf_port_db[$field] != $ospf_port_poll[$oid]) {
$db_update = TRUE;
}
}
if ($db_update) {
dbUpdateRowMulti($insert, 'ospf_ports', 'ospf_ports_id');
echo('U');
} else {
echo('.');
}
unset($ospf_ports_db[$ospf_port_index]);
}
$ospf_stats['ports']++;
unset($insert);
}
// Multi Insert/Update
dbProcessMulti('ospf_ports');
// Clean
$db_delete = [];
foreach ($ospf_ports_db as $ospf_port_db) {
$db_delete[] = $ospf_port_db['ospf_ports_id'];
echo '-';
}
// Multi Delete
if (!safe_empty($db_delete)) {
dbDelete('ospf_ports', generate_query_values_ng($db_delete, 'ospf_ports_id'));
}
unset($ospf_ports_db, $ospf_ports_poll, $db_delete);
echo PHP_EOL;
print_cli_data_field($mib . ' Neighbours', 2);
/*
OSPFV3-MIB::ospfv3NbrAddressType.4.0.1602414725 = INTEGER: ipv6(2)
OSPFV3-MIB::ospfv3NbrAddress.4.0.1602414725 = Hex-STRING: FE 80 00 00 00 00 00 00 0E C4 7A FF FE BC 32 9B
OSPFV3-MIB::ospfv3NbrOptions.4.0.1602414725 = INTEGER: 0
OSPFV3-MIB::ospfv3NbrPriority.4.0.1602414725 = INTEGER: 10
OSPFV3-MIB::ospfv3NbrState.4.0.1602414725 = INTEGER: twoWay(4)
OSPFV3-MIB::ospfv3NbrEvents.4.0.1602414725 = Counter32: 2
OSPFV3-MIB::ospfv3NbrLsRetransQLen.4.0.1602414725 = Gauge32: 0
OSPFV3-MIB::ospfv3NbrHelloSuppressed.4.0.1602414725 = INTEGER: false(2)
OSPFV3-MIB::ospfv3NbrIfId.4.0.1602414725 = INTEGER: 4
*/
$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'ospfv3NbrEntry', [], 'OSPFV3-MIB');
$ospf_nbr_oids = [ 'ospfNbrIpAddr' => 'ospfv3NbrAddress', 'ospfNbrAddressLessIndex' => 'ospfv3NbrIfId',
'ospfNbrRtrId' => 'ospfv3NbrRtrId',
'ospfNbrOptions' => 'ospfv3NbrOptions', 'ospfNbrPriority' => 'ospfv3NbrPriority',
'ospfNbrState' => 'ospfv3NbrState', 'ospfNbrEvents' => 'ospfv3NbrEvents',
'ospfNbrLsRetransQLen' => 'ospfv3NbrLsRetransQLen',
/* 'ospfNbmaNbrStatus', 'ospfNbmaNbrPermanence', */
'ospfNbrHelloSuppressed' => 'ospfv3NbrHelloSuppressed' ];
// Build array of existing entries
// V3 always have 3 part index, ie: .4.0.1602414725
foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` REGEXP ?',
[ $device['device_id'], '^[[:digit:]]+(\.[[:digit:]]+){2}$' ]) as $entry) {
$ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry;
}
if (OBS_DEBUG) {
echo("\nPolled: ");
print_vars($ospf_nbrs_poll);
echo('Database: ');
print_vars($ospf_nbrs_db);
echo("\n");
}
foreach ($ospf_nbrs_poll as $ospf_nbr_index => $ospf_nbr_poll) {
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
$insert = [];
// Get associated port
list($ospf_ifIndex, $ospf_inst, $ospf_rtr) = explode('.', $ospf_nbr_index);
$ospf_nbr_poll['ospfv3NbrRtrId'] = $ospf_rtr;
$ospf_nbr_poll['ospfv3NbrAddress'] = hex2ip($ospf_nbr_poll['ospfv3NbrAddress']);
$insert['port_id'] = NULL; // Unknown
if ($ospf_nbr_poll['ospfv3NbrIfId']) {
if ($port = get_port_by_index_cache($device, $ospf_nbr_poll['ospfv3NbrIfId'])) {
$insert['port_id'] = $port['port_id'];
}
} elseif ($ospf_ifIndex) {
if ($port = get_port_by_index_cache($device, $ospf_ifIndex)) {
$insert['port_id'] = $port['port_id'];
}
} else {
$ids = get_entity_ids_ip_by_network('port', $ospf_nbr_poll['ospfv3NbrAddress'], generate_query_values_and($device['device_id'], 'device_id'));
if (safe_count($ids)) {
$insert['port_id'] = current($ids);
}
}
if (!isset($ospf_nbrs_db[$ospf_nbr_index])) {
$insert['device_id'] = $device['device_id'];
$insert['ospf_nbr_id'] = $ospf_nbr_index;
if (is_null($insert['port_id'])) {
$insert['port_id'] = [ 'NULL' ];
}
foreach ($ospf_nbr_oids as $field => $oid) {
// Loop the OIDs
$insert[$field] = $ospf_nbr_poll[$oid];
}
dbInsertRowMulti($insert, 'ospf_nbrs');
echo('+');
} else {
$ospf_nbr_db = $ospf_nbrs_db[$ospf_nbr_index];
$db_update = FALSE;
$insert['ospf_nbrs_id'] = $ospf_nbr_db['ospf_nbrs_id'];
foreach ($ospf_nbr_oids as $field => $oid) {
// Loop the OIDs
$insert[$field] = $ospf_nbr_poll[$oid];
if ($ospf_nbr_db[$field] != $ospf_nbr_poll[$oid]) {
$db_update = TRUE;
}
}
if ($ospf_nbr_db['port_id'] != $insert['port_id']) {
$db_update = TRUE;
}
if ($db_update) {
if (is_null($insert['port_id'])) {
$insert['port_id'] = [ 'NULL' ];
}
dbUpdateRowMulti($insert, 'ospf_nbrs', 'ospf_nbrs_id');
echo('U');
} else {
echo('.');
}
unset($ospf_nbrs_db[$ospf_nbr_index]);
}
$ospf_stats['neighbours']++;
unset($insert);
}
// Multi Insert/Update
dbProcessMulti('ospf_nbrs');
// Clean
$db_delete = [];
foreach ($ospf_nbrs_db as $ospf_nbr_db) {
$db_delete[] = $ospf_nbr_db['ospf_nbrs_id'];
echo '-';
}
// Multi Delete
if (!safe_empty($db_delete)) {
dbDelete('ospf_nbrs', generate_query_values_ng($db_delete, 'ospf_nbrs_id'));
}
unset($ospf_nbrs_db, $ospf_nbrs_poll, $db_delete);
echo PHP_EOL;
// EOF

View File

@ -0,0 +1,166 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
*
*/
// this is eth100g only, note that fc8gTable, fc16gTable, eth10gTable, eth40gTable, eth400gtable all exist too!
/*
.1.3.6.1.4.1.42229.1.2.4.1.9 - eth100gTable for a single port (1/1/6)
CORIANT-GROOVE-MIB::eth100gEthFecType.1.1.0.6.0 = INTEGER: auto(3)
CORIANT-GROOVE-MIB::eth100gEthFecTypeState.1.1.0.6.0 = INTEGER: disabled(2)
CORIANT-GROOVE-MIB::eth100gTransmitInterpacketgap.1.1.0.6.0 = Gauge32: 8
CORIANT-GROOVE-MIB::eth100gGfpPayloadFcs.1.1.0.6.0 = INTEGER: disabled(2)
CORIANT-GROOVE-MIB::eth100gMappingMode.1.1.0.6.0 = INTEGER: gmp(1)
CORIANT-GROOVE-MIB::eth100gAdminStatus.1.1.0.6.0 = INTEGER: up(1)
CORIANT-GROOVE-MIB::eth100gOperStatus.1.1.0.6.0 = INTEGER: down(2)
CORIANT-GROOVE-MIB::eth100gAvailStatus.1.1.0.6.0 = BITS: 10 00 00 00 lowerLayerDown(3)
CORIANT-GROOVE-MIB::eth100gAliasName.1.1.0.6.0 = STRING: "100gbe-1/1/6"
CORIANT-GROOVE-MIB::eth100gClientShutdown.1.1.0.6.0 = INTEGER: no(2)
CORIANT-GROOVE-MIB::eth100gClientShutdownHoldoffTimer.1.1.0.6.0 = Gauge32: 0
CORIANT-GROOVE-MIB::eth100gNearEndAls.1.1.0.6.0 = INTEGER: no(2)
CORIANT-GROOVE-MIB::eth100gAlsDegradeMode.1.1.0.6.0 = INTEGER: disabled(2)
CORIANT-GROOVE-MIB::eth100gLoopbackEnable.1.1.0.6.0 = INTEGER: disabled(2)
CORIANT-GROOVE-MIB::eth100gLoopbackType.1.1.0.6.0 = INTEGER: none(0)
CORIANT-GROOVE-MIB::eth100gTestSignalType.1.1.0.6.0 = INTEGER: none(0)
CORIANT-GROOVE-MIB::eth100gTestSignalEnable.1.1.0.6.0 = INTEGER: none(0)
CORIANT-GROOVE-MIB::eth100gServiceLabel.1.1.0.6.0 = ""
CORIANT-GROOVE-MIB::eth100gLldpStatusIf.1.1.0.6.0 = INTEGER: disabled(4)
CORIANT-GROOVE-MIB::eth100gHoldoffSignal.1.1.0.6.0 = INTEGER: no(2)
CORIANT-GROOVE-MIB::eth100gManagedBy.1.1.0.6.0 = INTEGER: system(1)
.1.3.6.1.4.1.42229.1.2.4.1.9 - eth100gStatisticsTable for a single port (1/1/6)
CORIANT-GROOVE-MIB::eth100gStatisticsEntryLastClear.1.1.0.6.0 = STRING: "0000-01-01T00:00:00.000Z"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryLossOfSignalSeconds.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryBitErrorFec.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryUncorrectedBlockErrorFec.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInSymbolErrors.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInDropEvents.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInOctets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInBroadcastPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInMulticastPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInCrcAlignErrors.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInUndersizePackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInOversizePackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInFragments.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInJabbers.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets64octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets65to127octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets128to255octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets256to511octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets512to1023octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryInPackets1024to1518octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutSymbolErrors.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutDropEvents.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutOctets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutBroadcastPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutMulticastPackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutCrcAlignErrors.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutUndersizePackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutOversizePackets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutFragments.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutJabbers.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets64octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets65to127octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets128to255octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets256to511octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets512to1023octets.1.1.0.6.0 = STRING: "0"
CORIANT-GROOVE-MIB::eth100gStatisticsEntryOutPackets1024to1518octets.1.1.0.6.0 = STRING: "0"
*/
$mib = 'CORIANT-GROOVE-MIB';
// eth100gTable
$entries = [];
$entries = snmpwalk_cache_oid($device, 'eth100gTable', $entries, $mib);
$entries = snmpwalk_cache_oid($device, 'eth100gStatisticsTable', $entries, $mib);
print_debug_vars($entries);
foreach ($entries as $port_oid_suffix => $port) {
$ifIndex = $port_oid_suffix;
$entry = isset($entries[$ifIndex]) ? $entries[$ifIndex] : [];
// basics
$port_stats[$ifIndex]['ifDescr'] = $entry['eth100gAliasName'];
$port_stats[$ifIndex]['ifName'] = $entry['eth100gAliasName'];
$port_stats[$ifIndex]['ifAlias'] = $entry['eth100gServiceLabel'];
$port_stats[$ifIndex]['ifOperStatus'] = $entry['eth100gOperStatus'];
$port_stats[$ifIndex]['ifAdminStatus'] = $entry['eth100gAdminStatus'];
$port_stats[$ifIndex]['ifType'] = 'ethernetCsmacd'; // can we do better than hard coding?
// stats
$port_stats[$ifIndex]['ifInOctets'] = $entry['eth100gStatisticsEntryInOctets'];
$port_stats[$ifIndex]['ifOutOctets'] = $entry['eth100gStatisticsEntryOutOctets'];
$port_stats[$ifIndex]['ifInUcastPkts'] = $entry['eth100gStatisticsEntryInPackets'];
$port_stats[$ifIndex]['ifOutUcastPkts'] = $entry['eth100gStatisticsEntryOutPackets'];
$port_stats[$ifIndex]['ifInBroadcastPkts'] = $entry['eth100gStatisticsEntryInBroadcastPackets'];
$port_stats[$ifIndex]['ifOutBroadcastPkts'] = $entry['eth100gStatisticsEntryOutBroadcastPackets'];
$port_stats[$ifIndex]['ifInMulticastPkts'] = $entry['eth100gStatisticsEntryInMulticastPackets'];
$port_stats[$ifIndex]['ifOutMulticastPkts'] = $entry['eth100gStatisticsEntryOutMulticastPackets'];
$port_stats[$ifIndex]['ifInDiscards'] = $entry['eth100gStatisticsEntryInDropEvents'];
$port_stats[$ifIndex]['ifOutDiscards'] = $entry['eth100gStatisticsEntryOutDropEvents'];
$port_stats[$ifIndex]['ifInErrors'] = $entry['eth100gStatisticsEntryInCrcAlignErrors'];
$port_stats[$ifIndex]['ifOutErrors'] = $entry['eth100gStatisticsEntryOutCrcAlignErrors'];
}
// eth400gTable
$entries = [];
$entries = snmpwalk_cache_oid($device, 'eth400gTable', $entries, $mib);
$entries = snmpwalk_cache_oid($device, 'eth400gStatisticsTable', $entries, $mib);
print_debug_vars($entries);
foreach ($entries as $port_oid_suffix => $port) {
$ifIndex = $port_oid_suffix;
$entry = isset($entries[$ifIndex]) ? $entries[$ifIndex] : [];
// basics
$port_stats[$ifIndex]['ifDescr'] = $entry['eth400gAliasName'];
$port_stats[$ifIndex]['ifName'] = $entry['eth400gAliasName'];
$port_stats[$ifIndex]['ifAlias'] = $entry['eth400gServiceLabel'];
$port_stats[$ifIndex]['ifOperStatus'] = $entry['eth400gOperStatus'];
$port_stats[$ifIndex]['ifAdminStatus'] = $entry['eth400gAdminStatus'];
$port_stats[$ifIndex]['ifType'] = 'ethernetCsmacd'; // can we do better than hard coding?
// stats
$port_stats[$ifIndex]['ifInOctets'] = $entry['eth400gStatisticsEntryInOctets'];
$port_stats[$ifIndex]['ifOutOctets'] = $entry['eth400gStatisticsEntryOutOctets'];
$port_stats[$ifIndex]['ifInUcastPkts'] = $entry['eth400gStatisticsEntryInPackets'];
$port_stats[$ifIndex]['ifOutUcastPkts'] = $entry['eth400gStatisticsEntryOutPackets'];
$port_stats[$ifIndex]['ifInBroadcastPkts'] = $entry['eth400gStatisticsEntryInBroadcastPackets'];
$port_stats[$ifIndex]['ifOutBroadcastPkts'] = $entry['eth400gStatisticsEntryOutBroadcastPackets'];
$port_stats[$ifIndex]['ifInMulticastPkts'] = $entry['eth400gStatisticsEntryInMulticastPackets'];
$port_stats[$ifIndex]['ifOutMulticastPkts'] = $entry['eth400gStatisticsEntryOutMulticastPackets'];
$port_stats[$ifIndex]['ifInDiscards'] = $entry['eth400gStatisticsEntryInDropEvents'];
$port_stats[$ifIndex]['ifOutDiscards'] = $entry['eth400gStatisticsEntryOutDropEvents'];
$port_stats[$ifIndex]['ifInErrors'] = $entry['eth400gStatisticsEntryInCrcAlignErrors'];
$port_stats[$ifIndex]['ifOutErrors'] = $entry['eth400gStatisticsEntryOutCrcAlignErrors'];
}
// EOF

View File

@ -6,14 +6,14 @@
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
global $graphs;
$query = 'SELECT DISTINCT `sensor_class` FROM `sensors` WHERE `device_id` = ? AND `sensor_deleted` = ?';
$query .= generate_query_values(array_keys($config['sensor_types']), 'sensor_class'); // Limit by known classes
$query .= generate_query_values_and(array_keys($config['sensor_types']), 'sensor_class'); // Limit by known classes
$sensor_classes = dbFetchColumn($query, array($device['device_id'], '0'));
//$count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `sensor_deleted` = ?;', array($device['device_id'], '0'));

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