initial commit; version 22.5.12042

This commit is contained in:
2022-12-12 23:28:25 -05:00
commit af1b03d79f
17653 changed files with 22692970 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage alerting
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2015 Observium Limited
*
*/
/*
* This lies and says it did something. It did not. Used to prevent default.
*/
$notify_status['success'] = TRUE;
// EOF

View File

@ -0,0 +1,94 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage alerting
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
*
*/
// FIXME: This is fairly messy and crude. Feel free to improve it!
// Slack only params
switch($message_tags['ALERT_STATE'])
{
case "RECOVER":
$color = "2850816";
break;
case "SYSLOG":
$color = "8410368";
break;
default:
$color = "8388651";
}
$emoji = ':' . $message_tags['ALERT_EMOJI_NAME'] . ':';
// JSON data
$data = [
// "username" => $endpoint['username'],
// 'icon_emoji' => $emoji,
//"text" => $title,
];
if (isset($endpoint['short']) && $endpoint['short'] === 'true')
{
// Short format
$data['embeds'][] = [
'title' => $message_tags['TITLE'],
'url' => $message_tags['ALERT_URL'],
'color' => $color
];
} else {
$data['embeds'][] = [
'title' => $emoji.' '.$message_tags['TITLE'],
'url' => $message_tags['ALERT_URL'],
'color' => $color,
//'text' => simple_template('slack_text.tpl', $message_tags, array('is_file' => TRUE)),
'fields' => [
[
'name' => 'Device/Location',
'value' => $message_tags['DEVICE_HOSTNAME'] . " (" . $message_tags['DEVICE_OS'] . ")" . PHP_EOL . $message_tags['DEVICE_LOCATION'],
'inline' => TRUE,
],
[
'name' => 'Entity',
'url' => $message_tags['ENTITY_URL'],
'value' => $message_tags['ENTITY_TYPE'] . " / " . $message_tags['ENTITY_NAME'] .
(isset($message_tags['ENTITY_DESCRIPTION']) ? PHP_EOL . $message_tags['ENTITY_DESCRIPTION'] : ''),
'inline' => TRUE,
],
[
'name' => 'Alert Message/Duration',
'value' => $message_tags['ALERT_MESSAGE'] . PHP_EOL . $message_tags['DURATION'],
//'inline' => TRUE,
],
[
'name' => 'Metrics',
'value' => str_replace(" ", "", $message_tags['METRICS']),
//'inline' => TRUE,
],
],
];
/*
foreach ($graphs as $graph)
{
$data['attachments'][] = array('fallback' => "Graph Image",
'title' => $graph['label'],
'image_url' => $graph['url'],
'color' => 'danger');
}
*/
}
// EOF

View File

@ -0,0 +1,205 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage alerting
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
// Find local hostname
$localhost = get_localhost();
$emails = [];
$mail_params = [];
$emails[$endpoint['email']] = $endpoint['contact_descr'];
// Mail backend params
$backend = strtolower(trim($config['email']['backend']));
switch ($backend)
{
case 'sendmail':
$mail_params['sendmail_path'] = $config['email']['sendmail_path'];
break;
case 'smtp':
$mail_params['host'] = $config['email']['smtp_host'];
$mail_params['port'] = $config['email']['smtp_port'];
if ($config['email']['smtp_secure'] === 'ssl')
{
$mail_params['host'] = 'ssl://'.$config['email']['smtp_host'];
if ($config['email']['smtp_port'] == 25)
{
$mail_params['port'] = 465; // Default port for SSL
}
}
$mail_params['timeout'] = $config['email']['smtp_timeout'];
$mail_params['auth'] = $config['email']['smtp_auth'];
$mail_params['username'] = $config['email']['smtp_username'];
$mail_params['password'] = $config['email']['smtp_password'];
$mail_params['localhost'] = $localhost;
if (OBS_DEBUG) { $mail_params['debug'] = TRUE; }
break;
case 'smtpmx':
case 'mx':
$mail_params['mailname'] = $localhost;
$mail_params['netdns'] = FALSE;
$mail_params['timeout'] = $config['email']['smtp_timeout'];
if (OBS_DEBUG) { $mail_params['debug'] = TRUE; }
$backend = 'smtpmx';
break;
case 'mail':
default:
$backend = 'mail'; // Default mailer backend
}
// Time sent RFC 2822
$time_rfc = date('r', time());
// Mail headers
$headers = array();
if (empty($config['email']['from']))
{
// Default "From:"
$headers['From'] = 'Observium <observium@'.$localhost.'>';
$headers['Return-Path'] = 'observium@'.$localhost;
} else {
// Validate configured mail from
foreach (parse_email($config['email']['from']) as $from => $from_name)
{
$headers['From'] = (empty($from_name) ? $from : '"' . $from_name . '" <' . $from . '>'); // From:
$headers['Return-Path'] = $from;
break; // use only first entry
}
}
$rcpts = array();
$rcpts_full = array();
foreach ($emails as $to => $to_name)
{
$rcpts_full[] = (empty($to_name) ? $to : '"'.trim($to_name).'" <'.$to.'>');
$rcpts[] = $to;
}
$rcpts_full = implode(', ', $rcpts_full);
$rcpts = implode(', ', $rcpts);
$headers['To'] = $rcpts_full; // To:
$headers['Subject'] = $message_tags['TITLE']; // Subject:
// ID and Date, leave it before X- headers
$headers['Message-ID'] = '<' . md5(uniqid(time())) . '@' . $localhost . '>';
$headers['Date'] = $time_rfc;
$headers['X-Priority'] = 3; // Mail priority
$headers['X-Mailer'] = OBSERVIUM_PRODUCT.' '.OBSERVIUM_VERSION; // X-Mailer:
// Mail autogenerated, suppress autorespond by any issue system
$headers['Precedence'] = 'bulk';
$headers['Auto-submitted'] = 'auto-generated';
$headers['X-Auto-Response-Suppress'] = 'All';
$time_sent = $time_rfc;
// Creating the Mime message
$mime = new Mail_mime(array('head_charset' => 'utf-8',
'text_charset' => 'utf-8',
'html_charset' => 'utf-8',
'eol' => PHP_EOL));
// Generate Mail text in both plain text and html
$message['text'] = simple_template('email_text', $message_tags, array('is_file' => TRUE));
$message_tags_html = $message_tags;
$message_tags_html['CONDITIONS'] = nl2br(escape_html($message_tags['CONDITIONS']));
$message_tags_html['METRICS'] = nl2br(escape_html($message_tags['METRICS']));
// Generate image attach
//$graphs = json_decode($message_tags_html['ENTITY_GRAPHS_ARRAY'], TRUE);
$graphs = $message_tags_html['ENTITY_GRAPHS_ARRAY'];
if (is_array($graphs) && count($graphs))
{
$message_tags_html['ENTITY_GRAPHS'] = ''; // Reinit graphs html
foreach ($graphs as $key => $graph)
{
$cid = generate_random_string(16);
// Unencode data uri tag to file content
list($gmime, $base64) = explode(';', $graph['data'], 2);
$gmime = substr($gmime, 5);
$base64 = substr($base64, 7);
//print_vars(substr($graph['data'], 0, 20));
//print_vars($gmime);
//print_vars(substr($base64, 0, 20));
$mime->addHTMLImage(base64_decode($base64), $gmime, $cid.'.png', FALSE, $cid);
$message_tags_html['ENTITY_GRAPHS'] .= '<h4>'.$graph['type'].'</h4>';
$message_tags_html['ENTITY_GRAPHS'] .= '<a href="'.$graph['url'].'"><img src="cid:'.$cid.'"></a><br />';
}
}
//print_vars($message_tags_html);
$message['html'] = simple_template('email_html', $message_tags_html, array('is_file' => TRUE));
unset($message_tags_html);
foreach ($message as $part => $part_body)
{
switch ($part)
{
case 'text':
case 'txt':
case 'plain':
$part_body .= "\n\nE-mail sent to: $rcpts\n";
$part_body .= "E-mail sent at: $time_sent\n\n";
$part_body .= "-- \n" . OBSERVIUM_PRODUCT_LONG . ' ' . OBSERVIUM_VERSION . "\n" . OBSERVIUM_URL . "\n";
$mime->setTXTBody($part_body);
break;
case 'html':
$part_footer = "\n<br /><p style=\"font-size: 11px;\">E-mail sent to: $rcpts<br />\n";
$part_footer .= "E-mail sent at: $time_sent</p>\n";
$part_footer .= '<div style="font-size: 11px; color: #999;">-- <br /><a href="'.OBSERVIUM_URL.'">'.OBSERVIUM_PRODUCT_LONG.' '.OBSERVIUM_VERSION."</a></div>\n";
if (stripos($part_body, '</body>'))
{
$part_body = str_ireplace('</body>', $part_footer.'</body>', $part_body);
} else {
$part_body .= $part_footer;
}
$mime->setHTMLBody($part_body);
break;
//case 'image':
// break;
//case 'attachment':
// break;
}
}
$body = $mime->get();
// Prepare headers
foreach ($headers as $name => $value) {
$headers[$name] = $mime->encodeHeader($name, $value, 'utf-8', 'quoted-printable');
}
$headers = $mime->headers($headers);
//var_dump($headers);
// Create mailer instance
$mail = Mail::factory($backend, $mail_params);
// Sending email
$status = $mail->send($rcpts, $headers, $body);
if (PEAR::isError($status)) {
//print_message('%rMailer Error%n: ' . $status->getMessage(), 'color');
$notify_status['success'] = FALSE;
$notify_status['error'] = $status->getMessage();
} else {
$notify_status['success'] = TRUE;
}
unset($message);
// EOF

View File

@ -0,0 +1,39 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage alerting
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// Export all tags for external program usage
foreach (array_keys($message_tags) as $key)
{
putenv("OBSERVIUM_$key=" . $message_tags[$key]);
}
// Execute given script
external_exec($endpoint['script']);
// If script's exit code is 0, success. Otherwise we mark it as failed.
if ($GLOBALS['exec_status']['exitcode'] == 0)
{
$notify_status['success'] = TRUE;
} else {
$notify_status['success'] = FALSE;
}
// Clean out all set environment variable we set before execution
foreach (array_keys($message_tags) as $key)
{
putenv("OBSERVIUM_$key");
}
unset($message, $output, $exitcode);
// EOF

View File

@ -0,0 +1,93 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage alerting
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$message = $message_tags['TITLE'] . ' [' . $message_tags['ALERT_URL'] . ']' . PHP_EOL;
$message .= str_replace(" ", "", $message_tags['METRICS']);
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Client;
use Fabiang\Xmpp\Protocol\Message;
if (isset($endpoint['server']))
{
// Set server hostname if specified by user
$hostname = $endpoint['server'];
} else {
// Find server by SRV record, if we have an @ in our login username
if (strstr($endpoint['username'], '@') !== FALSE)
{
list(,$xmppdomain) = explode('@', $endpoint['username'], 2);
$resolver = new Net_DNS2_Resolver();
$maxprio = -1;
// Find and use highest priority server only. Could be improved to cycle if there are multiple?
try
{
$response = $resolver->query("_xmpp-client._tcp.$xmppdomain", 'SRV', 'IN');
if ($response)
{
foreach ($response->answer as $answer)
{
if ($answer->priority > $maxprio)
{
$hostname = $answer->target;
}
}
}
} catch (Exception $e) { print_debug("Error while resolving: " . $e->getMessage()); } // Continue when error resolving
}
}
if ($hostname != '')
{
// Default to port to 5222 unless specified by endpoint data
$port = ($endpoint['port'] ? $endpoint['port'] : 5222);
list($username,$xmppdomain) = explode('@',$endpoint['username']); // Username is only the part before @
$password = $endpoint['password'];
$options = new Options("tcp://$hostname:$port");
$options->setUsername($username);
$options->setPassword($password);
list($rusername,$rxmppdomain ) = explode('@',$endpoint['recipient']);
if ($rxmppdomain != '') { $options->setTo($rxmppdomain); } // Set destination domain to the recipient's part after the @
$client = new Client($options);
try
{
$client->connect();
$xmessage = new Message;
$xmessage->setMessage($message);
$xmessage->setTo($endpoint['recipient']);
$client->send($xmessage);
$client->disconnect();
$notify_status['success'] = TRUE;
} catch (Exception $e) {
// reason: $e->getMessage()
$notify_status['success'] = FALSE;
}
} else {
// reason: Could not determine server hostname!
$notify_status['success'] = FALSE;
}
unset($message);
// EOF

3475
includes/alerts.inc.php Normal file

File diff suppressed because it is too large Load Diff

660
includes/cache.inc.php Normal file
View File

@ -0,0 +1,660 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage cache
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Please see phpFastCache documentation and examples here:
// https://github.com/PHPSocialNetwork/phpfastcache/wiki
// https://github.com/PHPSocialNetwork/phpfastcache/tree/final/examples
// NOTES. phpfastcache 6.x supports php 5.6 - 7.2
// phpfastcache 8.x supports php 7.3 - 8.x
if (PHP_VERSION_ID < 50600) {
// Disable phpFastCache for PHP less than 5.6, since it unsupported
$config['cache']['enable'] = FALSE;
}
/**
* Cache functions.
* Leave it before initialize phpFastCache, since here used check for php version.
*/
/**
* Prepend cache key with username/level
*
* @param string $key Identificator name
* @param boolean $global Set to TRUE for do not prepend keys
* @return string Prepended key identificator (ie 'data' -> 'mysql|user|10|data')
*/
function get_cache_key($key, $global = FALSE) {
// https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%CB%96%5D-Unsupported-characters-in-key-identifiers
$key = str_replace([ '{', '}', '(', ')', '/', '\\', '@', ':' ], '_', $key);
if ($global || is_cli()) { return $key; } // CLI used global key
if ($_SESSION['authenticated']) {
if ($_SESSION['userlevel'] >= 10) {
// Use common cache for Global Administrators
$key = '__admin|' . $key;
} else {
// All other users use unique keys!
$user_key = str_replace([ '{', '}', '(', ')', '/', '\\', '@', ':' ], '_', $_SESSION['username']);
$key = $_SESSION['auth_mechanism'] . '|' . $user_key . '|' . $_SESSION['userlevel'] . '|' . $key;
}
} else {
// Just "protect" anonymous requests from read/write to global cache
$key = '__anonymous|' . $key;
}
return $key;
}
/**
* Call to getItem() method for retrieve an Item for cached object
*
* @param string $key Item identifier (key), for WUI key auto prepended with current user identificator (by get_cache_key())
* @return object|void Object with cache Item
*/
function get_cache_item($key) {
if (defined('OBS_CACHE_LINK') &&
$GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK]) {
$observium_cache = $GLOBALS[OBS_CACHE_LINK];
} else {
// Cache not enabled
return;
}
$observium_cache_key = get_cache_key($key); // User specific key
try {
$item = $observium_cache->getItem($observium_cache_key);
} catch(\phpFastCache\Exceptions\phpFastCacheInvalidArgumentException $e) {
$observium_cache->clear();
if (OBS_DEBUG || OBS_CACHE_DEBUG) {
print_warning('<span class="text-warning">CLEAR BROKEN CACHE</span>');
}
logfile('debug.log', 'CLEAR BROKEN CACHE.');
return;
}
return $item;
}
/**
* Call to isHit() method for check if your cache Item exists and is still valid
*
* @param object $item Cache Item object
* @return bool TRUE if cache exist and not expired
*/
function ishit_cache_item($item) {
if (!(defined('OBS_CACHE_LINK') &&
$GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK])) {
// Cache not enabled
return;
}
return $item->isHit();
}
/**
* Call to get() method for retrieve cache data for used Item
*
* @param object $item Cache Item object
* @return mixed Cached data
*/
function get_cache_data($item) {
if (!(defined('OBS_CACHE_LINK') &&
$GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK])) {
// Cache not enabled
return;
}
$start = microtime(TRUE);
$data = $item->get();
$cache_time = microtime(TRUE) - $start;
if (OBS_DEBUG || OBS_CACHE_DEBUG) {
print_warning('<span class="text-success">READ FROM CACHE</span> // TTL: '.$item->getTtl().'s // Expiration: <strong>' . $item->getExpirationDate()->format(Datetime::RFC2822) . '</strong><br />' .
'Key: <strong>' . $item->getKey() . '</strong> // Tags: <strong>' . $item->getTagsAsString() . '</strong><br />' .
'Driver: <strong>'.str_ireplace(array('phpFastCache\\Drivers\\', '\\Item'), '', get_class($item)).'</strong> // Read time: ' . sprintf("%.7f", $cache_time) . ' ms');
//print_vars($item->getTags());
//print_vars($data);
}
return $data;
}
/**
* Call to set() and save() methods for store data in cache
*
* @param object $item Cache Item object
* @param mixed $data Data for store in cache
* @param array $params Additional options for cache entry
* @return int Unix timestamp when cache item will expired
*/
function set_cache_item($item, $data, $params = array()) {
if (defined('OBS_CACHE_LINK') &&
$GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK])
{
$observium_cache = $GLOBALS[OBS_CACHE_LINK];
} else {
// Cache not enabled
return;
}
// Item tags (for search/cleanup cache later)
if (is_cli()) {
$tags = array('__cli');
} else {
$tags = array('__wui');
if ($_SESSION['authenticated']) {
if ($_SESSION['userlevel'] >= 10) {
$tags[] = '__admin';
} else {
$tags[] = '__username=' . str_replace([ '{', '}', '(', ')', '/', '\\', '@', ':' ], '_', $_SESSION['username']);
}
} else {
$tags[] = '__anonymous';
}
}
if (isset($params['tags'])) {
foreach ((array)$params['tags'] as $tag) {
$tags[] = str_replace([ '{', '}', '(', ')', '/', '\\', '@', ':' ], '_', $tag);
}
}
// TTL for cache entry in seconds
if (isset($params['ttl']) && is_numeric($params['ttl'])) {
$ttl = (int)$params['ttl'];
} elseif (is_numeric($GLOBALS['config']['cache']['ttl'])) {
$ttl = (int)$GLOBALS['config']['cache']['ttl'];
} else {
// Default TTL (5 min)
$ttl = 300;
}
$start = microtime(TRUE);
// Add data to cache
$item->set($data);
// Set expiration TTL
$item->expiresAfter($ttl);
// Add tags
$item->addTags($tags);
// Commit
try {
$observium_cache->save($item);
} catch(\Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException $e) {
$observium_cache->clear();
}
$cache_time = microtime(TRUE) - $start;
if (OBS_DEBUG || OBS_CACHE_DEBUG) {
//print_vars($save);
//print_vars($observium_cache->hasItem($item->getKey()));
print_warning('<span class="text-info">WROTE TO CACHE</span> // TTL: '.$item->getTtl().'s // Expiration: <strong>' . $item->getExpirationDate()->format(Datetime::RFC2822) . '</strong><br />' .
'Key: <strong>' . $item->getKey() . '</strong> // Tags: <strong>' . $item->getTagsAsString() . '</strong><br />' .
'Driver: <strong>'.str_ireplace(array('phpFastCache\\Drivers\\', '\\Item'), '', get_class($item)).'</strong> // Write time: ' . sprintf("%.7f", $cache_time) . ' ms');
//print_vars($item->getTags());
}
return $item->getExpirationDate()->getTimestamp();
}
/**
* Get cache Items by single tag
*
* @param string $tag Tag name for Get Items
*/
function get_cache_items($tag) {
if (defined('OBS_CACHE_LINK') &&
$GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK]) {
$observium_cache = $GLOBALS[OBS_CACHE_LINK];
} else {
// Cache not enabled
return;
}
return $observium_cache->getItemsByTag($tag);
}
/**
* Delete cache Items by tags.
* See session_logout() for example.
*
* @param array $tags Array of tags for deletion
*/
function del_cache_items($tags) {
if (defined('OBS_CACHE_LINK') &&
$GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK]) {
$observium_cache = $GLOBALS[OBS_CACHE_LINK];
} else {
// Cache not enabled
return;
}
return $observium_cache->deleteItemsByTags($tags);
}
/**
* Delete expired Items.
* Used "workaround" as described here:
* https://github.com/PHPSocialNetwork/phpfastcache/issues/413#issuecomment-270692658
*
* @param array $tag Array of tags for clear
* @return int|void Unixtime when last expired cache cleared
*/
function del_cache_expired($tag = '') {
if (defined('OBS_CACHE_LINK') &&
$GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK]) {
$observium_cache = $GLOBALS[OBS_CACHE_LINK];
} else {
// Cache not enabled
return;
}
try {
$item = $observium_cache->getItem('__cache_last_clear_expired');
} catch(\phpFastCache\Exceptions\phpFastCacheInvalidArgumentException $e) {
$observium_cache->clear();
if (OBS_DEBUG || OBS_CACHE_DEBUG) {
print_warning('<span class="text-warning">CLEAR BROKEN CACHE</span>');
}
logfile('debug.log', 'CLEAR BROKEN CACHE.');
return;
}
if (!$item->isHit()) {
// Here our default tags, see set_cache_item()
if (empty($tag)) {
if (is_cli()) {
$tag = '__cli';
} else {
$tag = '__wui';
}
}
// Touch items for clear expired
get_cache_items($tag);
$clear_expired = time();
// Store last clean time for 24 hours
$item->set($clear_expired)->expiresAfter(86400);
// Commit
$observium_cache->save($item);
if (OBS_DEBUG || OBS_CACHE_DEBUG) {
print_warning('<span class="text-success">CLEAR EXPIRED CACHE</span> // Time: <strong>' . format_unixtime($clear_expired) . '</strong>');
}
} else {
$clear_expired = $item->get();
if (OBS_DEBUG || OBS_CACHE_DEBUG) {
print_warning('<span class="text-info">LAST CLEAR CACHE TIME</span> // Time: <strong>' . format_unixtime($clear_expired) . '</strong>');
}
}
return $clear_expired;
}
/**
* Add clear cache attrib, this will request for clearing cache in next request.
*
* @param string $target Clear cache target: wui or cli (default if wui)
*/
/*
function set_cache_clear($target = 'wui')
{
if (OBS_DEBUG || OBS_CACHE_DEBUG)
{
print_error('<span class="text-warning">CACHE CLEAR SET.</span> Cache clear set.');
}
if (!$GLOBALS['config']['cache']['enable'])
{
// Cache not enabled
return;
}
switch (strtolower($target))
{
case 'cli':
// Add clear CLI cache attrib. Currently not used
set_obs_attrib('cache_cli_clear', get_request_id());
break;
default:
// Add clear WUI cache attrib
set_obs_attrib('cache_wui_clear', get_request_id());
}
}
*/
function get_cache_session($key) {
// Check if fast cache used
$fast_cache = defined('OBS_CACHE_LINK') && $GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK];
if ($fast_cache) {
$cache_item = get_cache_item($key);
//print_vars($cache_item->isHit());
$GLOBALS['cache_ishit'] = ishit_cache_item($cache_item);
if ($GLOBALS['cache_ishit']) {
return get_cache_data($cache_item);
}
} else {
// Fallback to session caching
//r($_COOKIE);
//r($_SESSION);
$GLOBALS['cache_ishit'] = isset($_SESSION['cache_session']) && array_key_exists($key, $_SESSION['cache_session']);
//r($GLOBALS['cache_ishit']);
if ($GLOBALS['cache_ishit']) {
// Check cache entry timeout $config['cache']['ttl']
$tdiff = time() - $_SESSION['cache_session_time'][$key];
if ($tdiff > $GLOBALS['config']['cache']['ttl']) {
// Too old cache entry, clear
unset($GLOBALS['cache_ishit']);
session_unset_var('cache_session->'.$key);
session_unset_var('cache_session_time->'.$key);
return NULL;
}
return $_SESSION['cache_session'][$key];
}
}
return NULL;
}
function set_cache_session($key, $data) {
// Check if fast cache used
$fast_cache = defined('OBS_CACHE_LINK') && $GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK];
if ($fast_cache) {
$cache_item = get_cache_item($key);
// Store $cache in fast caching
set_cache_item($cache_item, $data);
// Clear expired cache
del_cache_expired();
} else {
// Fallback to session caching
session_set_var('cache_session->'.$key, $data);
session_set_var('cache_session_time->'.$key, time());
//r($data);
//$_SESSION['cache_session'][$key] = $data;
}
// Clear hit cache if exist
if (isset($GLOBALS['cache_ishit'])) {
unset($GLOBALS['cache_ishit']);
}
}
function ishit_cache_session() {
if (isset($GLOBALS['cache_ishit'])) {
$return = $GLOBALS['cache_ishit'];
// Clear hit cache if exist
unset($GLOBALS['cache_ishit']);
} else {
$return = FALSE;
}
return $return;
}
/**
* Return total cache size in bytes.
* Note, this is not user/session specific size, but total for cache system
*
* @return array Total cache size in bytes
*/
function get_cache_stats() {
if (defined('OBS_CACHE_LINK') &&
$GLOBALS[OBS_CACHE_LINK] === (object)$GLOBALS[OBS_CACHE_LINK]) {
$observium_cache = $GLOBALS[OBS_CACHE_LINK];
} else {
// Cache not enabled
return [ 'enabled' => FALSE, 'size' => 0 ];
}
try {
//$_s = $observium_cache->getStats();
$size = $observium_cache->getStats()->getSize();
} catch (Exception $e) {
$size = 0;
}
//r($_s->getInfo());
return [
'enabled' => TRUE,
'driver' => str_ireplace(array('phpFastCache\\Drivers\\', '\\Driver'), '', get_class($observium_cache)),
'size' => $size,
];
}
/////////////////////////////////////////////////////////
// NO FUNCTION DEFINITIONS FOR CACHE AFTER THIS LINE! //
/////////////////////////////////////////////////////////
// YES, THAT MEANS YOU //
/////////////////////////////////////////////////////////
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 (OBS_CACHE_DEBUG || (defined('OBS_DEBUG') && OBS_DEBUG)) {
print_cli('%RCACHE DISABLED.%n Disabled in config.');
}
return;
}
// Syslog have different dir permissions
$cache_key = OBS_PROCESS_NAME === 'syslog' ? 'syslog' : 'cli';
} else {
$cache_key = 'wui'; // do not use $_SERVER['hostname'] as key
}
/**
* Temporary hardcoded caching in files, will improve later with other providers
*/
const OBS_CACHE_LINK = 'observium_cache'; // Variable name for call to cache class
// Call the phpFastCache
use phpFastCache\CacheManager;
//use Phpfastcache\Config\ConfigurationOption;
/* Setup File Path and other basic options
$cache_config = [
'path' => $config['cache_dir'],
//'securityKey' => is_cli() ? 'cli' : 'wui', // do not use $_SERVER['hostname'] as key
//'ignoreSymfonyNotice' => TRUE,
];
$cache_key = is_cli() ? 'cli' : 'wui'; // do not use $_SERVER['hostname'] as key
if (PHP_VERSION_ID >= 70300) {
CacheManager::setDefaultConfig(new \Phpfastcache\Config\ConfigurationOption($cache_config));
} else {
$cache_config['securityKey'] = $cache_key;
CacheManager::setDefaultConfig($cache_config);
}
*/
$cache_driver = 'files'; // If other drivers not detected, use files as fallback
if (str_istarts($config['cache']['driver'], 'auto')) {
// Detect avialable drivers,
// NOTE order from fastest to slowest!
//$detect_driver = array('zendshm', 'apcu', 'xcache', 'sqlite', 'files');
$detect_driver = array('zendshm', 'apcu', 'sqlite', 'files');
} else {
$detect_driver = array(strtolower($config['cache']['driver']));
}
// Basic detect if extension/driver available
$cache_driver = 'files';
foreach ($detect_driver as $entry) {
switch($entry) {
case 'zendshm':
if (extension_loaded('Zend Data Cache') && function_exists('zend_shm_cache_store')) {
$cache_driver = 'zendshm';
break 2;
}
break;
case '!memcached':
// Also need connection test
try {
$mc = new Memcached();
} catch (Exception $e) {}
if (class_exists('Memcached')) {
$cache_driver = 'memcached';
break 2;
}
break;
case 'apcu':
if (extension_loaded('apcu') && !is_cli() && ini_get('apc.enabled')) {
// NOTE. APCu unusable in CLI
$cache_driver = 'apcu';
break 2;
}
break;
/* XCache RIP
case 'xcache':
if (extension_loaded('xcache') && function_exists('xcache_get'))
{
$cache_driver = 'xcache';
break 2;
}
break;
*/
case 'sqlite':
if (extension_loaded('pdo_sqlite')) {
$cache_driver = 'sqlite';
break 2;
}
break;
case 'files':
default:
//$cache_driver = 'files';
break;
}
}
switch($cache_driver) {
case 'sqlite':
// Create base cache dir if not exist
if (!is_dir($config['cache_dir'])) {
mkdir($config['cache_dir'], 0777, TRUE);
chmod($config['cache_dir'], 0777);
}
// Setup File Path and other basic options
if (PHP_VERSION_ID >= 70300) {
// https://github.com/PHPSocialNetwork/phpfastcache/issues/676
$cache_config = new \Phpfastcache\Drivers\Sqlite\Config();
$cache_config->setpath($config['cache_dir']);
$cache_config->setSecurityKey($cache_key);
CacheManager::setDefaultConfig($cache_config);
//print_vars($cache_config);
} else {
$cache_config = [
'path' => $config['cache_dir'],
'securityKey' => $cache_key,
];
CacheManager::setDefaultConfig($cache_config);
}
// Do not break here!
case 'zendshm':
case 'memcached':
case 'apcu':
//case 'xcache':
try {
$GLOBALS[OBS_CACHE_LINK] = CacheManager::getInstance($cache_driver);
} catch (Exception $e) {
print_debug('Cache driver '.ucfirst($cache_driver).' not functional. Caching disabled!');
//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());
$GLOBALS[OBS_CACHE_LINK] = CacheManager::getInstance('Devnull'); // disable caching
}
break;
case 'files':
default:
// Create base cache dir if not exist
if (!is_dir($config['cache_dir'])) {
mkdir($config['cache_dir'], 0777, TRUE);
chmod($config['cache_dir'], 0777);
}
// Setup File Path and other basic options
if (PHP_VERSION_ID >= 70300) {
// https://github.com/PHPSocialNetwork/phpfastcache/issues/676
$cache_config = new \Phpfastcache\Drivers\Files\Config();
$cache_config->setpath($config['cache_dir']);
$cache_config->setSecurityKey($cache_key);
CacheManager::setDefaultConfig($cache_config);
//print_vars($cache_config);
} else {
$cache_config = [
'path' => $config['cache_dir'],
'securityKey' => $cache_key,
];
CacheManager::setDefaultConfig($cache_config);
}
try {
$GLOBALS[OBS_CACHE_LINK] = CacheManager::getInstance('files');
} catch (Exeption $e) {
print_debug('Cache driver Files not functional. Caching disabled!');
$GLOBALS[OBS_CACHE_LINK] = CacheManager::getInstance('Devfalse'); // disable caching
}
}
// Clear cache totally by requested attrib
if (is_cli()) {
if (get_obs_attrib('cache_cli_clear')) {
$GLOBALS[OBS_CACHE_LINK]->clear();
del_obs_attrib('cache_cli_clear');
if (OBS_DEBUG || OBS_CACHE_DEBUG) {
print_error('<span class="text-warning">CACHE CLEARED.</span> Cache clear requested.');
}
}
} elseif ($request_id = get_obs_attrib('cache_wui_clear')) {
if ($request_id !== get_request_id()) { // Skip cache clear inside same page request
$GLOBALS[OBS_CACHE_LINK]->clear();
del_obs_attrib('cache_wui_clear');
if (OBS_DEBUG || OBS_CACHE_DEBUG) {
print_error('<span class="text-warning">CACHE CLEARED.</span> Cache clear requested.');
}
}
}
if (OBS_CACHE_DEBUG) {
//$cache_stats = $GLOBALS[OBS_CACHE_LINK]->getStats();
//print_message('<span class="text-info">CACHE</span><br /> // Info: '.$cache_stats->info.'<br /> // Size: <strong>' . formatStorage($cache_stats->size) . '</strong><br />');// .
//'Key: <strong>' . $item->getKey() . '</strong> // Tags: <strong>' . $item->getTagsAsString() . '</strong><br />' .
//'Driver: <strong>'.str_replace(array('phpFastCache\\Drivers\\', '\\Item'), '', get_class($item)).'</strong> // Write time: ' . sprintf("%.7f", $cache_time) . ' ms');
//print_vars($GLOBALS[OBS_CACHE_LINK]->getStats());
//print_vars($GLOBALS[OBS_CACHE_LINK]->getPath());
//print_vars($GLOBALS[OBS_CACHE_LINK]->getConfig()->getSecurityKey());
}
// Clean
unset($detect_driver, $cache_driver, $entry);
// EOF

5704
includes/common.inc.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
<?php
// stub functions for not exist features
function cache_groups() { return array(); }
function get_type_groups() { return array(); }
function get_groups_by_type() { return array(); }
function get_group_entities() { return array(); }
// EOF

File diff suppressed because it is too large Load Diff

1052
includes/db.inc.php Normal file

File diff suppressed because it is too large Load Diff

402
includes/db/mysql.inc.php Normal file
View File

@ -0,0 +1,402 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage db
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
print_error("MySQL extension is deprecated since PHP 5.5, we unsupported it anymore. Use mysqli extension instead!");
/*
This code based on original non-OO version of dbFacile version 0.4.3
written by Alan Szlosek from http://www.greaterscope.net/projects/dbFacile
and licensed by the MIT license http://en.wikipedia.org/wiki/MIT_License
Many part of code rewritten by Observium developers.
It's a bit simplistic, but gives you the really useful bits in non-class form.
*/
/* Specific mysql function calls. */
/**
* Get MySQL client info
*
* @return string $info
*/
function dbClientInfo()
{
return mysql_get_client_info();
}
/**
* Returns a string representing the type of connection used
*
* @return string $info
*/
function dbHostInfo()
{
return mysql_get_host_info();
}
/**
* Open connection to mysql server
*
* @param string $host Hostname for mysql server, default 'localhost'
* @param string $user Username for connect to mysql server
* @param string $password Username password
* @param string $database Database name
* @param string $charset Charset used for mysql connection, default 'utf8'
*
* @return resource $connection
*/
function dbOpen($host = 'localhost', $user, $password, $database, $charset = 'utf8')
{
// Check host params
$host_array = explode(':', $host);
if (count($host_array) > 1)
{
if ($host_array[0] === 'p')
{
// This is for compatability with new style host option (from mysqli extension)
// p:example.com
// p:::1
array_shift($host_array);
$host = implode(':', $host_array);
$GLOBALS['config']['db_persistent'] = TRUE;
}
else if (count($host_array) === 2)
{
// IPv6 host not possible here
$host = $host_array[0];
if (is_numeric($host_array[1]))
{
// example.com:3306
$port = $host_array[1];
} else {
// example.com:/tmp/mysql.sock
$socket = $host_array[1];
}
}
}
switch ($host)
{
case 'localhost':
case '127.0.0.1':
case '::1':
case '':
// For localhost socket prefer
if (strlen($GLOBALS['config']['db_socket']))
{
$host .= ':' . $GLOBALS['config']['db_socket'];
}
else if (strlen($socket))
{
$host .= ':' . $socket;
}
else if (is_numeric($GLOBALS['config']['db_port']))
{
$host .= ':' . $GLOBALS['config']['db_port'];
}
else if (is_numeric($port))
{
$host .= ':' . $port;
}
break;
default:
// All other host uses only port
if (is_numeric($GLOBALS['config']['db_port']))
{
$host .= ':' . $GLOBALS['config']['db_port'];
}
else if (is_numeric($port))
{
$host .= ':' . $port;
}
}
$client_flags = 0;
// Optionally compress connection
if ($GLOBALS['config']['db_compress'] && defined('MYSQL_CLIENT_COMPRESS'))
{
$client_flags |= MYSQL_CLIENT_COMPRESS;
}
if ($GLOBALS['config']['db_persistent'] && ini_get('mysql.allow_persistent'))
{
// Open a persistent connection
$connection = mysql_pconnect($host, $user, $password, $client_flags);
} else {
// force opening a new link because we might be selecting a different database
$connection = mysql_connect($host, $user, $password, TRUE, $client_flags);
}
if ($connection)
{
if (mysql_select_db($database, $connection))
{
// Connected to DB
if ($charset)
{
mysql_set_charset($charset, $connection);
}
} else {
// DB not exist, reset $connection
if (OBS_DEBUG)
{
echo('MySQL connection error ' . mysql_errno() . ': ' . mysql_error($connection) . PHP_EOL);
}
return NULL;
}
}
return $connection;
}
/**
* Closes a previously opened database connection
*
* @param resource $connection Link to resource with mysql connection, default last used connection
*
* @return bool Returns TRUE on success or FALSE on failure.
*/
function dbClose($connection = NULL)
{
if (is_resource($connection))
{
return mysql_close($connection);
} else {
return mysql_close();
}
}
/**
* Returns the text of the error message from last MySQL operation
*
* @param resource $connection Link to resource with mysql connection, default last used connection
*
* @return string $return
*/
function dbError($connection = NULL)
{
if (is_resource($connection))
{
return mysql_error($connection);
} else {
return mysql_error();
}
}
/**
* Returns the numerical value of the error message from last MySQL operation
*
* @param resource $connection Link to resource with mysql connection, default last used connection
*
* @return string $return
*/
function dbErrorNo($connection = NULL)
{
if (is_resource($connection))
{
return mysql_errno($connection);
} else {
return mysql_errno();
}
}
function dbPing($connection = NULL)
{
if (is_resource($connection))
{
return mysql_ping($connection);
} else {
return mysql_ping();
}
}
function dbAffectedRows($connection = NULL)
{
if (is_resource($connection))
{
return mysql_affected_rows($connection);
} else {
return mysql_affected_rows();
}
}
function dbCallQuery($fullSql, $connection = NULL)
{
if (is_resource($connection))
{
return mysql_query($fullSql, $connection);
} else {
return mysql_query($fullSql);
}
}
/**
* Returns escaped string
*
* @param string $string Input string for escape in mysql query
*
* @return string
*/
function dbEscape($string, $connection = NULL)
{
if (is_resource($connection))
{
return mysql_real_escape_string($string, $connection);
} else {
return mysql_real_escape_string($string);
}
}
/**
* Returns the auto generated id used in the last query
*
* @param resource $connection Link to resource with mysql connection, default last used connection
*
* @return string
*/
function dbLastID($connection = NULL)
{
if (is_resource($connection))
{
return mysql_insert_id($connection);
} else {
return mysql_insert_id();
}
}
/*
* Fetches all of the rows (associatively) from the last performed query.
* Most other retrieval functions build off this
* */
function dbFetchRows($sql, $parameters = array(), $print_query = FALSE)
{
$time_start = utime();
$result = dbQuery($sql, $parameters, $print_query);
$rows = array();
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
$rows[] = $row;
}
mysql_free_result($result);
$time_end = utime();
$GLOBALS['db_stats']['fetchrows_sec'] += $time_end - $time_start;
$GLOBALS['db_stats']['fetchrows']++;
}
// no records, thus return empty array
// which should evaluate to false, and will prevent foreach notices/warnings
return $rows;
}
/*
* Like fetch(), accepts any number of arguments
* The first argument is an sprintf-ready query stringTypes
* */
function dbFetchRow($sql = null, $parameters = array(), $print_query = FALSE)
{
$time_start = utime();
$result = dbQuery($sql, $parameters, $print_query);
if ($result)
{
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$time_end = utime();
$GLOBALS['db_stats']['fetchrow_sec'] += $time_end - $time_start;
$GLOBALS['db_stats']['fetchrow']++;
return $row;
} else {
return null;
}
//$time_start = utime();
}
/*
* Fetches the first call from the first row returned by the query
* */
function dbFetchCell($sql, $parameters = array(), $print_query = FALSE)
{
$time_start = utime();
//$row = dbFetchRow($sql, $parameters);
$result = dbQuery($sql, $parameters, $print_query);
if ($result)
{
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$time_end = utime();
$GLOBALS['db_stats']['fetchcell_sec'] += $time_end - $time_start;
$GLOBALS['db_stats']['fetchcell']++;
return array_shift($row); // shift first field off first row
}
return null;
}
function dbBeginTransaction()
{
mysql_query('begin');
}
function dbCommitTransaction()
{
mysql_query('commit');
}
function dbRollbackTransaction()
{
mysql_query('rollback');
}
/*
class dbIterator implements Iterator {
private $result;
private $i;
public function __construct($r) {
$this->result = $r;
$this->i = 0;
}
public function rewind() {
mysql_data_seek($this->result, 0);
$this->i = 0;
}
public function current() {
$a = mysql_fetch_assoc($this->result);
return $a;
}
public function key() {
return $this->i;
}
public function next() {
$this->i++;
$a = mysql_data_seek($this->result, $this->i);
if ($a === false) {
$this->i = 0;
}
return $a;
}
public function valid() {
return ($this->current() !== false);
}
}
*/
// EOF

469
includes/db/mysqli.inc.php Normal file
View File

@ -0,0 +1,469 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage db
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
/* Specific mysqli function calls, uses procedural style. */
// Set to TRUE if MySQLnd driver is being used
define('OBS_DB_MYSQLND', function_exists('mysqli_get_client_stats'));
/**
* Get MySQL client info
*
* @return string $info
*/
function dbClientInfo() {
return mysqli_get_client_info();
}
/**
* Returns a string representing the type of connection used
*
* @return string $info
*/
function dbHostInfo() {
return isset($GLOBALS[OBS_DB_LINK]) ? mysqli_get_host_info($GLOBALS[OBS_DB_LINK]) : '';
}
/**
* Open connection to mysql server
*
* @param string $database Database name
* @param string $user Username for connect to mysql server
* @param string $password Username password
* @param string $host Hostname for mysql server, default 'localhost'
* @param string $charset Charset used for mysql connection, default 'utf8'
*
* @return object $connection
*/
function dbOpen($host, $user, $password, $database, $charset = 'utf8') {
// Check host params
$host_array = explode(':', $host);
if (count($host_array) > 1) {
if ($host_array[0] === 'p') {
// p:example.com
// p:::1
array_shift($host_array);
$host = implode(':', $host_array);
$GLOBALS['config']['db_persistent'] = TRUE;
} elseif (count($host_array) === 2) {
// This is for compatibility with old style host option (from mysql extension)
// IPv6 host not possible here
$host = $host_array[0];
if (is_numeric($host_array[1])) {
// example.com:3306
$port = $host_array[1];
} else {
// example.com:/tmp/mysql.sock
$socket = $host_array[1];
}
}
}
// Server port
if (isset($GLOBALS['config']['db_port']) && is_numeric($GLOBALS['config']['db_port'])) {
$port = $GLOBALS['config']['db_port'];
} elseif (!isset($port)) {
$port = ini_get("mysqli.default_port");
}
// Server socket
if (isset($GLOBALS['config']['db_socket']) && !safe_empty($GLOBALS['config']['db_socket'])) {
$socket = $GLOBALS['config']['db_socket'];
} elseif (!isset($socket)) {
$socket = ini_get("mysqli.default_socket");
}
// Prepending host by p: for open a persistent connection.
if (isset($GLOBALS['config']['db_persistent']) && $GLOBALS['config']['db_persistent'] &&
ini_get('mysqli.allow_persistent')) {
$host = 'p:' . $host;
}
// Init new connection
$time_start = utime();
$GLOBALS['db_stats']['connect'] = 1;
$connection = mysqli_init();
if ($connection === (object)$connection) {
$client_flags = 0;
// Optionally compress connection
if ($GLOBALS['config']['db_compress'] && defined('MYSQLI_CLIENT_COMPRESS')) {
$client_flags |= MYSQLI_CLIENT_COMPRESS;
}
// Optionally enable SSL
if ($GLOBALS['config']['db_ssl']) {
$client_flags |= MYSQLI_CLIENT_SSL;
if (!empty($GLOBALS['config']['db_ssl_key']) || !empty($GLOBALS['config']['db_ssl_cert']) ||
!empty($GLOBALS['config']['db_ssl_ca']) || !empty($GLOBALS['config']['db_ssl_ca_path']) ||
!empty($GLOBALS['config']['db_ssl_ciphers'])) {
$db_ssl_key = $GLOBALS['config']['db_ssl_key'] ? $GLOBALS['config']['db_ssl_key'] : '';
$db_ssl_cert = $GLOBALS['config']['db_ssl_cert'] ? $GLOBALS['config']['db_ssl_cert'] : '';
$db_ssl_ca = $GLOBALS['config']['db_ssl_ca'] ? $GLOBALS['config']['db_ssl_ca'] : '';
$db_ssl_ca_path = $GLOBALS['config']['db_ssl_ca_path'] ? $GLOBALS['config']['db_ssl_ca_path'] : '';
$db_ssl_ciphers = $GLOBALS['config']['db_ssl_ciphers'] ? $GLOBALS['config']['db_ssl_ciphers'] : '';
mysqli_ssl_set($connection, $db_ssl_key, $db_ssl_cert, $db_ssl_ca, $db_ssl_ca_path, $db_ssl_ciphers);
}
// Disables SSL certificate validation on mysqlnd for MySQL 5.6 or later
// https://bugs.php.net/bug.php?id=68344
if (!$GLOBALS['config']['db_ssl_verify']) {
$client_flags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
mysqli_options($connection, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, $GLOBALS['config']['db_ssl_verify']);
}
}
// Connection timeout
//$timeout = (isset($GLOBALS['config']['db_timeout']) && $GLOBALS['config']['db_timeout'] >= 1) ? (int) $GLOBALS['config']['db_timeout'] : 30;
//mysqli_options($connection, MYSQLI_OPT_CONNECT_TIMEOUT, $timeout);
// Convert integer and float columns back to PHP numbers. Boolean returns as int. Only valid for mysqlnd.
/*
if (defined('OBS_DB_MYSQLND') && OBS_DB_MYSQLND)
{
mysqli_options($connection, MYSQLI_OPT_INT_AND_FLOAT_NATIVE, TRUE);
}
*/
// Report if no index or bad index was used in a query
//mysqli_report(MYSQLI_REPORT_INDEX);
// Set default ignore errors on php8.1
// https://php.watch/versions/8.1/mysqli-error-mode
mysqli_report(MYSQLI_REPORT_OFF);
if (!mysqli_real_connect($connection, $host, $user, $password, $database, (int)$port, $socket, $client_flags)) {
$error_num = @mysqli_connect_errno();
if (defined('OBS_DEBUG') && OBS_DEBUG) {
echo('MySQLi connection error ' . $error_num . ': ' . @mysqli_connect_error() . PHP_EOL);
}
if ($error_num == 2006 && PHP_VERSION_ID >= 70400 && PHP_VERSION_ID < 70402) {
print_error("PHP version less than 7.4.2 have multiple issues with MySQL 8.0, please update your PHP to latest.");
}
$time_end = utime();
$GLOBALS['db_stats']['connect_sec'] = $time_end - $time_start;
return NULL;
}
$time_end = utime();
$GLOBALS['db_stats']['connect_sec'] = $time_end - $time_start;
//print_vars($GLOBALS['db_stats']['connect_sec']);
if ($charset) {
mysqli_set_charset($connection, $charset);
/*
if (version_compare(PHP_VERSION, '5.3.6', '<') && $charset == 'utf8')
{
// Seem as problem to set default charset on php < 5.3.6
mysqli_query($connection, "SET NAMES 'utf8' COLLATE 'utf8_general_ci';");
}
*/
}
}
return $connection;
}
/**
* Closes a previously opened database connection
*
* @param mysqli $connection Link to resource with mysql connection, default last used connection
*
* @return bool Returns TRUE on success or FALSE on failure.
*/
function dbClose($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
if (!OBS_DB_SKIP) { print_error("Call to function mysqli_close() without link identifier."); }
return;
}
return mysqli_close($connection);
}
/**
* Returns the text of the error message from last MySQL operation
*
* @param mysqli $connection Link to resource with mysql connection, default last used connection
*
* @return string $return
*/
function dbError($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
//if (!OBS_DB_SKIP) { print_error("Call to function mysqli_error() without link identifier."); }
return mysqli_connect_error();
}
return mysqli_error($connection);
}
/**
* Returns the numerical value of the error message from last MySQL operation
*
* @param mysqli $connection Link to resource with mysql connection, default last used connection
*
* @return int $return
*/
function dbErrorNo($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
//if (!OBS_DB_SKIP) { print_error("Call to function mysqli_errno() without link identifier."); }
return mysqli_connect_errno();
}
return mysqli_errno($connection);
}
function dbWarnings($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
return;
}
$warning = [];
if (mysqli_warning_count($connection)) {
$e = mysqli_get_warnings($connection);
do {
//echo "Warning: $e->errno: $e->message\n";
$warning[] = "$e->errno: $e->message";
} while ($e->next());
}
return $warning;
}
function dbPing($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
}
return mysqli_ping($connection);
}
function dbAffectedRows($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
if (!OBS_DB_SKIP) { print_error("Call to function mysqli_affected_rows() without link identifier."); }
return;
}
return mysqli_affected_rows($connection);
}
function dbCallQuery($fullSql, $connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
if (!OBS_DB_SKIP) { print_error("Call to function mysqli_query() without link identifier."); }
return;
}
return mysqli_query($connection, $fullSql);
//return mysqli_query($connection, $fullSql, MYSQLI_USE_RESULT); // Unbuffered results, for speedup!
}
/**
* Returns escaped string
*
* @param string $string Input string for escape in mysql query
* @param mysqli $connection Link to resource with mysql connection, default last used connection
*
* @return string
*/
function dbEscape($string, $connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
if (!OBS_DB_SKIP) { print_error("Call to function mysqli_real_escape_string() without link identifier."); }
return;
}
$return = mysqli_real_escape_string($connection, $string);
if (!isset($return[0]) && isset($string[0])) {
// If character set empty, use escape alternative
// FIXME. I really not know why, but in unittests $connection object is lost!
print_debug("Mysql connection lost, in dbEscape() used escape alternative!");
$search = array("\\", "\x00", "\n", "\r", "'", '"', "\x1a");
$replace = array("\\\\","\\0","\\n", "\\r", "\'", '\"', "\\Z");
$return = str_replace($search, $replace, $string);
}
return $return;
}
/**
* Returns the auto generated id used in the last query
*
* @param mysqli $connection Link to resource with mysql connection, default last used connection
*
* @return string
*/
function dbLastID($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
if (!OBS_DB_SKIP) { print_error("Call to function mysqli_insert_id() without link identifier."); }
return;
}
if ($id = mysqli_insert_id($connection)) {
//print_debug("DEBUG ID by function");
//var_dump($id);
return $id;
} else {
// mysqli_insert_id() not return last id, after non empty warnings
//print_debug("DEBUG ID by query");
//var_dump($id);
return dbFetchCell('SELECT last_insert_id();');
}
//return mysqli_insert_id($connection);
}
/*
* Fetches all of the rows (associatively) from the last performed query.
* Most other retrieval functions build off this
* */
function dbFetchRows($sql, $parameters = [], $print_query = FALSE) {
$time_start = utime();
$result = dbQuery($sql, $parameters, $print_query);
$rows = [];
if ($result instanceof mysqli_result) {
if (OBS_DB_MYSQLND) {
// MySQL Native Driver
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
} else {
while ($row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
}
}
mysqli_free_result($result);
$time_end = utime();
$GLOBALS['db_stats']['fetchrows_sec'] += $time_end - $time_start;
$GLOBALS['db_stats']['fetchrows']++;
}
// no records, thus return empty array
// which should evaluate to false, and will prevent foreach notices/warnings
return $rows;
}
/*
* Like fetch(), accepts any number of arguments
* The first argument is an sprintf-ready query stringTypes
* */
function dbFetchRow($sql = NULL, $parameters = array(), $print_query = FALSE) {
$time_start = utime();
$result = dbQuery($sql, $parameters, $print_query);
if ($result) {
$row = mysqli_fetch_assoc($result);
mysqli_free_result($result);
$time_end = utime();
$GLOBALS['db_stats']['fetchrow_sec'] += $time_end - $time_start;
$GLOBALS['db_stats']['fetchrow']++;
return $row;
}
return [];
}
/*
* Fetches the first call from the first row returned by the query
* */
function dbFetchCell($sql, $parameters = array(), $print_query = FALSE) {
$time_start = utime();
//$row = dbFetchRow($sql, $parameters);
$result = dbQuery($sql, $parameters, $print_query);
if ($result) {
$row = mysqli_fetch_assoc($result);
mysqli_free_result($result);
$time_end = utime();
$GLOBALS['db_stats']['fetchcell_sec'] += $time_end - $time_start;
$GLOBALS['db_stats']['fetchcell']++;
if (is_array($row)) {
return array_shift($row); // shift first field off first row
}
}
return NULL; // or ''?
}
function dbBeginTransaction($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
if (!OBS_DB_SKIP) { print_error("Call to begin db transaction without link identifier."); }
return;
}
mysqli_autocommit($connection, FALSE); // Set autocommit to off
}
function dbCommitTransaction($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
if (!OBS_DB_SKIP) { print_error("Call to commmit db transaction without link identifier."); }
return;
}
mysqli_commit($connection);
mysqli_autocommit($connection, TRUE); // Restore autocommit to on
}
function dbRollbackTransaction($connection = NULL) {
// Observium uses $observium_link global variable name for db link
if ($connection === (object)$connection) {}
elseif (isset($GLOBALS[OBS_DB_LINK]) && $GLOBALS[OBS_DB_LINK] === (object)$GLOBALS[OBS_DB_LINK]) {
$connection = $GLOBALS[OBS_DB_LINK];
} else {
if (!OBS_DB_SKIP) { print_error("Call to rollback db transaction without link identifier."); }
return;
}
mysqli_rollback($connection);
mysqli_autocommit($connection, TRUE); // Restore autocommit to on
}
// EOF

1121
includes/defaults.inc.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,930 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage definitions
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
/////////////////////////////////////////////////////////
// NO CHANGES TO THIS FILE, IT IS NOT USER-EDITABLE //
/////////////////////////////////////////////////////////
// YES, THAT MEANS YOU //
/////////////////////////////////////////////////////////
// Always set locale to EN, because we use parsing strings
setlocale(LC_ALL, 'C');
putenv('LC_ALL=C');
// Use default charset UTF-8
ini_set('default_charset', 'UTF-8');
// Flags (mostly used in snmp and network functions, only 2^bit)
// Bits 0-3 common flags
define('OBS_QUOTES_STRIP', 1); // Strip ALL quotes from string
define('OBS_QUOTES_TRIM', 2); // Trim double/single quotes only from begin/end of string
define('OBS_ESCAPE', 4); // Escape strings or output
define('OBS_DECODE_UTF8', 8); // Decode ascii coded chars in string as correct UTF-8
// Bits 4-15 snmp flags
define('OBS_SNMP_NUMERIC', 16); // Use numeric OIDs (-On)
define('OBS_SNMP_NUMERIC_INDEX', 32); // Use numeric index (-Ob)
define('OBS_SNMP_CONCAT', 64); // Concatenate multiline snmp variable (newline chars removed)
define('OBS_SNMP_ENUM', 128); // Don't enumerate SNMP values
define('OBS_SNMP_HEX', 256); // Force HEX output (-Ox) and disable use of DISPLAY-HINT information when assigning values (-Ih).
define('OBS_SNMP_TABLE', 512); // Force Program Like output (-OX)
define('OBS_SNMP_DISPLAY_HINT', 1024); // Disables the use of DISPLAY-HINT information when assigning values (-Ih). This would then require providing the raw value.
define('OBS_SNMP_TIMETICKS', 2048); // Force TimeTicks values as raw numbers (-Ot)
define('OBS_SNMP_ASCII', 4096); // Force all string values as ASCII strings
define('OBS_SNMP_NOINDEX', 8192); // Allow to walk tables without indexes, like snmpwalk_cache_bare_oid()
define('OBS_SNMP_NOINCREASE', 16384); // Do not check returned OIDs are increasing in snmpwalk (-Cc)
define('OBS_SNMP_INDEX_PARTS', 32768); // Use this to split index parts by arrow (->), actually for strings in index part and/or for OBS_SNMP_TABLE flag
define('OBS_SNMP_ALL', OBS_QUOTES_TRIM | OBS_QUOTES_STRIP); // Set of common snmp options
define('OBS_SNMP_ALL_MULTILINE', OBS_QUOTES_TRIM | OBS_SNMP_CONCAT); // Set of common snmp options with concatenate multiline snmp variable
define('OBS_SNMP_ALL_ASCII', OBS_QUOTES_TRIM | OBS_SNMP_ASCII); // Set of common snmp options with forcing string values as ASCII strings
define('OBS_SNMP_ALL_UTF8', OBS_SNMP_ALL_ASCII | OBS_SNMP_HEX | OBS_DECODE_UTF8); // Set of common snmp options with forcing string values as UTF8 strings
define('OBS_SNMP_ALL_HEX', OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX); // Set of common snmp options forcing HEX output
define('OBS_SNMP_ALL_ENUM', OBS_SNMP_ALL | OBS_SNMP_ENUM); // Set of common snmp options without enumerating values
define('OBS_SNMP_ALL_NUMERIC', OBS_SNMP_ALL | OBS_SNMP_NUMERIC); // Set of common snmp options with numeric OIDs
define('OBS_SNMP_ALL_NUMERIC_INDEX', OBS_SNMP_ALL | OBS_SNMP_NUMERIC_INDEX); // Set of common snmp options with numeric indexes
define('OBS_SNMP_ALL_NOINDEX', OBS_SNMP_ALL | OBS_SNMP_NOINDEX); // Set of common snmp options with ability collect table without indexes
define('OBS_SNMP_ALL_TABLE', OBS_QUOTES_TRIM | OBS_SNMP_TABLE); // Set of common snmp options with Program Like (help for MAC parse in indexes)
define('OBS_SNMP_ALL_TIMETICKS', OBS_SNMP_ALL | OBS_SNMP_TIMETICKS); // Set of common snmp options with TimeTicks as raw numbers
// Bits 16-19 network flags
define('OBS_DNS_A', 65536); // Use only IPv4 dns queries
define('OBS_DNS_AAAA', 131072); // Use only IPv6 dns queries
define('OBS_DNS_ALL', OBS_DNS_A | OBS_DNS_AAAA); // Use both IPv4/IPv6 dns queries
define('OBS_DNS_FIRST', 262144); // Flag for use in gethostbyname6()
define('OBS_PING_SKIP', 524288); // Skip device icmp ping checks
// Permission levels flags
define('OBS_PERMIT_ACCESS', 1); // Can access (ie: logon)
define('OBS_PERMIT_READ', 2); // Can read basic data
define('OBS_PERMIT_SECURE', 4); // Can read secure data
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
define('OBS_CONFIG_EXPERT', 7); // 0111: Expert view, includes advanced and basic
// Common regex patterns
const OBS_PATTERN_START = '%(?:^|[\s\"\(=])'; // Beginning of any pattern, matched string can start from newline, space, double quote, opening parenthesis, equal sign
const OBS_PATTERN_END = '(?:[\s\"\),]|[\:\.]\ |\.?$)%i'; // End of any pattern, matched string can ended with endline, space, double quote, closing parenthesis, comma, dot
const OBS_PATTERN_END_U = OBS_PATTERN_END . 'u'; // ++Unicode
// IPv4 string in group \1 or 'ipv4'
const OBS_PATTERN_IPV4 = '(?<ipv4>(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))';
const OBS_PATTERN_IPV4_FULL = OBS_PATTERN_START . OBS_PATTERN_IPV4 . OBS_PATTERN_END;
// IPv4 netmask string in group \1 or 'ipv4_mask'
const OBS_PATTERN_IPV4_MASK = '(?<ipv4_mask>(?:0|128|192|224|240|248|252|254)\.0\.0\.0|255\.(?:0|128|192|224|240|248|252|254)\.0\.0|255\.255\.(?:0|128|192|224|240|248|252|254)\.0|255\.255\.255\.(?:0|128|192|224|240|248|252|254|255))';
// IPv4 inverse netmask string in group \1 or 'ipv4_inverse_mask'
const OBS_PATTERN_IPV4_INVERSE_MASK = '(?<ipv4_inverse_mask>(?:255|127|63|31|15|7|3|1|0)\.255\.255\.255|0\.(?:255|127|63|31|15|7|3|1|0)\.255\.255|0\.0\.(?:255|127|63|31|15|7|3|1|0)\.255|0\.0\.0\.(?:255|127|63|31|15|7|3|1|0))';
// IPv4 network string in group \1 or 'ipv4_network', additionally 'ipv4', 'ipv4_prefix' or 'ipv4_mask' or 'ipv4_inverse_mask'
const OBS_PATTERN_IPV4_NET = '(?<ipv4_network>' . OBS_PATTERN_IPV4 . '\/(?:(?<ipv4_prefix>3[0-2]|[1-2][0-9]|[0-9])|' . OBS_PATTERN_IPV4_MASK . '|' . OBS_PATTERN_IPV4_INVERSE_MASK . '))';
const OBS_PATTERN_IPV4_NET_FULL = OBS_PATTERN_START . OBS_PATTERN_IPV4_NET . OBS_PATTERN_END;
// IPv6 string in group \1 or 'ipv6'
const OBS_PATTERN_IPV6 = '(?<ipv6>(?:(?:(?:[a-f\d]{1,4}:){5}[a-f\d]{1,4}|(?:[a-f\d]{1,4}:){4}:[a-f\d]{1,4}|(?:[a-f\d]{1,4}:){3}(?::[a-f\d]{1,4}){1,2}|(?:[a-f\d]{1,4}:){2}(?::[a-f\d]{1,4}){1,3}|[a-f\d]{1,4}:(?::[a-f\d]{1,4}){1,4}|(?:[a-f\d]{1,4}:){1,5}|:(?::[a-f\d]{1,4}){1,5}|:):(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])|(?:[a-f\d]{1,4}:){7}[a-f\d]{1,4}|(?:[a-f\d]{1,4}:){6}:[a-f\d]{1,4}|(?:[a-f\d]{1,4}:){5}(?::[a-f\d]{1,4}){1,2}|(?:[a-f\d]{1,4}:){4}(?::[a-f\d]{1,4}){1,3}|(?:[a-f\d]{1,4}:){3}(?::[a-f\d]{1,4}){1,4}|(?:[a-f\d]{1,4}:){2}(?::[a-f\d]{1,4}){1,5}|[a-f\d]{1,4}:(?::[a-f\d]{1,4}){1,6}|(?:[a-f\d]{1,4}:){1,7}:|:(?::[a-f\d]{1,4}){1,7}|::))';
const OBS_PATTERN_IPV6_FULL = OBS_PATTERN_START . OBS_PATTERN_IPV6 . OBS_PATTERN_END;
// IPv6 network string in group \1 or 'ipv6_network', additionally 'ipv6', 'ipv6_prefix'
const OBS_PATTERN_IPV6_NET = '(?<ipv6_network>' . OBS_PATTERN_IPV6 . '\/(?<ipv6_prefix>12[0-8]|1[0-1][0-9]|[0-9]{1,2}))';
const OBS_PATTERN_IPV6_NET_FULL = OBS_PATTERN_START . OBS_PATTERN_IPV6_NET . OBS_PATTERN_END;
// IPv4 or IPv6 string in group \1 or 'ip'
const OBS_PATTERN_IP = '(?<ip>' . OBS_PATTERN_IPV4 . '|' . OBS_PATTERN_IPV6 . ')';
const OBS_PATTERN_IP_FULL = OBS_PATTERN_START . OBS_PATTERN_IP . OBS_PATTERN_END;
// IPv4 or IPv6 network string in group \1 or 'ip_network'
const OBS_PATTERN_IP_NET = '(?<ip_network>' . OBS_PATTERN_IPV4_NET . '|' . OBS_PATTERN_IPV6_NET . ')';
const OBS_PATTERN_IP_NET_FULL = OBS_PATTERN_START . OBS_PATTERN_IP_NET . OBS_PATTERN_END;
// MAC string in group \1 or 'mac'
const OBS_PATTERN_MAC = '(?<mac>(?:[a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5}|[a-f\d]{2}(?:\-[a-f\d]{2}){5}|[a-f\d]{2}(?:\ [a-f\d]{2}){5}|[a-f\d]{4}(?:\.[a-f\d]{4}){2}|(?:0x)?[a-f\d]{12}))';
const OBS_PATTERN_MAC_FULL = OBS_PATTERN_START . OBS_PATTERN_MAC . OBS_PATTERN_END;
// FQDN string in group \1 or 'domain'
//define('OBS_PATTERN_FQDN', '(?<domain>(?:(?:(?:xn--)?[a-z0-9_]+(?:\-[a-z0-9_]+)*\.)+(?:[a-z]{2,}|xn--[a-z0-9]{4,}))|localhost)'); // Alternative, less correct
//define('OBS_PATTERN_FQDN', '(?<domain>(?:(?:(?=[a-z0-9\-_]{1,63}\.)(?:xn--)?[a-z0-9_]+(?:\-[a-z0-9_]+)*\.)+(?:[a-z]{2,63}|xn--[a-z0-9]{4,}))|localhost)'); // Punicode, Non-unicode
const OBS_PATTERN_FQDN = '(?<domain>(?:(?:(?=[\p{L}\d\-_]{1,63}\.)(?:xn--)?[\p{L}\d_]+(?:\-[\p{L}\d_]+)*\.)+(?:[\p{L}]{2,63}|xn--[a-z\d]{4,}))|localhost)';
const OBS_PATTERN_FQDN_FULL = OBS_PATTERN_START . OBS_PATTERN_FQDN . OBS_PATTERN_END_U;
// pattern for email only (without Name, ie: user@domain.name)
// Email string in group \1 or 'email', additional groups: 'user', 'domain'
const OBS_PATTERN_EMAIL = '(?<email>(?<user>[\p{L}\d\.\'_\%\+\-]{1,63}|\"[\p{L}\d\.\'_\%\+\-\ \\\\]{1,63}\")@' . OBS_PATTERN_FQDN . ')';
const OBS_PATTERN_EMAIL_FULL = OBS_PATTERN_START . OBS_PATTERN_EMAIL . OBS_PATTERN_END_U;
// pattern for Full email with Name (ie: "My Name" <user@domain.name>), but name is optional
// Long Email string in group \1 or 'email_long', additional groups: 'name', 'email', 'user', 'domain'
const OBS_PATTERN_EMAIL_LONG = '(?<email_long>(?<name>[\"\'][\p{L}\d\.\'_\%\+\-\ \\\\]+[\"\']|(?:[\p{L}\d\.\'_\%\+\-]+\ )*[\p{L}\d\.\'_\%\+\-]+)?\s*<' . OBS_PATTERN_EMAIL . '>)';
const OBS_PATTERN_EMAIL_LONG_FULL = OBS_PATTERN_START . OBS_PATTERN_EMAIL_LONG . OBS_PATTERN_END_U;
//define('OBS_PATTERN_URL', '(?<url>(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?)');
//define('OBS_PATTERN_URL_FULL', OBS_PATTERN_START . OBS_PATTERN_URL . OBS_PATTERN_END_U);
// SNMP HEX-STRING group \1 or 'hex'
const OBS_PATTERN_SNMP_HEX = '(?<hex>[a-f\d]{2}(\ +[a-f\d]{2})*)\ ?';
// SNMP NUMERIC OID group \1 or 'oid_num'
const OBS_PATTERN_SNMP_OID_NUM = '/^(?<oid_num>\.?(\d+(?:\.\d+)+))$/';
// Split graph type with subtype
const OBS_PATTERN_GRAPH_TYPE = '/^(?<type>[a-z\d\-]+)_(?<subtype>[a-z\d\-_]+)/i';
// timestamps formatted as 'Y-m-d H:i:s'
const OBS_PATTERN_TIMESTAMP = '/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/';
const OBS_PATTERN_WINDOWSTIME = '/^(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?<hour>\d{2})(?<min>\d{2})(?<sec>\d{2}\.\d+)(\+\d+)?$/';
const OBS_PATTERN_RRDTIME = '/^(\-?\d+|[\-\+]\d+[dwmysh]|now)$/i';
// patterns for validating kind of used data
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\.\-+]*\])*$/';
// Json flags
define('OBS_JSON_BIGINT_AS_STRING', PHP_VERSION_ID >= 50400 && PHP_INT_SIZE > 4 && !(defined('JSON_C_VERSION'))); // Check if BIGINT supported
$json_encode = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
if (defined('JSON_PRESERVE_ZERO_FRACTION')) {
$json_encode |= JSON_PRESERVE_ZERO_FRACTION;
}
$json_decode = OBS_JSON_BIGINT_AS_STRING ? JSON_BIGINT_AS_STRING : 0;
$json_decode |= JSON_UNESCAPED_UNICODE;
/* use fix_json_unicode()
if (defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
// Prevent invalid UTF8 broke whole json
// available in php7.2+
$json_decode |= JSON_INVALID_UTF8_IGNORE; //JSON_INVALID_UTF8_SUBSTITUTE;
}
*/
define('OBS_JSON_ENCODE', $json_encode);
define('OBS_JSON_DECODE', $json_decode);
unset($json_encode, $json_decode);
// Detect encrypt module
if (PHP_VERSION_ID >= 70200 && extension_loaded('sodium')) {
// Libsodium is part of php since 7.2
define('OBS_ENCRYPT', TRUE);
define('OBS_ENCRYPT_MODULE', 'sodium');
} elseif (extension_loaded('mcrypt')) {
// Older php can use mcrypt (not supported since php 7.2)
define('OBS_ENCRYPT', TRUE);
define('OBS_ENCRYPT_MODULE', 'mcrypt');
} else {
// No encrypt modules found
define('OBS_ENCRYPT', FALSE);
}
//var_dump(OBS_ENCRYPT);
// Always use "enhanced algorithm" for rounding float numbers in JSON/serialize
ini_set('serialize_precision', -1);
// Use more accurate math
if (function_exists('bcadd')) {
// BC Math
define('OBS_MATH', 'bc');
} elseif (defined('GMP_VERSION')) {
// GMP (gmp have troubles with convert float numbers)
define('OBS_MATH', 'gmp');
} else {
// Fallback to php math
define('OBS_MATH', 'php');
}
//var_dump(OBS_MATH);
// Minimum supported versions
// NOTE. Minimum supported versions equals to latest in minimum supported RHEL (7.x at 02.2021)
const OBS_MIN_PHP_VERSION = '5.6.26'; // PHP (15 Sep 2016, https://www.php.net/releases/index.php)
//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_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)
// Minimum possible unixtime, only for validate passed unixtime
//define('OBS_MIN_UNIXTIME', 946684800); // 01/01/2000 @ 12:00am (UTC), just in most cases unixtime not possible less than this date (net-snmp released in 2000, any network device not have uptime longest)
const OBS_MIN_UNIXTIME = 504921600; // 01/01/1986 @ 12:00am (UTC), not network devices produces before this date :)
// OBSERVIUM URLs
const OBSERVIUM_URL = 'https://www.observium.org';
const OBSERVIUM_DOCS_URL = 'https://docs.observium.org';
const OBSERVIUM_MIBS_URL = 'https://mibs.observium.org/mib';
// Set QUIET
define('OBS_QUIET', isset($options['q']));
// Set DEBUG
if (isset($options['d'])) {
// CLI
echo("DEBUG!\n");
define('OBS_DEBUG', is_array($options['d']) ? count($options['d']) : 1); // -d == 1, -dd == 2..
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
if (OBS_DEBUG > 1) {
//ini_set('error_reporting', E_ALL ^ E_NOTICE); // FIXME, too many warnings ;)
ini_set('error_reporting', E_ALL ^ E_DEPRECATED ^ E_NOTICE ^ E_WARNING);
} else {
ini_set('error_reporting', E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR); // Only various errors
}
} elseif (defined('OBS_API')) {
// API
$debug_web_requested = ((isset($_REQUEST['debug']) && $_REQUEST['debug']) ||
(isset($_SERVER['PATH_INFO']) && strpos($_SERVER['PATH_INFO'], 'debug')) ||
(isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], 'debug')));
if ($debug_web_requested) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
$debug = TRUE;
// API used self debug output
if (isset($config['web_debug_unprivileged']) && $config['web_debug_unprivileged'] &&
is_numeric($_GET['debug']) && $_GET['debug'] > 1) {
define('OBS_DEBUG', 1);
} else {
define('OBS_DEBUG', 0);
}
} else {
define('OBS_DEBUG', 0);
}
} elseif ($debug_web_requested = ((isset($_REQUEST['debug']) && $_REQUEST['debug']) ||
(isset($_SERVER['PATH_INFO']) && strpos($_SERVER['PATH_INFO'], 'debug')) ||
(isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], 'debug')))) {
// WEB
// Note, for security reasons set OBS_DEBUG constant in WUI moved to auth module
if (isset($config['web_debug_unprivileged']) && $config['web_debug_unprivileged']) {
define('OBS_DEBUG', 1);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
//ini_set('error_reporting', E_ALL ^ E_NOTICE);
ini_set('error_reporting', E_ALL ^ E_DEPRECATED ^ E_NOTICE ^ E_WARNING);
} // else not set anything before auth
} else {
define('OBS_DEBUG', 0);
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
//ini_set('error_reporting', 0); // Use default php config
}
if (!defined('OBS_DEBUG') || !OBS_DEBUG) {
// Disable E_NOTICE from reporting.
error_reporting(error_reporting() & ~E_NOTICE);
}
ini_set('log_errors', 1);
//
// Unit test not used sql connect and does not include includes/sql-config.inc.php
if (defined('__PHPUNIT_PHAR__'))
{
// Base dir, if it's not set in config
if (!isset($config['install_dir'])) {
$config['install_dir'] = dirname(__DIR__);
}
if (!defined('OBS_DB_SKIP')) {
define('OBS_DB_SKIP', TRUE);
}
// In phpunit, autoload not work
set_include_path(dirname(__DIR__) . "/libs/pear" . PATH_SEPARATOR . get_include_path());
require("Net/IPv4.php");
require("Net/IPv6.php");
require("Console/Color2.php");
//print_warning("WARNING. In PHP Unit tests can skip MySQL connect. But If you test mysql functions, check your configs.");
} else {
define('OBS_DB_SKIP', FALSE);
}
// Set default Include path
set_include_path($config['install_dir'] . "/libs/pear" . PATH_SEPARATOR . // Still required Pear path
$config['install_dir'] . "/libs" . PATH_SEPARATOR .
get_include_path());
// Set default paths.
$config['install_dir'] = rtrim($config['install_dir'], ' /');
if (!isset($config['html_dir'])) { $config['html_dir'] = $config['install_dir'] . '/html'; }
else { $config['html_dir'] = rtrim($config['html_dir'], ' /'); }
if (!isset($config['rrd_dir'])) { $config['rrd_dir'] = $config['install_dir'] . '/rrd'; }
else { $config['rrd_dir'] = rtrim($config['rrd_dir'], ' /'); }
// Fix RRD Directory path to always have a trailing slash so that it works nicely with rrdcached
//$config['rrd_dir'] = fix_path_slash($config['rrd_dir']);
if (!isset($config['log_dir'])) { $config['log_dir'] = $config['install_dir'] . '/logs'; }
else { $config['log_dir'] = rtrim($config['log_dir'], ' /'); }
if (!isset($config['log_file'])) { $config['log_file'] = $config['log_dir'] . '/observium.log'; } // FIXME should not be absolute path, look for where it is used
if (!isset($config['temp_dir'])) { $config['temp_dir'] = '/tmp'; }
else { $config['temp_dir'] = rtrim($config['temp_dir'], ' /'); }
if (!isset($config['mib_dir'])) { $config['mib_dir'] = $config['install_dir'] . '/mibs'; }
else { $config['mib_dir'] = rtrim($config['mib_dir'], ' /'); }
if (!isset($config['template_dir'])) { $config['template_dir'] = $config['install_dir'] . '/templates'; }
else { $config['template_dir'] = rtrim($config['template_dir'], ' /'); }
if (!isset($config['cache_dir'])) { $config['cache_dir'] = $config['temp_dir'] . '/observium_cache'; }
else { $config['cache_dir'] = rtrim($config['cache_dir'], ' /'); }
#if (!isset($config['nagplug_dir'])) { $config['nagplug_dir'] = '/usr/lib/nagios/plugins'; }
#else { $config['nagplug_dir'] = rtrim($config['nagplug_dir'], ' /'); }
// 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");
// Collect php errors mostly for catch php8 errors
if ($config['php_debug'] && !defined('__PHPUNIT_PHAR__')) {
ini_set('error_reporting', E_ALL ^ E_DEPRECATED ^ E_NOTICE ^ E_WARNING ^ E_STRICT);
ini_set("error_log", $config['log_dir'] . "/php-errors.log");
}
// Debug nicer functions
if ((defined('OBS_DEBUG') && OBS_DEBUG) ||
(isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']))) {
// Nicer for print_vars(), for WUI loaded always,
// Required php tokenizer extension!
if (!function_exists('rt') && function_exists('token_get_all') &&
is_file($config['install_dir']."/libs/ref.inc.php")) {
include($config['install_dir']."/libs/ref.inc.php");
}
}
require($config['install_dir'] . '/includes/definitions/version.inc.php');
// Community specific definition
if (OBSERVIUM_EDITION === 'community' &&
is_file($config['install_dir'].'/includes/definitions/definitions.dat')) {
//var_dump($config);
$config_tmp = file_get_contents($config['install_dir'].'/includes/definitions/definitions.dat');
$config_tmp = gzuncompress($config_tmp);
$config_tmp = safe_unserialize($config_tmp);
//var_dump($config_tmp);
if (is_array($config_tmp) && isset($config_tmp['os'])) { // Simple check for passed correct data
$config = array_merge($config, $config_tmp);
}
unset($config_tmp);
}
$definition_files = [
'os', // OS definitions
'wui', // Web UI specific definitions
'graphtypes', // Graph Type definitions
'rrdtypes', // RRD Type definitions
'entities', // Entity type definitions
'rewrites', // Rewriting array definitions
'mibs', // MIB definitions
'vendors', // Vendor/manufacturer definitions
'geo', // Geolocation api definitions
'vm', // Virtual Machine definitions
'transports', // Alerting transport definitions
'apis', // External APIs definitions
'apps', // Apps system definitions
];
foreach ($definition_files as $file) {
$file = $config['install_dir'].'/includes/definitions/'.$file.'.inc.php';
if (is_file($file)) {
include($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.');
// 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');
// 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');
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');
}
// 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)');
// Alert severities (emoji used _only_ as notification icon)
// Recover emoji is white_check_mark
$config['alert']['severity']['crit'] = [ 'name' => 'Critical', 'color' => '#D94640', 'label-class' => 'error', 'row-class' => 'error', 'icon' => $config['icon']['critical'], 'emoji' => 'fire' ];
$config['alert']['severity']['warn'] = [ 'name' => 'Warning', 'color' => '#F2CA3F', 'label-class' => 'warning', 'row-class' => 'warning', 'icon' => $config['icon']['warning'], 'emoji' => 'warning' ];
//$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');
// '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
// note, rate not fully correct after server reboot (it will less than really)
$config['snmp']['errorcodes'][-1] = [
'reason' => 'Cached', // snmp really not requested, but gets from cache
'name' => 'OBS_SNMP_ERROR_CACHED',
'msg' => ''
];
$config['snmp']['errorcodes'][0] = [
'reason' => 'OK',
'name' => 'OBS_SNMP_ERROR_OK',
'msg' => ''
];
// [1-99] Non critical
$config['snmp']['errorcodes'][1] = [
'reason' => 'Empty response', // exitcode = 0, but not have any data
'count' => 288, // 288 with rate 1/poll ~ 1 day
'rate' => 0.9,
'name' => 'OBS_SNMP_ERROR_EMPTY_RESPONSE',
'msg' => ''
];
$config['snmp']['errorcodes'][2] = [
'reason' => 'Request not completed', // Snmp output return correct data, but stopped by some reason (timeout, network error)
'name' => 'OBS_SNMP_ERROR_REQUEST_NOT_COMPLETED',
'msg' => ''
];
$config['snmp']['errorcodes'][3] = [
'reason' => 'Too long response', // Not empty output, but exitcode = 1 and runtime > 10
'name' => 'OBS_SNMP_ERROR_TOO_LONG_RESPONSE',
'msg' => ''
];
$config['snmp']['errorcodes'][4] = [
'reason' => 'Too big max-repetition in GETBULK', // Not empty output, but exitcode = 2 and stderr "Reason: (tooBig)"
'count' => 2880, // 2880 with rate 1/poll ~ 10 day
'rate' => 0.9,
'name' => 'OBS_SNMP_ERROR_TOO_BIG_MAX_REPETITION_IN_GETBULK',
'msg' => 'WARNING! %command% did not complete. Try to increase SNMP timeout or decrease SNMP Max Repetitions on the device properties page or set to 0 to not use bulk snmp commands.'
];
$config['snmp']['errorcodes'][5] = [
'reason' => 'GETNEXT empty response', // Not empty output, SNMPGETNEXT returned different Oid
'count' => 288, // 288 with rate 1/poll ~ 1 day
'rate' => 0.9,
'name' => 'OBS_SNMP_ERROR_GETNEXT_EMPTY_RESPONSE',
'msg' => ''
];
// [900-999] Critical errors, but this is incorrect auth or config or missed files on client side
$config['snmp']['errorcodes'][900] = [
'reason' => 'isSNMPable', // Device up/down test, not used for counting
'name' => 'OBS_SNMP_ERROR_ISSNMPABLE',
'msg' => ''
];
$config['snmp']['errorcodes'][991] = [
'reason' => 'Authentication failure', // Snmp auth errors
'name' => 'OBS_SNMP_ERROR_AUTHENTICATION_FAILURE',
'msg' => ''
];
$config['snmp']['errorcodes'][992] = [
'reason' => 'Unsupported authentication or privacy protocol', // Snmp auth errors
'name' => 'OBS_SNMP_ERROR_UNSUPPORTED_ALGO',
'msg' => 'ERROR! Unsupported SNMPv3 authentication or privacy protocol detected. Newer version of net-snmp required. Please read [FAQ](' .
OBSERVIUM_DOCS_URL . '/faq/#snmpv3-strong-authentication-or-encryption){target=_blank}.'
];
$config['snmp']['errorcodes'][993] = [
'reason' => 'OID not increasing', // OID not increasing
'name' => 'OBS_SNMP_ERROR_OID_NOT_INCREASING',
'msg' => 'WARNING! %command% ended prematurely due to an error [%reason%] on MIB::Oid [%mib%::%oid%]. Try to use -Cc option for %command% command.'
];
$config['snmp']['errorcodes'][994] = [
'reason' => 'Unknown host', // Unknown host
'name' => 'OBS_SNMP_ERROR_UNKNOWN_HOST',
'msg' => ''
];
$config['snmp']['errorcodes'][995] = [
'reason' => 'Incorrect arguments', // Incorrect arguments passed to snmpcmd
'name' => 'OBS_SNMP_ERROR_INCORRECT_ARGUMENTS',
'msg' => ''
];
$config['snmp']['errorcodes'][996] = [
'reason' => 'MIB or oid not found', // MIB module or oid not found in specified dirs
'name' => 'OBS_SNMP_ERROR_MIB_OR_OID_NOT_FOUND',
'msg' => ''
];
$config['snmp']['errorcodes'][997] = [
'reason' => 'Wrong .index in mibs dir', // This is common net-snmp bug, require delete all .index files
'name' => 'OBS_SNMP_ERROR_WRONG_INDEX_IN_MIBS_DIR',
'msg' => 'ERROR! Wrong .index in mibs dir net-snmp bug detected. Required delete all .index files. Please read [FAQ](' .
OBSERVIUM_DOCS_URL . '/faq/#all-my-hosts-seem-down-to-observium-snmp-doesnt-seem-to-work-anymore){target=_blank}.'
];
$config['snmp']['errorcodes'][998] = [
'reason' => 'MIB or oid disabled', // MIB or oid disabled
'name' => 'OBS_SNMP_ERROR_MIB_OR_OID_DISABLED',
'msg' => ''
];
$config['snmp']['errorcodes'][999] = [
'reason' => 'Unknown', // Some unidentified error
'count' => 288, // 288 with rate 1.95/poll ~ 12 hours
'rate' => 0.9,
'name' => 'OBS_SNMP_ERROR_UNKNOWN',
'msg' => ''
];
// [1000-1xxx] Critical errors on device side, can be auto disabled
$config['snmp']['errorcodes'][1000] = [
'reason' => 'Failed response', // Any critical error in snmp output, which not return useful data
'count' => 70, // errors in every poll run, disable after ~ 6 hours
'rate' => 0.9,
'name' => 'OBS_SNMP_ERROR_FAILED_RESPONSE',
'msg' => ''
];
//$config['snmp']['errorcodes'][1001] = array('reason' => 'Authentication failure', // Snmp auth errors
// 'count' => 25, // errors in every poll run, disable after ~ 1.5 hour
// 'rate' => 0.9,
// 'msg' => '');
$config['snmp']['errorcodes'][1002] = [
'reason' => 'Request timeout', // Cmd exit by timeout
'count' => 25, // errors in every poll run, disable after ~ 1.5 hour
'rate' => 0.9,
'name' => 'OBS_SNMP_ERROR_REQUEST_TIMEOUT',
'msg' => ''
];
$config['snmp']['errorcodes'][1004] = [
'reason' => 'Bulk Request timeout', // Cmd exit by timeout
'count' => 25, // errors in every poll run, disable after ~ 1.5 hour
'rate' => 0.9,
'name' => 'OBS_SNMP_ERROR_BULK_REQUEST_TIMEOUT',
'msg' => 'ERROR! %command% exit by timeout. Try to decrease SNMP Max Repetitions on the device properties page or set to 0 to not use bulk snmp commands.'
];
// Register error code constants
define('OBS_SNMP_ERROR_CACHED', -1);
define('OBS_SNMP_ERROR_OK', 0);
define('OBS_SNMP_ERROR_EMPTY_RESPONSE', 1);
define('OBS_SNMP_ERROR_REQUEST_NOT_COMPLETED', 2);
define('OBS_SNMP_ERROR_TOO_LONG_RESPONSE', 3);
define('OBS_SNMP_ERROR_TOO_BIG_MAX_REPETITION_IN_GETBULK', 4);
define('OBS_SNMP_ERROR_GETNEXT_EMPTY_RESPONSE', 5);
define('OBS_SNMP_ERROR_ISSNMPABLE', 900);
define('OBS_SNMP_ERROR_AUTHENTICATION_FAILURE', 991);
define('OBS_SNMP_ERROR_UNSUPPORTED_ALGO', 992);
define('OBS_SNMP_ERROR_OID_NOT_INCREASING', 993);
define('OBS_SNMP_ERROR_UNKNOWN_HOST', 994);
define('OBS_SNMP_ERROR_INCORRECT_ARGUMENTS', 995);
define('OBS_SNMP_ERROR_MIB_OR_OID_NOT_FOUND', 996);
define('OBS_SNMP_ERROR_WRONG_INDEX_IN_MIBS_DIR', 997);
define('OBS_SNMP_ERROR_MIB_OR_OID_DISABLED', 998);
define('OBS_SNMP_ERROR_UNKNOWN', 999);
define('OBS_SNMP_ERROR_FAILED_RESPONSE', 1000);
define('OBS_SNMP_ERROR_REQUEST_TIMEOUT', 1002);
define('OBS_SNMP_ERROR_BULK_REQUEST_TIMEOUT', 1004);
/*
foreach ($config['snmp']['errorcodes'] as $errorcode => $tmp) {
//$errorname = $tmp['name'];
// fast generate names:
$errorname = str_replace([ '.', ' ', '-' ], [ '', '_', '_' ], $tmp['reason']);
$errorname = 'OBS_SNMP_ERROR_'.strtoupper($errorname);
print_debug("define('$errorname', $errorcode);");
define($errorname, $errorcode);
}
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');
// 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');
// CLEANME. RANCID OS map (for config generation script)
/* MOVED to os definitions as $config['os'][$os]['rancid']
$config['rancid']['os_map']['arista_eos'] = 'arista';
//$config['rancid']['os_map']['avocent'] = 'avocent';
//$config['rancid']['os_map']['ciena-waveserveros'] = 'ciena-ws';
$config['rancid']['os_map']['cyclades'] = 'avocent';
$config['rancid']['os_map']['f5'] = 'f5'; // Only for <= v10
$config['rancid']['os_map']['fortigate'] = 'fortigate';
$config['rancid']['os_map']['ftos'] = 'force10';
$config['rancid']['os_map']['ios'] = 'cisco'; // ios in rancid 3.11+
$config['rancid']['os_map']['iosxe'] = 'cisco';
$config['rancid']['os_map']['iosxr'] = 'cisco-xr'; // ios-xr in rancid 3.11+
$config['rancid']['os_map']['asa'] = 'cisco';
$config['rancid']['os_map']['pixos'] = 'cisco';
$config['rancid']['os_map']['nxos'] = 'cisco-nx'; // ios-nx in rancid 3.11+
$config['rancid']['os_map']['ironware'] = 'foundry';
$config['rancid']['os_map']['junos'] = 'juniper'; // junos in rancid 3.11+
$config['rancid']['os_map']['screenos'] = 'netscreen';
$config['rancid']['os_map']['opengear'] = 'opengear';
$config['rancid']['os_map']['routeros'] = 'mikrotik'; // routeros in rancid 3.13+
$config['rancid']['os_map']['pfsense'] = 'pfsense';
$config['rancid']['os_map']['netscaler'] = 'netscaler';
// Rancid v3.0+ specific os map
//$config['rancid']['os_map_3']['adtran-aos'] = 'adtran';
$config['rancid']['os_map_3']['arbos'] = 'arbor';
$config['rancid']['os_map_3']['powerconnect-fastpath'] = 'dell';
$config['rancid']['os_map_3']['powerconnect-radlan'] = 'dell';
$config['rancid']['os_map_3']['dnos6'] = 'dell';
$config['rancid']['os_map_3']['enterasys'] = 'enterasys';
$config['rancid']['os_map_3']['xos'] = 'extreme';
//--$config['rancid']['os_map_3']['juniper-srx'] = 'juniper-srx'; // SRX in junos..
$config['rancid']['os_map_3']['mrvos'] = 'mrv';
$config['rancid']['os_map_3']['seos'] = 'redback';
// Rancid v3.2+ specific os map
//--$config['rancid']['os_map_3.2']['wlc'] = 'cisco-wlc4';
$config['rancid']['os_map_3.2']['wlc'] = 'cisco-wlc5';
$config['rancid']['os_map_3.2']['panos'] = 'paloalto';
$config['rancid']['os_map_3.2']['procurve'] = 'hp';
// Rancid v3.3+ specific os map
$config['rancid']['os_map_3.3']['ciena-waveserveros'] = 'ciena-ws';
$config['rancid']['os_map_3.3']['steelhead'] = 'riverbed';
// Rancid v3.4+ specific os map
$config['rancid']['os_map_3.4']['a10-ax'] = 'a10';
$config['rancid']['os_map_3.4']['a10-ex'] = 'a10';
// Rancid v3.5+ specific os map
$config['rancid']['os_map_3.5']['edgemax'] = 'edgemax';
//--$config['rancid']['os_map_3.5']['f5'] = 'bigip'; // v11+
// Rancid v3.7+ specific os map
$config['rancid']['os_map_3.7']['ciscosb'] = 'cisco-sb'; // ios-sb in rancid 3.11+
//--$config['rancid']['os_map_3.7']['wlc'] = 'cisco-wlc8';
$config['rancid']['os_map_3.7']['timos'] = 'sros'; // Classic CLI (TiMOS)
// Rancid v3.8+ specific os map
$config['rancid']['os_map_3.8']['cisco-fxos'] = 'fxos';
$config['rancid']['os_map_3.8']['vrp'] = 'vrp';
//--$config['rancid']['os_map_3.8']['f5'] = 'bigip13'; // v13+
//$config['rancid']['os_map_3.8']['timos'] = 'sros-md'; // MD-CLI (TiMOS) 7750 SR and 7950 XRS routers
// Rancid v3.9+ specific os map
//$config['rancid']['os_map_3.9']['arrcus'] = 'arcos'; // We not support this OS
// Rancid v3.11+ specific os map
//$config['rancid']['os_map_3.11']['ios-exr'] = 'ios-exr';
//$config['rancid']['os_map_3.11']['junos-evo'] = 'junos-evo';
// Rancid v3.13+ specific os map
//$config['rancid']['os_map_3.13']['axis-switch'] = 'axis';
//--$config['rancid']['os_map_3.13']['ios-xr7'] = 'ios-xr7'; // IOS XR 7+
*/
# Enable these (in config.php) if you added the powerconnect addon to your RANCID install
#$config['rancid']['os_map']['powerconnect-fastpath'] = 'dell';
#$config['rancid']['os_map']['powerconnect-radlan'] = 'dell';
#$config['rancid']['os_map']['dnos6'] = 'dell';
//////////////////////////////////////////////////////////////////////////
// No changes below this line // (no changes above it either, remember? //
//////////////////////////////////////////////////////////////////////////
// Include DB functions
define('OBS_DB_LINK', 'observium_link'); // Global variable name for DB link identifier, required for mysqli
define('OBS_DB_EXTENSION', 'mysqli'); // Old MySQL extension is deprecated since PHP 5.5, we unsupported it anymore
$config['db_extension'] = OBS_DB_EXTENSION;
/*
switch ($config['db_extension'])
{
case 'mysql':
define('OBS_DB_EXTENSION', $config['db_extension']);
print_error("MySQL extension is deprecated since PHP 5.5, we unsupported it anymore. Use mysqli extension instead!");
break;
case 'mysqli':
default:
define('OBS_DB_EXTENSION', 'mysqli');
}
*/
require_once($config['install_dir'] . "/includes/db.inc.php");
// Connect to database
if (OBS_DB_SKIP !== TRUE) {
$GLOBALS[OBS_DB_LINK] = dbOpen($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']);
}
// 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['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');
// Set some times needed by loads of scripts (it's dynamic, so we do it here!)
$config['time']['now'] = time();
$config['time']['fiveminute'] = $config['time']['now'] - 300; //time() - (5 * 60);
$config['time']['fourhour'] = $config['time']['now'] - 14400; //time() - (4 * 60 * 60);
$config['time']['sixhour'] = $config['time']['now'] - 21600; //time() - (6 * 60 * 60);
$config['time']['twelvehour'] = $config['time']['now'] - 43200; //time() - (12 * 60 * 60);
$config['time']['day'] = $config['time']['now'] - 86400; //time() - (24 * 60 * 60);
$config['time']['twoday'] = $config['time']['now'] - 172800; //time() - (2 * 24 * 60 * 60);
$config['time']['week'] = $config['time']['now'] - 604800; //time() - (7 * 24 * 60 * 60);
$config['time']['twoweek'] = $config['time']['now'] - 1209600; //time() - (2 * 7 * 24 * 60 * 60);
$config['time']['month'] = $config['time']['now'] - 2678400; //time() - (31 * 24 * 60 * 60);
$config['time']['twomonth'] = $config['time']['now'] - 5356800; //time() - (2 * 31 * 24 * 60 * 60);
$config['time']['threemonth'] = $config['time']['now'] - 8035200; //time() - (3 * 31 * 24 * 60 * 60);
$config['time']['sixmonth'] = $config['time']['now'] - 16070400; //time() - (6 * 31 * 24 * 60 * 60);
$config['time']['year'] = $config['time']['now'] - 31536000; //time() - (365 * 24 * 60 * 60);
$config['time']['twoyear'] = $config['time']['now'] - 63072000; //time() - (2 * 365 * 24 * 60 * 60);
$config['time']['threeyear'] = $config['time']['now'] - 94608000; //time() - (3 * 365 * 24 * 60 * 60);
// 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'][] = 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' => 'discovery_modules->cisco-vrf', 'new' => 'discovery_modules->vrf', 'info' => 'changed since 20.10.10792' ];
// do not keep in memory this setting, use get_defined_settings($key)
$config['hide_config'] = [
// SSH related
//'ssh_username', 'ssh_key', 'ssh_key_path', 'ssh_key_password',
// DB related
//'db_user', 'db_pass',
// Auth related
//'auth_radius_secret', 'auth_ldap_binddn', 'auth_ldap_bindpw',
// WMI related
//'wmi->user', 'wmi->pass',
];
// 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');
// End of includes/definitions.inc.php

Binary file not shown.

View File

@ -0,0 +1,12 @@
<?php
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');
//EOF

View File

@ -0,0 +1,370 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage definitions
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Definitions related to the Web UI
// WUI specific definitions, but can used in other code, like alert notifications
// Specific string for detect empty variable in web queries
define('OBS_VAR_UNSET', '[UNSET]');
// Default classes
define('OBS_CLASS_BOX', 'box box-solid');
define('OBS_CLASS_TABLE', 'table table-condensed');
// Combination of classes
define('OBS_CLASS_TABLE_BOX', OBS_CLASS_BOX . ' ' . OBS_CLASS_TABLE);
define('OBS_CLASS_TABLE_STRIPED', OBS_CLASS_TABLE . ' table-striped');
define('OBS_CLASS_TABLE_STRIPED_TWO', OBS_CLASS_TABLE . ' table-striped-two');
define('OBS_CLASS_TABLE_STRIPED_MORE', OBS_CLASS_TABLE . ' table-condensed-more table-striped');
// Colours
// FIXME, we still use this somewhere? :O
define('OBS_COLOUR_LIST_A', '#ffffff'); //$list_colour_a = "#ffffff";
define('OBS_COLOUR_LIST_B', '#eeeeee'); //$list_colour_b = "#eeeeee";
define('OBS_COLOUR_LIST_B_B', '#e3e3e3'); //$list_colour_b_b = "#e3e3e3";
define('OBS_COLOUR_LIST_HIGHLIGHT', '#ffcccc'); //$list_highlight = "#ffcccc";
define('OBS_COLOUR_WARN_A', '#ffeeee'); //$warn_colour_a = "#ffeeee";
define('OBS_COLOUR_WARN_B', '#ffcccc'); //$warn_colour_b = "#ffcccc";
/* After this line keep only WUI specific definitions, not required in cli! */
//if (is_cli()) { return; }
// List of allowed (un-escaped) tags in escape_html(): <tag>..</tag>, <br/>
$config['escape_html']['tags'] = []; // prevent change by config
$config['escape_html']['tags'][] = 'sup';
$config['escape_html']['tags'][] = 'sub';
$config['escape_html']['tags'][] = 'br';
// List of allowed (un-escaped) entities in escape_html(): &entity;
$config['escape_html']['entities'] = []; // prevent change by config
$config['escape_html']['entities'][] = 'deg'; // °
$config['escape_html']['entities'][] = 'omega'; // ω
$config['escape_html']['entities'][] = 'Omega'; // Ω
$config['escape_html']['entities'][] = 'mu'; // μ
$config['escape_html']['entities'][] = 'pi'; // π
$config['escape_html']['entities'][] = 'hellip'; // …
$config['escape_html']['entities'][] = 'mldr'; // …
$config['escape_html']['entities'][] = 'nldr'; // ‥
$config['escape_html']['entities'][] = 'plusmn'; // ±
$config['escape_html']['entities'][] = 'pm'; // ±
$config['escape_html']['entities'][] = 'micro'; // µ
// HEX/UNICODE entities (probably need more generic way, also for emoji)
$config['escape_html']['entities'][] = '#x200B'; // &#x200B; U+200B ZERO WIDTH SPACE (HTML &#8203;)
$config['escape_html']['entities'][] = '#8203'; // &#x200B; U+200B ZERO WIDTH SPACE (HTML &#8203;)
$config['pages']['gridstack']['no_panel'] = TRUE;
$config['pages']['dashboard']['no_panel'] = TRUE;
$config['pages']['map']['no_panel'] = TRUE;
// Refresh pages definitions
$config['wui']['refresh_times'] = array(0, 60, 120, 300, 900, 1800); // Allowed refresh times in seconds
// $vars array combination where auto-refresh page disabled by default
$config['wui']['refresh_disabled'][] = array('page' => 'dashboard');
$config['wui']['refresh_disabled'][] = array('page' => 'map');
$config['wui']['refresh_disabled'][] = array('page' => 'add_alert_check');
$config['wui']['refresh_disabled'][] = array('page' => 'alert_check');
$config['wui']['refresh_disabled'][] = array('page' => 'alert_regenerate');
$config['wui']['refresh_disabled'][] = array('page' => 'alert_maintenance_add');
$config['wui']['refresh_disabled'][] = array('page' => 'group_add');
$config['wui']['refresh_disabled'][] = array('page' => 'groups_regenerate');
$config['wui']['refresh_disabled'][] = array('page' => 'group', 'view' => 'edit');
$config['wui']['refresh_disabled'][] = array('page' => 'add_alertlog_rule');
$config['wui']['refresh_disabled'][] = array('page' => 'syslog_rules');
$config['wui']['refresh_disabled'][] = array('page' => 'add_syslog_rule');
$config['wui']['refresh_disabled'][] = array('page' => 'contact');
$config['wui']['refresh_disabled'][] = array('page' => 'contacts');
$config['wui']['refresh_disabled'][] = array('page' => 'bills', 'view' => 'add');
$config['wui']['refresh_disabled'][] = array('page' => 'bill', 'view' => 'edit');
$config['wui']['refresh_disabled'][] = array('page' => 'bill', 'view' => 'delete');
$config['wui']['refresh_disabled'][] = array('page' => 'device', 'tab' => 'data');
$config['wui']['refresh_disabled'][] = array('page' => 'device', 'tab' => 'edit');
$config['wui']['refresh_disabled'][] = array('page' => 'device', 'tab' => 'port', 'view' => 'realtime');
$config['wui']['refresh_disabled'][] = array('page' => 'device', 'tab' => 'showconfig');
$config['wui']['refresh_disabled'][] = array('page' => 'device', 'tab' => 'entphysical'); // Inventory
$config['wui']['refresh_disabled'][] = array('page' => 'addhost');
$config['wui']['refresh_disabled'][] = array('page' => 'delhost');
$config['wui']['refresh_disabled'][] = array('page' => 'delsrv');
$config['wui']['refresh_disabled'][] = array('page' => 'deleted-ports');
$config['wui']['refresh_disabled'][] = array('page' => 'adduser');
$config['wui']['refresh_disabled'][] = array('page' => 'edituser');
$config['wui']['refresh_disabled'][] = array('page' => 'settings');
$config['wui']['refresh_disabled'][] = array('page' => 'preferences');
$config['wui']['refresh_disabled'][] = array('page' => 'logout');
$config['wui']['refresh_disabled'][] = array('page' => 'customoids');
$config['wui']['refresh_disabled'][] = array('page' => 'log');
$config['wui']['refresh_disabled'][] = array('page' => 'pollers');
// Search modules used by the ajax search, in order.
$config['wui']['search_modules'] = [ 'groups', 'devices', 'accesspoints', 'ports', 'slas', 'sensors', 'status', 'neighbours',
'ip-addresses', 'inventory', 'loadbalancers' ];
// Default groups list (on status page and default panel)
//$config['wui']['groups_list'] = array('device', 'port', 'processor', 'mempool', 'sensor', 'bgp_peer');
$config['wui']['groups_list'] = array('device', 'port', 'processor', 'mempool', 'sensor');
// Themes (dark not exist in community edition)
$config['themes']['light'] = array('name' => "Light Mode", 'type' => 'light', 'css' => 'observium.css', 'icon' => 'sprite-sun');
$config['themes']['dark'] = array('name' => "Dark Mode", 'type' => 'dark', 'css' => 'observium-dark.css', 'icon' => 'sprite-moon');
$config['themes']['darkblue'] = array('name' => "Dark Blue Mode", 'type' => 'dark', 'css' => 'observium-darkblue.css', 'icon' => 'sprite-moon');
// Define Icons used by the user interface, emoji icons see in emoji.inc.php
$config['icon']['globe'] = "sprite-globe";
$config['icon']['overview'] = "sprite-overview";
$config['icon']['settings-change'] = "sprite-sliders-2";
$config['icon']['config'] = "sprite-config";
$config['icon']['logout'] = "sprite-logout";
$config['icon']['plus'] = "sprite-plus";
$config['icon']['minus'] = "sprite-minus";
$config['icon']['success'] = "sprite-success";
$config['icon']['error'] = "sprite-error";
$config['icon']['important'] = "sprite-important";
$config['icon']['stop'] = "sprite-cancel";
$config['icon']['cancel'] = "sprite-cancel";
$config['icon']['help'] = "sprite-support";
$config['icon']['info'] = "sprite-info";
$config['icon']['exclamation'] = "sprite-exclamation-mark";
$config['icon']['critical'] = $config['icon']['exclamation']; // red exclamation mark in a circle
$config['icon']['warning'] = $config['icon']['error']; // yellow exclamation mark in a triangle
$config['icon']['informational'] = $config['icon']['info']; // blue exclamation mark in a circle
$config['icon']['flag'] = "sprite-flag";
$config['icon']['plus'] = "sprite-plus";
$config['icon']['export'] = "sprite-export";
$config['icon']['minus'] = "sprite-minus";
$config['icon']['filter'] = "sprite-funnel";
$config['icon']['question'] = "sprite-question";
$config['icon']['checked'] = "sprite-checked";
$config['icon']['ok'] = "sprite-ok";
$config['icon']['return'] = "sprite-return";
$config['icon']['sort'] = "sprite-sort";
$config['icon']['network'] = "sprite-routing";
$config['icon']['up'] = $config['icon']['checked'];
$config['icon']['down'] = $config['icon']['minus'];
// what is this joke? ignore/shutdown :)
$config['icon']['ignore'] = "sprite-shutdown";
$config['icon']['shutdown'] = "sprite-ignore";
$config['icon']['percent'] = "sprite-percent";
$config['icon']['or-gate'] = "sprite-logic-or";
$config['icon']['and-gate'] = "sprite-logic-and";
$config['icon']['ipv4'] = "sprite-ipv4";
$config['icon']['ipv6'] = "sprite-ipv6";
$config['icon']['connected'] = "sprite-connected";
$config['icon']['cross-connect'] = "sprite-cross-connect";
$config['icon']['merge'] = "sprite-merge";
$config['icon']['split'] = "sprite-split";
$config['icon']['group'] = "sprite-groups";
$config['icon']['groups'] = $config['icon']['group'];
$config['icon']['alert'] = "sprite-alert";
$config['icon']['alert-log'] = "sprite-alert-log";
$config['icon']['alert-rules'] = "sprite-alert-rules";
$config['icon']['alert-rule-add'] = $config['icon']['plus'];
$config['icon']['scheduled-maintenance'] = "sprite-scheduled-maintenance";
$config['icon']['scheduled-maintenance-add'] = $config['icon']['plus'];
$config['icon']['syslog'] = "sprite-syslog";
$config['icon']['syslog-alerts'] = "sprite-syslog-alerts";
$config['icon']['syslog-rules'] = "sprite-syslog-rules";
$config['icon']['syslog-rule-add'] = $config['icon']['plus'];
$config['icon']['eventlog'] = "sprite-eventlog";
$config['icon']['pollerlog'] = "sprite-performance";
$config['icon']['pollers'] = "sprite-module";
$config['icon']['processes'] = "sprite-processes";
$config['icon']['netmap'] = "sprite-netmap";
$config['icon']['contacts'] = "sprite-mail";
$config['icon']['contact-add'] = $config['icon']['plus'];
$config['icon']['customoid'] = "sprite-customoid";
$config['icon']['customoid-add'] = $config['icon']['plus'];
$config['icon']['inventory'] = "sprite-inventory";
$config['icon']['package'] = "sprite-package";
$config['icon']['packages'] = "sprite-package";
$config['icon']['search'] = "sprite-search";
$config['icon']['devices'] = "sprite-devices";
$config['icon']['device'] = "sprite-device";
$config['icon']['device-delete'] = $config['icon']['minus'];
$config['icon']['location'] = "sprite-building";
$config['icon']['locations'] = $config['icon']['location'];
$config['icon']['port'] = "sprite-ethernet";
$config['icon']['port-core'] = "sprite-hub";
$config['icon']['port-customer'] = "sprite-user-self";
$config['icon']['port-transit'] = "sprite-transit";
$config['icon']['port-peering'] = "sprite-peering";
$config['icon']['port-peering-transit'] = "sprite-peering-transit";
$config['icon']['health'] = "sprite-health";
$config['icon']['processor'] = "sprite-processor";
$config['icon']['mempool'] = "sprite-mempool";
$config['icon']['storage'] = "sprite-database";
$config['icon']['diskio'] = "sprite-storage-io";
$config['icon']['printersupply'] = "sprite-printer-supplies";
$config['icon']['status'] = "sprite-status";
$config['icon']['sensor'] = "sprite-performance";
$config['icon']['sla'] = "sprite-sla";
$config['icon']['pseudowire'] = "sprite-cross-connect";
$config['icon']['virtual-machine'] = "sprite-virtual-machine";
$config['icon']['antenna'] = "sprite-antenna";
$config['icon']['p2pradio'] = "sprite-antenna";
$config['icon']['billing'] = "sprite-accounting";
$config['icon']['neighbours'] = "sprite-neighbours";
$config['icon']['cbqos'] = "sprite-qos";
$config['icon']['voltage'] = "sprite-voltage";
$config['icon']['pressure'] = "sprite-pressure";
$config['icon']['frequency'] = "sprite-frequency";
$config['icon']['dbm'] = "sprite-laser";
$config['icon']['counter'] = "sprite-counter";
$config['icon']['fanspeed'] = "sprite-fanspeed";
$config['icon']['current'] = "sprite-amps";
$config['icon']['power'] = "sprite-watts";
$config['icon']['illuminance'] = "sprite-light-bulb";
$config['icon']['load'] = "sprite-asterisk";
$config['icon']['progress'] = "sprite-percent";
$config['icon']['temperature'] = "sprite-temperature";
$config['icon']['humidity'] = "sprite-humidity";
$config['icon']['airflow'] = "sprite-airflow";
$config['icon']['current'] = "sprite-amps";
$config['icon']['apower'] = "sprite-voltamps";
$config['icon']['rpower'] = "sprite-voltampreactive";
$config['icon']['crestfactor'] = "sprite-lightning";
$config['icon']['powerfactor'] = "sprite-lightning";
$config['icon']['impedance'] = "sprite-ohms-2";
$config['icon']['resistance'] = "sprite-ohms";
$config['icon']['velocity'] = "sprite-performance";
$config['icon']['waterflow'] = "sprite-flowrate";
$config['icon']['volume'] = "sprite-volume";
$config['icon']['distance'] = "sprite-distance";
$config['icon']['lflux'] = "sprite-light-bulb";
$config['icon']['clock'] = "sprite-clock";
$config['icon']['fiber'] = "sprite-laser"; // FIXME need other icon
$config['icon']['wavelength'] = "sprite-laser"; // FIXME need other icon
$config['icon']['gauge'] = "sprite-data"; // FIXME need other icon
$config['icon']['distance'] = "sprite-distance";
// Status classes
$config['icon']['battery'] = "sprite-capacity";
$config['icon']['mains'] = "sprite-network";
$config['icon']['outlet'] = "sprite-power";
$config['icon']['linkstate'] = $config['icon']['port'];
$config['icon']['fan'] = $config['icon']['fanspeed'];
$config['icon']['blower'] = $config['icon']['airflow'];
$config['icon']['chassis'] = "sprite-nic"; // FIXME need other icon
$config['icon']['contact'] = "sprite-connected"; // FIXME need other icon
$config['icon']['output'] = "sprite-merge"; // FIXME need other icon
$config['icon']['powersupply'] = "sprite-power"; // FIXME need other icon
$config['icon']['rectifier'] = "sprite-frequency-2"; // FIXME need other icon
$config['icon']['service'] = "sprite-service";
$config['icon']['servicegroup'] = $config['icon']['service'];
$config['icon']['vserver'] = "sprite-device";
$config['icon']['runtime'] = "sprite-runtime";
$config['icon']['apps'] = "sprite-applications";
$config['icon']['capacity'] = "sprite-capacity";
$config['icon']['collectd'] = "sprite-collectd";
$config['icon']['munin'] = "sprite-munin";
$config['icon']['smokeping'] = "sprite-paper-plane";
$config['icon']['wifi'] = "sprite-wifi";
$config['icon']['hypervisor'] = "sprite-virtual-machine";
$config['icon']['logs'] = "sprite-logs";
$config['icon']['loadbalancer'] = "sprite-loadbalancer-2";
$config['icon']['routing'] = "sprite-routing";
$config['icon']['vrf'] = "sprite-vrf";
$config['icon']['cef'] = "sprite-cef";
$config['icon']['ospf'] = "sprite-ospf";
$config['icon']['eigrp'] = "sprite-eigrp";
$config['icon']['ipsec_tunnel'] = "sprite-tunnel";
$config['icon']['vlan'] = "sprite-vlan";
$config['icon']['switching'] = "sprite-switching";
$config['icon']['crossbar'] = $config['icon']['switching'];
$config['icon']['nfsen'] = "sprite-funnel";
$config['icon']['device-data'] = "sprite-data";
$config['icon']['device-poller'] = "sprite-performance";
$config['icon']['techsupport'] = "sprite-support";
$config['icon']['tools'] = "sprite-tools";
$config['icon']['device-tools'] = "sprite-cog";
$config['icon']['device-settings'] = "sprite-settings-3";
$config['icon']['hardware'] = "sprite-cogs"; // FIXME
$config['icon']['linecard'] = "sprite-nic";
$config['icon']['firewall'] = "sprite-firewall";
$config['icon']['settings'] = "sprite-settings";
$config['icon']['refresh'] = "sprite-refresh";
$config['icon']['rebuild'] = $config['icon']['refresh'];
$config['icon']['graphs'] = "sprite-graphs";
$config['icon']['graphs-line'] = "sprite-graphs-line";
$config['icon']['graphs-stacked'] = "sprite-graphs-stacked";
$config['icon']['graphs-small'] = "sprite-graphs-small";
$config['icon']['graphs-large'] = "sprite-graphs-large";
$config['icon']['bgp'] = "sprite-bgp";
$config['icon']['bgp-internal'] = "sprite-bgp-internal";
$config['icon']['bgp-external'] = "sprite-bgp-external";
$config['icon']['bgp-alert'] = "sprite-bgp-alerts";
$config['icon']['bgp-afi'] = "sprite-bgp-afi";
$config['icon']['users'] = "sprite-users";
$config['icon']['user-self'] = "sprite-user-self";
$config['icon']['user-add'] = "sprite-user-add";
$config['icon']['user-delete'] = "sprite-user-delete";
$config['icon']['user-edit'] = "sprite-user-edit";
$config['icon']['user-log'] = "sprite-user-log";
$config['icon']['lock'] = "sprite-lock";
//$config['icon']['database'] = "sprite-storage-test2";
$config['icon']['databases'] = "sprite-databases";
$config['icon']['database'] = "sprite-database";
$config['icon']['mibs'] = "sprite-map-2";
$config['icon']['notes'] = "sprite-note";
// Font icons
$config['icon']['info-sign'] = "icon-info-sign";
$config['icon']['edit'] = "icon-cog";
$config['icon']['delete'] = "icon-trash";
$config['icon']['add'] = "icon-plus-sign";
$config['icon']['remove'] = "icon-minus-sign";
$config['icon']['arrow-up'] = "icon-circle-arrow-up";
$config['icon']['arrow-down'] = "icon-circle-arrow-down";
$config['icon']['arrow-right'] = "icon-circle-arrow-right";
$config['icon']['arrow-left'] = "icon-circle-arrow-left";
$config['icons'] = [ 'sprite-device', 'sprite-network', 'sprite-virtual-machine' ];
// EOF

View File

@ -0,0 +1,188 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
// IP-MIB contains two tables:
// ipNetToMediaTable -- deprecated, as it contains only entries for IPv4.
// ipNetToPhysicalTable -- current, address version agnostic table
// IPV6-MIB has been abandoned in favor of the revised IP-MIB, but has one table:
// ipv6NetToMediaTable
// CISCO-IETF-IP-MIB -- based on an early draft of the revised IP-MIB
// cInetNetToMediaTable
unset($mac_table);
// Caching ifIndex
$query = 'SELECT `port_id`, `ifIndex` FROM `ports` WHERE `device_id` = ? GROUP BY `port_id`';
foreach (dbFetchRows($query, array($device['device_id'])) as $entry) {
$entry_if = $entry['ifIndex'];
$interface[$entry_if] = $entry['port_id'];
}
/// FIXME. Here necessary to use snmpwalk_cache_oid, but snmpwalk_cache_oid() not support custom options like (-OXqs) for parser. -- mike
/// Duplicate the function to use -OX. The SNMP specific stuff is all elsewhere, so shouldn't be too much duplicated -- adama
// FIXME check is_device_mib first!
// First check IP-MIB::ipNetToPhysicalPhysAddress (IPv4 & IPv6)
//ipNetToPhysicalPhysAddress[5][ipv4]["80.93.52.129"] 0:23:ab:64:d:42
//ipNetToPhysicalPhysAddress[34][ipv6]["2a:01:00:d8:00:00:00:01:00:00:00:00:00:00:00:03"] 0:15:63:e8:fb:31:0:0
$ipNetToPhysicalPhysAddress_oid = snmp_walk($device, 'ipNetToPhysicalPhysAddress', '-OXqs', 'IP-MIB');
if ($ipNetToPhysicalPhysAddress_oid)
{
$oid_data = $ipNetToPhysicalPhysAddress_oid;
print_debug("Used IP-MIB::ipNetToPhysicalPhysAddress");
} else {
$oid_data = '';
if ($device['os_group'] === 'cisco')
{
// Last check CISCO-IETF-IP-MIB::cInetNetToMediaPhysAddress (IPv6 only, Cisco only)
//cInetNetToMediaPhysAddress[167][ipv6]["20:01:0b:08:0b:08:0b:08:00:00:00:00:00:00:00:b1"] 0:24:c4:db:9b:40:0:0
$cInetNetToMediaPhysAddress_oid = snmp_walk($device, 'cInetNetToMediaPhysAddress', '-OXqs', 'CISCO-IETF-IP-MIB');
if ($cInetNetToMediaPhysAddress_oid)
{
$oid_data .= $cInetNetToMediaPhysAddress_oid;
print_debug("Used CISCO-IETF-IP-MIB::cInetNetToMediaPhysAddress");
}
} else {
// Or check IPV6-MIB::ipv6NetToMediaPhysAddress (IPv6 only, deprecated, junos)
//ipv6NetToMediaPhysAddress[18][fe80:0:0:0:200:ff:fe00:4] 2:0:0:0:0:4
$ipv6NetToMediaPhysAddress_oid = snmp_walk($device, 'ipv6NetToMediaPhysAddress', '-OXqs', 'IPV6-MIB');
if ($ipv6NetToMediaPhysAddress_oid)
{
$oid_data .= $ipv6NetToMediaPhysAddress_oid;
print_debug("Used IPV6-MIB::ipv6NetToMediaPhysAddress");
}
}
}
if (!strstr($oid_data, 'ipv4'))
{
// Check IP-MIB::ipNetToMediaPhysAddress (IPv4 only)
//ipNetToMediaPhysAddress[213][10.0.0.162] 70:81:5:ec:f9:bf
$ipNetToMediaPhysAddress_oid = snmp_walk($device, 'ipNetToMediaPhysAddress', '-OXqs', 'IP-MIB');
if ($ipNetToMediaPhysAddress_oid)
{
$oid_data .= $ipNetToMediaPhysAddress_oid;
print_debug("Used IP-MIB::ipNetToMediaPhysAddress");
}
}
$oid_data = trim($oid_data);
// Caching old ARP/NDP table
$query = 'SELECT mac_id, mac_address, ip_address, ip_version, ifIndex FROM ip_mac AS M
LEFT JOIN ports AS I ON M.port_id = I.port_id
WHERE I.device_id = ?';
$cache_arp = dbFetchRows($query, array($device['device_id']));
foreach ($cache_arp as $entry)
{
$old_if = $entry['ifIndex'];
$old_mac = $entry['mac_address'];
$old_address = $entry['ip_address'];
$old_version = $entry['ip_version'];
$old_table[$old_if][$old_version][$old_address] = $old_mac;
}
$ipv4_pattern = '/\[(\d+)\](?:\[ipv4\])?\["?([\d\.]+)"?\]\s+([a-f\d]+):([a-f\d]+):([a-f\d]+):([a-f\d]+):([a-f\d]+):([a-f\d]{1,2})/i';
$ipv6_pattern = '/\[(\d+)\](?:\[ipv6\])?\["?([a-f\d:]+)"?\]\s+(?:([a-f\d]+):([a-f\d]+):)?([a-f\d]+):([a-f\d]+):([a-f\d]+):([a-f\d]{1,2})/i';
foreach (explode("\n", $oid_data) as $data)
{
if (preg_match($ipv4_pattern, $data, $matches))
{
$ip = $matches[2];
$ip_version = 4;
}
elseif (preg_match($ipv6_pattern, $data, $matches))
{
if (count(explode(':', $matches[2])) === 8)
{
$ip = Net_IPv6::uncompress($matches[2], TRUE);
}
else
{
$ip = hex2ip($matches[2]);
}
$ip_version = 6;
} else {
// In principle the such shouldn't be.
continue;
}
$if = $matches[1];
$port_id = $interface[$if];
if ($ip && $port_id)
{
if ($matches[3] === '' && $matches[4] === '')
{
// Convert IPv4 to fake MAC for 6to4 tunnels
//ipNetToPhysicalPhysAddress[27][ipv6]["20:02:c0:58:63:01:00:00:00:00:00:00:00:00:00:00"] 0:0:c0:58
$matches[3] = 'ff';
$matches[4] = 'fe';
}
$mac = zeropad($matches[3]);
for ($i = 4; $i <= 8; $i++) { $mac .= ':' . zeropad($matches[$i]); }
$clean_mac = str_replace(':', '', $mac);
$mac_table[$if][$ip_version][$ip] = $clean_mac;
if (isset($old_table[$if][$ip_version][$ip]))
{
$old_mac = $old_table[$if][$ip_version][$ip];
if ($clean_mac != $old_mac && $clean_mac != '00:00:00:00:00:00' && $old_mac != '00:00:00:00:00:00')
{
print_debug("Changed MAC address for $ip from ".format_mac($old_mac)." to ".format_mac($clean_mac));
log_event("MAC changed: $ip : " . format_mac($old_mac) . " -> " . format_mac($clean_mac), $device, "port", $port_id);
dbUpdate(array('mac_address' => $clean_mac) , 'ip_mac', 'port_id = ? AND ip_address = ?', array($port_id, $ip));
echo("U");
} else {
echo(".");
}
} else {
$params = array(
'port_id' => $port_id,
'mac_address' => $clean_mac,
'ip_address' => $ip,
'ip_version' => $ip_version);
dbInsert($params, 'ip_mac');
print_debug("Added MAC address ".format_mac($clean_mac)." for $ip");
//log_event("MAC added: $ip : " . format_mac($clean_mac), $device, "port", $port_id);
echo("+");
}
}
}
// Remove expired ARP/NDP entries
$remove_mac_ids = array();
foreach ($cache_arp as $entry)
{
$entry_mac_id = $entry['mac_id'];
$entry_mac = $entry['mac_address'];
$entry_ip = $entry['ip_address'];
$entry_version = $entry['ip_version'];
$entry_if = $entry['ifIndex'];
$entry_port_id = $interface[$entry_if];
if (!isset($mac_table[$entry_if][$entry_version][$entry_ip]))
{
$remove_mac_ids[] = $entry_mac_id;
//dbDelete('ip_mac', 'mac_id = ?', array($entry_mac_id));
print_debug("Removed MAC address ".format_mac($entry_mac)." for $entry_ip");
//log_event("MAC removed: $entry_ip : " . format_mac($entry_mac), $device, "port", $entry['port_id']);
echo("-");
}
}
if (count($remove_mac_ids))
{
dbDelete('ip_mac', '1' . generate_query_values($remove_mac_ids, 'mac_id'));
}
echo(PHP_EOL);
unset($interface, $remove_mac_ids);
// EOF

View File

@ -0,0 +1,407 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// 'BGP4-MIB', 'CISCO-BGP4-MIB', 'BGP4-V2-MIB-JUNIPER', 'FORCE10-BGP4-V2-MIB', 'ARISTA-BGP4V2-MIB', 'FOUNDRY-BGP4V2-MIB', 'HUAWEI-BGP-VPN-MIB'
if (!$config['enable_bgp'] || !is_device_mib($device, 'BGP4-MIB')) {
// Note, BGP4-MIB is main MIB, without it, the rest will not be checked
if ($device['bgpLocalAs']) {
// Clean old discovered peers?
log_event('BGP Local ASN removed: AS' . $device['bgpLocalAs'], $device, 'device', $device['device_id']);
dbUpdate([ 'bgpLocalAs' => [ 'NULL' ] ], 'devices', 'device_id = ?', [ $device['device_id'] ]);
print_cli_data("Updated ASN", $device['bgpLocalAs'] . " -> ''", 2);
}
return;
}
/* Moved to definitions
$vendor_oids = array(
// Juniper BGP4-V2 MIB
'BGP4-V2-MIB-JUNIPER' => array('vendor_use_index' => array('jnxBgpM2PeerRemoteAddr' => 1,
'jnxBgpM2PeerRemoteAddrType' => 1,
'jnxBgpM2PeerLocalAddr' => 1),
'vendor_PeerTable' => 'jnxBgpM2PeerTable',
'vendor_PeerAdminStatus' => 'jnxBgpM2PeerStatus', //'jnxBgpM2CfgPeerAdminStatus' not exist in JunOS
'vendor_PeerRemoteAs' => 'jnxBgpM2PeerRemoteAs',
'vendor_PeerRemoteAddr' => 'jnxBgpM2PeerRemoteAddr',
'vendor_PeerLocalAddr' => 'jnxBgpM2PeerLocalAddr',
'vendor_PeerLocalAs' => 'jnxBgpM2PeerLocalAs',
'vendor_PeerIdentifier' => 'jnxBgpM2PeerIdentifier',
'vendor_PeerIndex' => 'jnxBgpM2PeerIndex',
'vendor_PeerRemoteAddrType' => 'jnxBgpM2PeerRemoteAddrType',
'vendor_PrefixCountersSafi' => 'jnxBgpM2PrefixCountersSafi'),
// Force10 BGP4-V2 MIB
'FORCE10-BGP4-V2-MIB' => array('vendor_PeerTable' => 'f10BgpM2PeerTable',
'vendor_PeerAdminStatus' => 'f10BgpM2PeerStatus',
'vendor_PeerRemoteAs' => 'f10BgpM2PeerRemoteAs',
'vendor_PeerRemoteAddr' => 'f10BgpM2PeerRemoteAddr',
'vendor_PeerLocalAddr' => 'f10BgpM2PeerLocalAddr',
'vendor_PeerLocalAs' => 'f10BgpM2PeerLocalAs',
'vendor_PeerIdentifier' => 'f10BgpM2PeerIdentifier',
'vendor_PeerIndex' => 'f10BgpM2PeerIndex',
'vendor_PeerRemoteAddrType' => 'f10BgpM2PeerRemoteAddrType',
'vendor_PrefixCountersSafi' => 'f10BgpM2PrefixCountersSafi'),
// Arista BGP4-V2 MIB
'ARISTA-BGP4V2-MIB' => array('vendor_use_index' => array('aristaBgp4V2PeerRemoteAddr' => 1,
'aristaBgp4V2PeerRemoteAddrType' => 1),
'vendor_PeerTable' => 'aristaBgp4V2PeerTable',
'vendor_PeerAdminStatus' => 'aristaBgp4V2PeerAdminStatus',
'vendor_PeerRemoteAs' => 'aristaBgp4V2PeerRemoteAs',
'vendor_PeerRemoteAddr' => 'aristaBgp4V2PeerRemoteAddr',
'vendor_PeerLocalAddr' => 'aristaBgp4V2PeerLocalAddr',
'vendor_PeerLocalAs' => 'aristaBgp4V2PeerLocalAs',
'vendor_PeerIdentifier' => 'aristaBgp4V2PeerRemoteIdentifier',
'vendor_PeerIndex' => '',
'vendor_PeerRemoteAddrType' => 'aristaBgp4V2PeerRemoteAddrType',
'vendor_PrefixCountersSafi' => 'aristaBgp4V2PrefixInPrefixes'),
# PrefixCountersSafi is not-accessible in draft-13, but we
# only use the INDEX from it, so use aristaBgp4V2PrefixInPrefixes.
// Brocade BGP4-V2 MIB
'FOUNDRY-BGP4V2-MIB' => array('vendor_use_index' => array('bgp4V2PeerRemoteAddr' => 1,
'bgp4V2PeerRemoteAddrType' => 1,
'bgp4V2PeerLocalAddr' => 1),
'vendor_PeerTable' => 'bgp4V2PeerTable',
'vendor_PeerAdminStatus' => 'bgp4V2PeerAdminStatus',
'vendor_PeerRemoteAs' => 'bgp4V2PeerRemoteAs',
'vendor_PeerRemoteAddr' => 'bgp4V2PeerRemoteAddr',
'vendor_PeerLocalAddr' => 'bgp4V2PeerLocalAddr',
'vendor_PeerLocalAs' => 'bgp4V2PeerLocalAs',
'vendor_PeerIdentifier' => 'bgp4V2PeerRemoteIdentifier',
'vendor_PeerIndex' => '',
'vendor_PeerRemoteAddrType' => 'bgp4V2PeerRemoteAddrType',
'vendor_PrefixCountersSafi' => 'bgp4V2PrefixInPrefixes'),
# PrefixCountersSafi is not-accessible in draft-13, but we
# only use the INDEX from it, so use bgp4V2PrefixInPrefixes.
'HUAWEI-BGP-VPN-MIB' => array('vendor_use_index' => array('hwBgpPeerRemoteAddr' => 1,
'hwBgpPeerRemoteAddrType' => 1,
'hwBgpPeerRemoteIdentifier' => 1,
'hwBgpPeerAdminStatus' => 1,
'afi' => 'hwBgpPeerAddrFamilyAfi',
'safi' => 'hwBgpPeerAddrFamilySafi'),
'vendor_PeerTable' => 'hwBgpPeerTable',
'vendor_PeerAdminStatus' => 'hwBgpPeerAdminStatus', // really not exist, always set to start if entry exist
'vendor_PeerRemoteAs' => 'hwBgpPeerRemoteAs',
'vendor_PeerRemoteAddr' => 'hwBgpPeerRemoteAddr',
'vendor_PeerLocalAddr' => '',
'vendor_PeerLocalAs' => '',
'vendor_PeerIdentifier' => 'hwBgpPeerRemoteIdentifier', // really not exist, use hwBgpPeerRemoteAddr
'vendor_PeerIndex' => '',
'vendor_PeerRemoteAddrType' => 'hwBgpPeerRemoteAddrType',
'vendor_PrefixCountersSafi' => 'hwBgpPeerPrefixActiveCounter'), # we only use the INDEX from it
);
*/
// Get Local ASN
// Get array with exist MIBs on device with LocasAs-es
$local_as_array = get_bgp_localas_array($device);
$vendor_mib = FALSE; // CLEANME. Clear after full rewrite to definitions.
$bgpVrfLocalAs = [];
foreach ($local_as_array as $entry) {
// CLEANME. Clear after full rewrite to definitions.
if ($entry['mib'] !== 'BGP4-MIB' && $entry['mib'] !== 'CISCO-BGP4-MIB') {
$vendor_mib = $entry['mib'];
}
// LocalAs by first non-zero
if ($entry['LocalAs'] != 0) {
if (!isset($bgpLocalAs) &&
$entry['oid'] !== 'cbgpPeer2LocalAs') {
// Do not use Cisco Peer LocalAs as device bgp, see https://jira.observium.org/browse/OBS-4116
$bgpLocalAs = $entry['LocalAs'];
}
if (isset($entry['virtual_name']) && !isset($bgpVrfLocalAs[$entry['virtual_name']])) {
// Set per vrf LocalAs
$bgpVrfLocalAs[$entry['virtual_name']] = $entry['LocalAs'];
}
}
}
// Discover BGP peers
/// NOTE. PeerIdentifier != PeerRemoteAddr
if (is_numeric($bgpLocalAs) && $bgpLocalAs != 0) {
print_cli_data("Local AS", "AS$bgpLocalAs ", 2);
// Detect if Local AS changed
if ($bgpLocalAs != $device['bgpLocalAs']) {
if (!$device['bgpLocalAs']) {
log_event('BGP Local ASN added: AS' . $bgpLocalAs, $device, 'device', $device['device_id']);
} elseif (!$bgpLocalAs) {
log_event('BGP Local ASN removed: AS' . $device['bgpLocalAs'], $device, 'device', $device['device_id']);
} else {
log_event('BGP ASN changed: AS' . $device['bgpLocalAs'] . ' -> AS' . $bgpLocalAs, $device, 'device', $device['device_id']);
}
dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id = ?', array($device['device_id']));
print_cli_data("Updated ASN", $device['bgpLocalAs'] . " -> $bgpLocalAs", 2);
}
print_cli_data_field("Caching");
// Init
$p_list = []; // valid_peers
$peerlist = [];
$af_list = [];
foreach ($local_as_array as $entry) {
$mib = $entry['mib'];
echo("$mib ");
if ($check_vrfs = isset($entry['virtual_name'])) {
// Keep original
$device_original = $device;
$bgpLocalAs_original = $bgpLocalAs;
if (isset($bgpVrfLocalAs[$entry['virtual_name']])) {
// Need in per VRF discovery
$bgpLocalAs = $bgpVrfLocalAs[$entry['virtual_name']];
}
$vrf_name = $entry['virtual_name'];
$snmp_virtual = $entry['snmp_context'];
// Set device for VRF tables
$device = snmp_virtual_device($device_original, $snmp_virtual);
echo("(Virtual Routing $vrf_name) ");
}
/* Start caching bgp peers */
$include = __DIR__ . '/bgp/' . strtolower($mib) . '.inc.php';
if (!is_file($include)) {
// Common for vendor mibs
$include = __DIR__ . '/bgp/bgp4v2-mib.inc.php';
}
include $include;
/* End caching bgp peers */
if ($check_vrfs) {
// Restore device array
$device = $device_original;
$bgpLocalAs = $bgpLocalAs_original;
}
}
} else {
echo("No BGP on host");
if (is_numeric($device['bgpLocalAs'])) {
log_event('BGP ASN removed: AS' . $device['bgpLocalAs'], $device, 'device', $device['device_id']);
dbUpdate(array('bgpLocalAs' => array('NULL')), 'devices', 'device_id = ?', array($device['device_id']));
print_message('Removed ASN (' . $device['bgpLocalAs'] . ')');
} # End if
} # End if
// Process discovered peers
global $table_rows;
$table_rows = array();
if (safe_count($peerlist)) {
print_debug_vars($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_devices = [];
$peer_devices_ids = [];
foreach (dbFetchRows('SELECT `device_id`, `bgpPeerLocalAddr`, `bgpPeerRemoteAddr` FROM `bgpPeers` WHERE `bgpPeerRemoteAs` = ?' . $peer_as_where, [ $bgpLocalAs ]) as $entry) {
$peer_devices[$entry['bgpPeerLocalAddr']][$entry['bgpPeerRemoteAddr']] = $entry['device_id'];
$peer_devices_ids[] = $entry['device_id'];
}
print_debug_vars($peer_devices);
$peer_ip_where = generate_query_values($peer_devices_ids, 'device_id') . generate_query_values('up', 'ifOperStatus');
foreach ($peerlist as $peer) {
$astext = get_astext($peer['as']);
$reverse_dns = gethostbyaddr6($peer['ip']);
if ($reverse_dns == $peer['ip']) {
unset($reverse_dns);
}
// Search remote device if possible
$peer_addr_version = get_ip_version($peer['ip']);
$peer_addr_type = get_ip_type($peer['ip']);
$peer_local_type = get_ip_type($peer['local_ip']);
$peer_device_id = [ 'NULL' ];
if (!in_array($peer_addr_type, [ 'unspecified', 'loopback' ]) &&
!in_array($peer_local_type, [ 'unspecified', 'loopback' ])) {
//if ($tmp_id = dbFetchCell('SELECT `device_id` FROM `bgpPeers` WHERE `bgpPeerLocalAddr` = ? AND `bgpPeerRemoteAs` = ? AND `bgpPeerRemoteAddr` = ?' . $peer_as_where, array($peer['ip'], $bgpLocalAs, $peer['local_ip'])))
print_debug("bgpPeerLocalAddr: ".$peer['ip'].", bgpPeerRemoteAddr: ".$peer['local_ip']);
if (isset($peer_devices[$peer['ip']][$peer['local_ip']])) {
// Simple search remote device by Local IP and Local AS and Remote IP
//$peer_device_id = $tmp_id;
$peer_device_id = $peer_devices[$peer['ip']][$peer['local_ip']];
} elseif ($ids = get_entity_ids_ip_by_network('device', $peer['ip'], $peer_ip_where)) {
// Fetch all devices with peer IP
// Peer device will found if device UP and NOT DISABLED, port with IP is UP, bgpLocalAs present on remote device
$peer_device_id = array_shift($ids);
/*
foreach($ids as $tmp_id)
{
//if (dbFetchCell('SELECT COUNT(*) FROM `bgpPeers` WHERE `device_id` = ? AND `bgpPeerRemoteAs` = ?', array($tmp_id, $bgpLocalAs)))
if (dbExist('bgpPeers', '`device_id` = ? AND `bgpPeerRemoteAs` = ?', array($tmp_id, $bgpLocalAs)))
{
// Validate if bgpLocalAs also present on remote device
$peer_device_id = $tmp_id;
break; // Found, stop loop
}
}
*/
}
}
if (is_numeric($peer_device_id)) {
$peer_device = device_by_id_cache($peer_device_id);
} else {
unset($peer_device);
}
//$peer['local_as'] = (isset($peer['local_as']) && $peer['local_as'] != 0 && $peer['local_as'] != '') ? $peer['local_as'] : $bgpLocalAs;
$local_as = $peer['local_as'];
$virtual_name = [ 'NULL' ];
if (isset($peer['virtual_name'])) {
$local_as .= ' ('.$peer['virtual_name'].')';
$virtual_name = $peer['virtual_name'];
}
$table_rows[$peer['ip']] = [ $local_as, $peer['local_ip'], $peer['as'], $peer['ip'], '', $reverse_dns, truncate($peer_device['hostname'], 30) ];
$params = [
'device_id' => $device['device_id'],
'bgpPeerIdentifier' => $peer['identifier'],
'bgpPeerRemoteAddr' => $peer['ip'],
'bgpPeerLocalAddr' => $peer['local_ip'],
'local_as' => $peer['local_as'],
'bgpPeerRemoteAs' => $peer['as'],
'astext' => $astext,
'reverse_dns' => $reverse_dns,
'virtual_name' => $virtual_name,
'peer_device_id' => $peer_device_id
];
$peer_db = dbFetchRow('SELECT * FROM `bgpPeers` WHERE `device_id` = ? AND `bgpPeerRemoteAddr` = ?', [ $device['device_id'], $peer['ip'] ]);
if (safe_count($peer_db)) {
$update_array = [];
foreach ($params as $param => $value) {
if ($value === [ 'NULL' ]) {
if ($peer_db[$param] != '') {
$update_array[$param] = $value;
}
} elseif ($value != $peer_db[$param]) {
$update_array[$param] = $value;
}
}
if (count($update_array)) {
dbUpdate($update_array, 'bgpPeers', '`device_id` = ? AND `bgpPeerRemoteAddr` = ?', [ $device['device_id'], $peer['ip'] ]);
if (isset($update_array['reverse_dns']) && count($update_array) === 1) {
// Do not count updates if changed only reverse DNS
$GLOBALS['module_stats'][$module]['unchanged']++;
} else {
$GLOBALS['module_stats'][$module]['updated']++;
}
} else {
$GLOBALS['module_stats'][$module]['unchanged']++;
}
$peer_id = $peer_db['bgpPeer_id'];
} else {
$peer_id = dbInsert($params, 'bgpPeers');
$GLOBALS['module_stats'][$module]['added']++;
}
$peer['id'] = $peer_id;
$peer_ids[$peer['ip']] = $peer_id;
// AFI/SAFI for specific vendors
if (isset($peer_afis[$peer['ip']])) {
$peer_index = $peer['index']; // keep original
foreach ($peer_afis[$peer['ip']] as $af_entry) {
$peer['index'] = isset($af_entry['index']) ? $af_entry['index'] : $peer_index;
discovery_bgp_afisafi($device, $peer, $af_entry['afi'], $af_entry['safi'], $af_list);
}
$peer['index'] = $peer_index; // restore
}
// Autodiscovery for bgp neighbours
if ($config['autodiscovery']['bgp']) {
if (($peer['as'] == $device['bgpLocalAs']) || // ASN matches local router
($config['autodiscovery']['bgp_as_private'] && is_bgp_as_private($peer['as'])) || // ASN is private
(is_array($config['autodiscovery']['bgp_as_whitelist']) && in_array($peer['as'], $config['autodiscovery']['bgp_as_whitelist']))) { // ASN is in bgp_as_whitelist
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $peer['id']);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($peer['id'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscover
$remote_device_id = autodiscovery_device($peer['id'], NULL, 'BGP', NULL, $device);
}
}
}
} # Foreach
// Remove deleted AFI/SAFI
unset($afi, $safi, $peer_ip, $peer_id);
$cbgp_delete = [];
$query = 'SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ?';
foreach (dbFetchRows($query, [ $device['device_id'] ]) as $entry) {
$peer_id = $entry['bgpPeer_id'];
$afi = $entry['afi'];
$safi = $entry['safi'];
$cbgp_id = $entry['cbgp_id'];
if (!isset($af_list[$peer_id][$afi][$safi])) {
$cbgp_delete[] = $cbgp_id;
//dbDelete('bgpPeers_cbgp', '`cbgp_id` = ?', array($cbgp_id));
}
} # AF list
if (safe_count($cbgp_delete)) {
// Multi-delete
dbDelete('bgpPeers_cbgp', generate_query_values($cbgp_delete, 'cbgp_id', NULL, FALSE));
}
unset($af_list, $cbgp_delete);
} # end peerlist
// Delete removed peers
unset($peer_ip, $peer_as);
$peers_delete = [];
$query = 'SELECT * FROM `bgpPeers` WHERE `device_id` = ?';
foreach (dbFetchRows($query, [ $device['device_id'] ]) as $entry) {
$peer_ip = $entry['bgpPeerRemoteAddr'];
$peer_as = $entry['bgpPeerRemoteAs'];
if (!isset($p_list[$peer_ip][$peer_as])) {
// dbDelete('bgpPeers', '`bgpPeer_id` = ?', [ $entry['bgpPeer_id'] ]);
$peers_delete[] = $entry['bgpPeer_id'];
$GLOBALS['module_stats'][$module]['deleted']++;
} else {
// Unset, for exclude duplicate entries in DB
unset($p_list[$peer_ip][$peer_as]);
}
}
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));
}
$table_headers = array('%WLocal: AS (VRF)%n', '%WIP%n', '%WPeer: AS%n', '%WIP%n', '%WFamily%n', '%WrDNS%n', '%WRemote Device%n');
print_cli_table($table_rows, $table_headers);
unset($p_list, $peerlist, $vendor_mib, $cisco_version, $cisco_peers, $table_rows, $table_headers, $peer_devices, $peer_devices_ids);
// EOF

View File

@ -0,0 +1,76 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
/**
* @var array $device
* @var string $mib
* @var array $entry
* @var string $bgpLocalAs
* @var integer $cisco_version Come from cisco-bgp4-mib.inc.php
* @var array $p_list
* @var array $peerlist
* @var bool $check_vrfs
* @var string $vrf_name
*/
// All MIBs except CISCO-BGP4-MIB (table version 2)
if (isset($cisco_version) && $cisco_version > 1) {
return;
}
if (is_device_mib($device, 'CUMULUS-BGPUN-MIB')) {
// CUMULUS-BGPUN-MIB is copy-paste of BGP4-MIB
return;
}
$peers_data = snmpwalk_cache_oid($device, 'bgpPeerRemoteAs', [], 'BGP4-MIB');
//$peers_data = snmpwalk_cache_oid($device, 'bgpPeerRemoteAddr', $peers_data, 'BGP4-MIB');
$peers_data = snmpwalk_cache_oid($device, 'bgpPeerLocalAddr', $peers_data, 'BGP4-MIB');
$peers_data = snmpwalk_cache_oid($device, 'bgpPeerIdentifier', $peers_data, 'BGP4-MIB');
$peers_data = snmpwalk_cache_oid($device, 'bgpPeerAdminStatus', $peers_data, 'BGP4-MIB');
foreach ($peers_data as $index => $bgp4_entry) {
$index_parts = explode('.', $index);
if (safe_count($index_parts) > 4) {
// Aruba case:
// BGP4-MIB::bgpPeerRemoteAddr.4.18.1.23.109 = IpAddress: 18.1.23.109
$ip_len = array_shift($index_parts);
$peer_ip = implode('.', $index_parts);
} else {
$peer_ip = $index;
}
$peer_as = snmp_dewrap32bit($bgp4_entry['bgpPeerRemoteAs']); // Dewrap for 32bit ASN
if ($peer_as > $bgp4_entry['bgpPeerRemoteAs']) {
$peers_data[$index]['bgpPeerRemoteAs'] = $peer_as;
}
$local_ip = $bgp4_entry['bgpPeerLocalAddr'];
$peer = [
'mib' => $mib,
'index' => $index,
'identifier' => $bgp4_entry['bgpPeerIdentifier'],
'local_ip' => $local_ip,
'ip' => $peer_ip === '0.0.0.0' ? '' : $peer_ip,
'local_as' => $bgpLocalAs,
'as' => $peer_as,
'admin_status' => $bgp4_entry['bgpPeerAdminStatus']
];
if ($check_vrfs) {
$peer['virtual_name'] = $vrf_name;
}
if (!isset($p_list[$peer_ip][$peer_as]) && is_bgp_peer_valid($peer, $device)) {
print_debug("Found peer IP: $peer_ip (AS$peer_as, LocalIP: $local_ip)");
$peerlist[] = $peer;
$p_list[$peer_ip][$peer_as] = 1;
}
}
// EOF

View File

@ -0,0 +1,224 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
/**
* @var array $config
* @var array $device
* @var string $mib
* @var array $entry
* @var string $bgpLocalAs
* @var array $peers_data from BGP4-MIB
* @var array $p_list
* @var array $peerlist
* @var bool $check_vrfs
* @var string $vrf_name
*/
// Common vendor specific
$def = $config['mibs'][$mib]['bgp'];
$vendor_mib = $mib;
$vendor_bgp = snmpwalk_cache_oid($device, $def['oids']['PeerRemoteAs']['oid'], [], $vendor_mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
if (safe_empty($vendor_bgp)) {
$vendor_mib = FALSE; // Unset vendor_mib since not found on device
return;
}
// PeerRemoteAddr
$vendor_oid = $def['oids']['PeerRemoteAddr']['oid'];
if (!isset($def['index'][$vendor_oid])) {
$vendor_bgp = snmpwalk_cache_oid($device, $vendor_oid, $vendor_bgp, $vendor_mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
}
// PeerLocalAddr
$local_ips = [];
$vendor_oid = $def['oids']['PeerLocalAddr']['oid'];
if (!isset($def['index'][$vendor_oid]) && strlen($vendor_oid)) {
$vendor_bgp = snmpwalk_cache_oid($device, $vendor_oid, $vendor_bgp, $vendor_mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
} else {
// LocalAddr trick, when not available in vendor table, by known device ip/network
foreach (dbFetchRows('SELECT * FROM `ipv4_addresses` LEFT JOIN `ipv4_networks` USING(`ipv4_network_id`) WHERE `device_id` = ?', [ $device['device_id'] ]) as $ipv4) {
$local_ips['ipv4'][$ipv4['ipv4_address']] = $ipv4['ipv4_network'];
}
foreach (dbFetchRows('SELECT * FROM `ipv6_addresses` LEFT JOIN `ipv6_networks` USING(`ipv6_network_id`) WHERE `device_id` = ?', [ $device['device_id'] ]) as $ipv6) {
$local_ips['ipv6'][$ipv6['ipv6_address']] = $ipv6['ipv6_network'];
}
print_debug_vars($local_ips);
}
// PeerIdentifier
$vendor_oid = $def['oids']['PeerIdentifier']['oid'];
if (!isset($def['index'][$vendor_oid]) && !safe_empty($vendor_oid)) {
$vendor_bgp = snmpwalk_cache_oid($device, $vendor_oid, $vendor_bgp, $vendor_mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
}
// PeerLocalAs
$vendor_oid = $def['oids']['PeerLocalAs']['oid'];
if (!isset($def['index'][$vendor_oid]) && !safe_empty($vendor_oid)) {
$vendor_bgp = snmpwalk_cache_oid($device, $vendor_oid, $vendor_bgp, $vendor_mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
}
// PeerAdminStatus
$vendor_oid = $def['oids']['PeerAdminStatus']['oid'];
if (!isset($def['index'][$vendor_oid]) && !safe_empty($vendor_oid)) {
$vendor_bgp = snmpwalk_cache_oid($device, $vendor_oid, $vendor_bgp, $vendor_mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
}
// PeerRemoteAddrType
$vendor_oid = $def['oids']['PeerRemoteAddrType']['oid'];
if (!isset($def['index'][$vendor_oid])) {
$vendor_bgp = snmpwalk_cache_oid($device, $vendor_oid, $vendor_bgp, $vendor_mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
}
// PeerIndex
$vendor_oid = $def['oids']['PeerIndex']['oid'];
if (!isset($def['index'][$vendor_oid]) && !safe_empty($vendor_oid)) {
$vendor_bgp = snmpwalk_cache_oid($device, $vendor_oid, $vendor_bgp, $vendor_mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
}
// PrefixCountersSafi
$vendor_oid = $def['oids']['PrefixCountersSafi']['oid'];
if (!safe_empty($vendor_oid)) {
$vendor_counters = snmpwalk_cache_oid($device, $vendor_oid, [], $vendor_mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
} else {
$vendor_counters = NULL;
}
//print_vars($vendor_counters);
// See possible AFI/SAFI here: https://www.juniper.net/techpubs/en_US/junos12.3/topics/topic-map/bgp-multiprotocol.html
$afis['1'] = 'ipv4';
$afis['2'] = 'ipv6';
$afis['ipv4'] = '1';
$afis['ipv6'] = '2';
//print_vars($vendor_bgp);
print_debug("$vendor_mib Peers: ");
foreach ($vendor_bgp as $idx => $vendor_entry) {
if (!safe_empty($def['index'])) {
parse_bgp_peer_index($vendor_entry, $idx, $vendor_mib);
}
$peer_ip = hex2ip($vendor_entry[$def['oids']['PeerRemoteAddr']['oid']]);
$peer_addr_type = 'ipv' . get_ip_version($peer_ip);
$local_ip = '';
if (strlen($def['oids']['PeerLocalAddr']['oid'])) {
$local_ip = hex2ip($vendor_entry[$def['oids']['PeerLocalAddr']['oid']]);
} elseif (isset($local_ips[$peer_addr_type])) {
// Trick for detect local ip by matching between device IPs network and peer ip
// Actually for Huawei BGP peers
foreach ($local_ips[$peer_addr_type] as $ip => $network) {
if (match_network($peer_ip, $network)) {
$local_ip = $ip;
print_debug("Local IP: $ip. Matched Peer IP [$peer_ip] with device network [$network].");
break;
}
}
}
$local_as = isset($vendor_entry[$def['oids']['PeerLocalAs']['oid']]) ? snmp_dewrap32bit($vendor_entry[$def['oids']['PeerLocalAs']['oid']]) : $bgpLocalAs;
$peer_as = $vendor_entry[$def['oids']['PeerRemoteAs']['oid']];
// index
$vendor_oid = $def['oids']['PeerIndex']['oid'];
if (empty($vendor_oid)) {
$index = $idx;
} else {
$index = $vendor_entry[$vendor_oid];
}
$peer = [
'mib' => $mib,
'index' => $index,
'identifier' => $vendor_entry[$def['oids']['PeerIdentifier']['oid']],
'local_ip' => $local_ip,
'local_as' => $local_as,
'ip' => $peer_ip === '0.0.0.0' ? '' : $peer_ip,
'as' => $peer_as,
'admin_status' => $vendor_entry[$def['oids']['PeerAdminStatus']['oid']]
];
if ($check_vrfs) {
$peer['virtual_name'] = $vrf_name;
}
if (!isset($p_list[$peer_ip][$peer_as]) && is_bgp_peer_valid($peer, $device)) {
// Fix possible 32bit ASN for peers from BGP4-MIB
// Brocade example:
// BGP4-MIB::bgpPeerRemoteAs.27.122.122.4 = 23456
// FOUNDRY-BGPV2-MIB::bgp4V2PeerRemoteAs.1.1.4.27.122.122.5.1.4.27.122.122.4 = 133189
if (isset($p_list[$peer_ip])) {
unset($p_list[$peer_ip]); // Clean old peer list
$bgp4_peer_as = $peers_data[$peer_ip]['bgpPeerRemoteAs']; // BGP4-MIB
if ($peer_as > $bgp4_peer_as) {
//$peers_data[$peer_ip]['bgpPeerRemoteAs'] = $peer_as;
// Yah, need to found and remove duplicate peer from $peerlist
foreach ($peerlist as $key => $tmp) {
if ($tmp['ip'] == $peer_ip && $tmp['as'] == $bgp4_peer_as) {
unset($peerlist[$key]);
break;
}
}
}
}
$p_list[$peer_ip][$peer_as] = 1;
$peerlist[] = $peer;
print_debug("Found peer IP: $peer_ip (AS$peer_as, LocalIP: $local_ip)");
} elseif (isset($p_list[$peer_ip][$peer_as]) && $local_as != $bgpLocalAs) {
// Find and replace local_as key in peer list if different local as
// FIXME, Yah, $peerlist stored as simple array without indexed key, that why used derp per-peer loop
foreach ($peerlist as $key => $tmp) {
if ($tmp['ip'] == $peer_ip && $tmp['as'] == $peer_as) {
$peerlist[$key]['local_as'] = $local_as;
print_debug("Replaced Local AS for peer: $peer_ip (AS$peer_as, LocalIP: $local_ip) - AS$bgpLocalAs -> AS$local_as");
break;
}
}
} else {
print_debug("Vendor peer already found: $peer_ip");
print_debug_vars($peer);
}
// AFI/SAFI
$vendor_oid = isset($def['index']['afi']) ? $def['index']['afi'] : $def['oids']['PeerRemoteAddrType']['oid'];
$afi = $vendor_entry[$vendor_oid];
if (isset($def['index']['safi'])) {
$safi = $vendor_entry[$def['index']['safi']];
// Here each table entry is uniq afi/safi, see HUAWEI-BGP-VPN-MIB
if (isset($vendor_counters[$index])) {
//$peer_afis[$peer_ip][$afi][$safi] = 1;
$peer_afis[$peer_ip][] = [ 'afi' => $afi, 'safi' => $safi, 'index' => $index ];
//discovery_bgp_afisafi($device, $entry, $afi, $safi, $af_list);
}
continue;
}
if ($vendor_mib === 'VIPTELA-OPER-BGP') {
// This mib has only one possible AFI/SAFI
if (isset($vendor_counters[$index.'.0'])) {
//$peer_afis[$peer_ip][$afi][$safi] = 1;
$peer_afis[$peer_ip][] = [ 'afi' => 'ipv4', 'safi' => 'unicast' ];
}
continue;
}
// Here can be multiple table entries for different afi/safi
foreach ($config['routing_safis'] as $i => $safi_def) {
$safi = $safi_def['name'];
if (is_numeric($afi)) {
$afi_num = $afi;
$afi = $config['routing_afis'][$afi]['name'];
} else {
$afi_num = $config['routing_afis_name'][$afi];
}
if (isset($vendor_counters["$index.$afi_num.$i"])) {
//$peer_afis[$peer_ip][$afi][$safi] = 1;
$peer_afis[$peer_ip][] = [ 'afi' => $afi, 'safi' => $safi, 'index' => $index ];
//discovery_bgp_afisafi($device, $entry, $afi, $safi, $af_list);
} else {
print_debug("Did not find AFI/SAFI with index $index.$afi_num.$i");
}
}
}
// EOF

View File

@ -0,0 +1,136 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
/**
* @var array $device
* @var string $mib
* @var array $entry
* @var string $bgpLocalAs
* @var array $p_list
* @var array $peerlist
* @var bool $check_vrfs
* @var string $vrf_name
*/
$cisco_version = $entry['cisco_version'];
if ($cisco_version < 2) {
// Get afi/safi and populate cbgp on cisco ios (xe/xr)
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyName', [], 'CISCO-BGP4-MIB');
} else {
// Check Cisco cbgpPeer2Table
$cisco_peers = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', [], 'CISCO-BGP4-MIB');
$cisco_peers = snmpwalk_cache_oid($device, 'cbgpPeer2LocalAddr', $cisco_peers, 'CISCO-BGP4-MIB');
// Cisco vendor mib LocalAddr issue:
// cbgpPeer2LocalAddr.ipv4."10.0.1.1" = "0B 8E 95 38 " --> 11.142.149.56
// but should:
// bgpPeerLocalAddr.10.0.1.1 = 10.0.1.3
// Yah, Cisco you again added extra work for me? What mean this random numbers?
$cisco_fix = snmpwalk_cache_oid($device, 'bgpPeerLocalAddr', [], 'BGP4-MIB');
$cisco_peers = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteIdentifier', $cisco_peers, 'CISCO-BGP4-MIB');
$cisco_peers = snmpwalk_cache_oid($device, 'cbgpPeer2AdminStatus', $cisco_peers, 'CISCO-BGP4-MIB');
$cisco_peers = snmpwalk_cache_oid($device, 'cbgpPeer2LocalAs', $cisco_peers, 'CISCO-BGP4-MIB');
print_debug("CISCO-BGP4-MIB Peers: ");
foreach ($cisco_peers as $index => $cisco_entry) {
list(, $peer_ip) = explode('.', $index, 2);
$peer_ip = hex2ip($peer_ip);
if (isset($cisco_fix[$peer_ip]) && strlen($cisco_fix[$peer_ip]['bgpPeerLocalAddr'])) {
// Fix incorrect IPv4 local IPs
$local_ip = $cisco_fix[$peer_ip]['bgpPeerLocalAddr'];
} else {
$local_ip = hex2ip($cisco_entry['cbgpPeer2LocalAddr']);
}
$peer_as = $cisco_entry['cbgpPeer2RemoteAs'];
$local_as = snmp_dewrap32bit($cisco_entry['cbgpPeer2LocalAs']);
if ($local_as == 0) {
// Per session local ASN can be zero if session down
$local_as = $bgpLocalAs;
}
$peer = [
'mib' => $mib,
'index' => $index,
'identifier' => $cisco_entry['cbgpPeer2RemoteIdentifier'],
'local_ip' => $local_ip,
'local_as' => $local_as,
'ip' => $peer_ip === '0.0.0.0' ? '' : $peer_ip,
'as' => $peer_as,
'admin_status' => $cisco_entry['cbgpPeer2AdminStatus']
];
if ($check_vrfs) {
$peer['virtual_name'] = $vrf_name;
}
if (!isset($p_list[$peer_ip][$peer_as]) && is_bgp_peer_valid($peer, $device)) {
$p_list[$peer_ip][$peer_as] = 1;
$peerlist[] = $peer;
print_debug("Found peer IP: $peer_ip (AS$peer_as, LocalIP: $local_ip)");
} elseif (isset($p_list[$peer_ip][$peer_as]) && $local_as != $bgpLocalAs) {
// Find and replace local_as key in peer list if different local as
// FIXME, Yah, $peerlist stored as simple array without indexed key, that why used derp per-peer loop
foreach ($peerlist as $key => $tmp) {
if ($tmp['ip'] == $peer_ip && $tmp['as'] == $peer_as) {
$peerlist[$key]['local_as'] = $local_as;
print_debug("Replaced Local AS for peer: $peer_ip (AS$peer_as, LocalIP: $local_ip) - AS$bgpLocalAs -> AS$local_as");
break;
}
}
}
}
// Get afi/safi and populate cbgp on cisco ios (xe/xr)
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyName', [], 'CISCO-BGP4-MIB');
}
// Process AFI/SAFI
foreach ($af_data as $af => $af_entry) {
if ($cisco_version === 2) {
list(, $af) = explode('.', $af, 2);
$text = $af_entry['cbgpPeer2AddrFamilyName'];
} else {
$text = $af_entry['cbgpPeerAddrFamilyName'];
}
$afisafi = explode('.', $af);
$c = count($afisafi);
$afi = $afisafi[$c - 2];
$safi = $afisafi[$c - 1];
$peer_ip = hex2ip(str_replace(".$afi.$safi", '', $af));
print_debug("Peer IP: $peer_ip, AFI: $afi, SAFI: $safi");
if ($afi && $safi) {
//$peer_afis[$peer_ip][$afi][$safi] = $text;
$peer_afis[$peer_ip][] = [ 'afi' => $afi, 'safi' => $safi ];
/*
if (strlen($table_rows[$peer_ip][4]))
{
$table_rows[$peer_ip][4] .= ', ';
}
$table_rows[$peer_ip][4] .= $afi . '.' . $safi;
$peer_id = $peer_ids[$peer_ip];
$af_list[$peer_id][$afi][$safi] = 1;
//if (dbFetchCell('SELECT COUNT(*) FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND `bgpPeer_id` = ? AND `afi` = ? AND `safi` = ?', array($device['device_id'], $peer_id, $afi, $safi)) == 0)
if (!dbExist('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeer_id` = ? AND `afi` = ? AND `safi` = ?', array($device['device_id'], $peer_id, $afi, $safi)))
{
$params = [ 'device_id' => $device['device_id'], 'bgpPeer_id' => $peer_id, 'afi' => $afi, 'safi' => $safi ];
dbInsert($params, 'bgpPeers_cbgp');
}
*/
}
}
// EOF

View File

@ -0,0 +1,88 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
/**
* @var array $device
* @var string $mib
* @var array $entry
* @var string $bgpLocalAs
* @var array $p_list
* @var array $peerlist
* @var bool $check_vrfs
* @var string $vrf_name
*/
// CUMULUS-BGPUN-MIB::bgpPeerState.192.168.0.1 = INTEGER: established(6)
// CUMULUS-BGPUN-MIB::bgpPeerState.192.168.0.5 = INTEGER: established(6)
// CUMULUS-BGPUN-MIB::bgpPeerAdminStatus.192.168.0.1 = INTEGER: start(2)
// CUMULUS-BGPUN-MIB::bgpPeerAdminStatus.192.168.0.5 = INTEGER: start(2)
// CUMULUS-BGPUN-MIB::bgpPeerLocalAddr.192.168.0.1 = STRING: "fe80::e04:1fff:fe86:1"
// CUMULUS-BGPUN-MIB::bgpPeerLocalAddr.192.168.0.5 = STRING: "192.168.125.2"
// CUMULUS-BGPUN-MIB::bgpPeerRemoteAs.192.168.0.1 = INTEGER: 65000
// CUMULUS-BGPUN-MIB::bgpPeerRemoteAs.192.168.0.5 = INTEGER: 65005
// CUMULUS-BGPUN-MIB::bgpPeerInUpdates.192.168.0.1 = Counter32: 6
// CUMULUS-BGPUN-MIB::bgpPeerInUpdates.192.168.0.5 = Counter32: 6
// CUMULUS-BGPUN-MIB::bgpPeerOutUpdates.192.168.0.1 = Counter32: 6
// CUMULUS-BGPUN-MIB::bgpPeerOutUpdates.192.168.0.5 = Counter32: 6
// CUMULUS-BGPUN-MIB::bgpPeerInTotalMessages.192.168.0.1 = Counter32: 32629
// CUMULUS-BGPUN-MIB::bgpPeerInTotalMessages.192.168.0.5 = Counter32: 32629
// CUMULUS-BGPUN-MIB::bgpPeerOutTotalMessages.192.168.0.1 = Counter32: 32629
// CUMULUS-BGPUN-MIB::bgpPeerOutTotalMessages.192.168.0.5 = Counter32: 32629
// CUMULUS-BGPUN-MIB::bgpPeerLastError.192.168.0.1 = Hex-STRING: 00 00
// CUMULUS-BGPUN-MIB::bgpPeerLastError.192.168.0.5 = Hex-STRING: 00 00
// CUMULUS-BGPUN-MIB::bgpPeerFsmEstablishedTime.192.168.0.1 = Gauge32: 97875
// CUMULUS-BGPUN-MIB::bgpPeerFsmEstablishedTime.192.168.0.5 = Gauge32: 97875
// CUMULUS-BGPUN-MIB::bgpPeerInUpdateElapsedTime.192.168.0.1 = Gauge32: 11473
// CUMULUS-BGPUN-MIB::bgpPeerInUpdateElapsedTime.192.168.0.5 = Gauge32: 11473
// CUMULUS-BGPUN-MIB::bgpPeerIface.192.168.0.1 = STRING: "swp1"
// CUMULUS-BGPUN-MIB::bgpPeerIface.192.168.0.5 = STRING: "192.168.125.254"
$peers_data = snmpwalk_cache_oid($device, 'bgpPeerRemoteAs', [], 'CUMULUS-BGPUN-MIB');
//$peers_data = snmpwalk_cache_oid($device, 'bgpPeerRemoteAddr', $peers_data, 'CUMULUS-BGPUN-MIB');
$peers_data = snmpwalk_cache_oid($device, 'bgpPeerLocalAddr', $peers_data, 'CUMULUS-BGPUN-MIB');
$peers_data = snmpwalk_cache_oid($device, 'bgpPeerIface', $peers_data, 'CUMULUS-BGPUN-MIB');
$peers_data = snmpwalk_cache_oid($device, 'bgpPeerAdminStatus', $peers_data, 'CUMULUS-BGPUN-MIB');
foreach ($peers_data as $index => $bgp4_entry) {
$peer_ip = $index;
$peer_as = snmp_dewrap32bit($bgp4_entry['bgpPeerRemoteAs']); // Dewrap for 32bit ASN
if ($peer_as > $bgp4_entry['bgpPeerRemoteAs']) {
$peers_data[$index]['bgpPeerRemoteAs'] = $peer_as;
}
$local_ip = $bgp4_entry['bgpPeerLocalAddr'];
// Add bgpPeerIdentifier
//$bgp4_entry['bgpPeerIdentifier'] = get_ip_version($bgp4_entry['bgpPeerIface']) ? $bgp4_entry['bgpPeerIface'] : $index;
$bgp4_entry['bgpPeerIdentifier'] = $index;
$peers_data[$index]['bgpPeerIdentifier'] = $bgp4_entry['bgpPeerIdentifier'];
$peer = [
'mib' => $mib,
'index' => $index,
'identifier' => $bgp4_entry['bgpPeerIdentifier'],
'local_ip' => $local_ip,
'ip' => $peer_ip === '0.0.0.0' ? '' : $peer_ip,
'local_as' => $bgpLocalAs,
'as' => $peer_as,
'admin_status' => $bgp4_entry['bgpPeerAdminStatus']
];
if ($check_vrfs) {
$peer['virtual_name'] = $vrf_name;
}
if (!isset($p_list[$peer_ip][$peer_as]) && is_bgp_peer_valid($peer, $device)) {
print_debug("Found peer IP: $peer_ip (AS$peer_as, LocalIP: $local_ip)");
$peerlist[] = $peer;
$p_list[$peer_ip][$peer_as] = 1;
}
}
// EOF

View File

@ -0,0 +1,126 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// Check if QoS exists on the host
$query = 'SELECT * FROM `ports_cbqos`';
$query .= ' WHERE `device_id` = ?';
$cbq_db = dbFetchRows($query, array($device['device_id']));
foreach ($cbq_db as $cbq) { $cbq_table[$cbq['policy_index']][$cbq['object_index']] = $cbq; }
// Walk the first service policies OID and then see if it was populated before we continue
$service_policies = array(); // This ends up being indexed by cbQosPolicyIndex
$service_policies = snmpwalk_cache_oid($device, "cbQosIfType", $service_policies, 'CISCO-CLASS-BASED-QOS-MIB');
if (count($service_policies))
{
$table_rows = array();
// Continue populating service policies
$service_policies = snmpwalk_cache_oid($device, "cbQosPolicyDirection", $service_policies, 'CISCO-CLASS-BASED-QOS-MIB');
$service_policies = snmpwalk_cache_oid($device, "cbQosIfIndex", $service_policies, 'CISCO-CLASS-BASED-QOS-MIB');
$policy_maps = snmpwalk_cache_oid($device, "cbQosPolicyMapCfgEntry", array(), 'CISCO-CLASS-BASED-QOS-MIB');
$class_maps = snmpwalk_cache_oid($device, "cbQosCMCfgEntry", array(), 'CISCO-CLASS-BASED-QOS-MIB');
$object_indexes = snmpwalk_cache_twopart_oid($device, "cbQosObjectsEntry", array(), 'CISCO-CLASS-BASED-QOS-MIB');
# print_r($policy_maps);
# print_r($class_maps);
# print_r($object_indexes);
$cm_stats = array();
// $oids = array('cbQosCMPrePolicyPkt64','cbQosCMPrePolicyByte64', 'cbQosCMPostPolicyByte64', 'cbQosCMDropPkt64', 'cbQosCMDropByte64', 'cbQosCMNoBufDropPkt64');
$oids = array('cbQosCMPrePolicyPkt64');
foreach ($oids as $oid)
{
$cm_stats = snmpwalk_cache_twopart_oid($device, $oid, $cm_stats, 'CISCO-CLASS-BASED-QOS-MIB');
}
foreach ($cm_stats as $policy_index => $policy_entry)
{
foreach ($policy_entry as $object_index => $object_entry)
{
$port = get_port_by_ifIndex($device['device_id'], $service_policies[$policy_index]['cbQosIfIndex']);
$object_entry['port_id'] = $port['port_id'];
$object_entry['direction'] = $service_policies[$policy_index]['cbQosPolicyDirection'];
$object_entry['policy_index'] = $policy_index;
$object_entry['object_index'] = $object_index;
$object_entry['cm_cfg_index'] = $object_indexes[$policy_index][$object_index]['cbQosConfigIndex'];
$object_entry['pm_cfg_index'] = $object_indexes[$policy_index][$policy_index]['cbQosConfigIndex'];
// Loop the entries for this policy and get the policy configuration id. This is messy. This MIB sucks. Also sometimes the indexing format changes (!)
foreach ($object_indexes[$policy_index] AS $object_data)
{
# print_vars($object_data);
if ($object_data['cbQosObjectsType'] == 'policymap') { $object_entry['pm_cfg_index'] = $object_data['cbQosConfigIndex']; }
}
$object_entry['policy_name'] = $policy_maps[$object_entry['pm_cfg_index']]['cbQosPolicyMapName'];
$object_entry['policy_desc'] = $policy_maps[$object_entry['pm_cfg_index']]['cbQosPolicyMapDesc'];
$object_entry['cm_name'] = $class_maps[$object_entry['cm_cfg_index']]['cbQosCMName'];
$object_entry['cm_desc'] = $class_maps[$object_entry['cm_cfg_index']]['cbQosCMDesc'];
$object_entry['cm_info'] = $class_maps[$object_entry['cm_cfg_index']]['cbQosCMInfo'];
if ($object_entry['policy_index'] == '1995099406' ) { print_vars($object_entry); }
if (!isset($cbq_table[$policy_index][$object_index]))
{
dbInsert(array('device_id' => $device['device_id'], 'port_id' => $port['port_id'], 'policy_index' => $policy_index, 'object_index' => $object_index, 'direction' => $object_entry['direction'], 'object_name' => $object_entry['cm_name'], 'policy_name' => $object_entry['policy_name']), 'ports_cbqos');
//echo("+");
$cbq_table[$policy_index][$object_index] = dbFetchRow("SELECT * FROM `ports_cbqos` WHERE `device_id` = ? AND `port_id` = ? AND `policy_index` = ? AND `object_index` = ?",
array($device['device_id'], $port['port_id'], $policy_index, $object_index));
} else {
if ($cbq_table[$policy_index][$object_index]['policy_name'] != $object_entry['policy_name'] || $cbq_table[$policy_index][$object_index]['object_name'] != $object_entry['cm_name']) {
dbUpdate(array('object_name' => $object_entry['cm_name'], 'policy_name' => $object_entry['policy_name']), 'ports_cbqos', '`device_id` = ? AND `port_id` = ? AND `policy_index` = ? AND `object_index` = ?', array($device['device_id'], $port['port_id'], $policy_index, $object_index));
//echo("U");
}
unset($cbq_table[$policy_index][$object_index]);
}
$table_row = array();
$table_row[] = $port['port_label_short'];
$table_row[] = $object_entry['policy_name'];
$table_row[] = $object_entry['cm_name'];
$table_row[] = $object_entry['direction'];
$table_rows[] = $table_row;
unset($table_row);
}
}
$headers = array('%WPort%n', '%WPolicy%n', '%WObject%n', '%WDir%n');
print_cli_table($table_rows, $headers);
} // End check if QoS is enabled before we walk everything
else
{
echo 'QoS not configured.', PHP_EOL;
}
foreach($cbq_table AS $policy => $objects)
{
foreach($objects AS $object_name => $object)
{
dbDelete('ports_cbqos', '`cbqos_id` = ?', array($object['cbqos_id'])); echo '-';
}
}
// EOF

View File

@ -0,0 +1,61 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
echo("Cisco CEF Switching Path: ");
$cefs = snmpwalk_cache_threepart_oid($device, "cefSwitchingPath", array(), 'CISCO-CEF-MIB');
if (OBS_DEBUG > 1) { print_vars($cefs); }
if (is_array($cefs))
{
if (!is_array($entity_array))
{
echo("Caching OIDs: ");
$entity_array = array();
echo(" entPhysicalDescr");
$entity_array = snmpwalk_cache_oid($device, "entPhysicalDescr", $entity_array, "ENTITY-MIB");
echo(" entPhysicalName");
$entity_array = snmpwalk_cache_oid($device, "entPhysicalName", $entity_array, "ENTITY-MIB");
echo(" entPhysicalModelName");
$entity_array = snmpwalk_cache_oid($device, "entPhysicalModelName", $entity_array, "ENTITY-MIB");
}
foreach ($cefs as $entity => $afis)
{
$entity_name = $entity_array[$entity]['entPhysicalName'] ." - ".$entity_array[$entity]['entPhysicalModelName'];
echo("\n$entity $entity_name\n");
foreach ($afis as $afi => $paths)
{
echo(" |- $afi\n");
foreach ($paths as $path => $path_name)
{
echo(" | |-".$path.": ".$path_name['cefSwitchingPath']."\n");
$cef_exists[$device['device_id']][$entity][$afi][$path] = 1;
// FIXME, old code was incorrect, but not sure that still fixed..
//if (dbFetchCell("SELECT COUNT(*) from `cef` WHERE `device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?", array($device['device_id'], $entity, $afi, $path)) != "1") // Why != 1 ???
if (!dbExist('cef_switching', '`device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_path` = ?', array($device['device_id'], $entity, $afi, $path)))
{
dbInsert(array('device_id' => $device['device_id'], 'entPhysicalIndex' => $entity, 'afi' => $afi, 'cef_path' => $path), 'cef_switching');
echo("+");
}
}
}
}
}
// FIXME - need to delete old ones. FIXME REALLY.
echo(PHP_EOL);
// EOF

View File

@ -0,0 +1,74 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mib = 'Printer-MIB';
//Printer-MIB::prtMarkerMarkTech.1.1 = INTEGER: electrophotographicLaser(4)
//Printer-MIB::prtMarkerCounterUnit.1.1 = INTEGER: impressions(7)
//Printer-MIB::prtMarkerLifeCount.1.1 = Counter32: 19116
//Printer-MIB::prtMarkerPowerOnCount.1.1 = Counter32: 43
//Printer-MIB::prtMarkerProcessColorants.1.1 = INTEGER: 1
//Printer-MIB::prtMarkerSpotColorants.1.1 = INTEGER: 0
//Printer-MIB::prtMarkerAddressabilityUnit.1.1 = INTEGER: tenThousandthsOfInches(3)
//Printer-MIB::prtMarkerAddressabilityFeedDir.1.1 = INTEGER: 600
//Printer-MIB::prtMarkerAddressabilityXFeedDir.1.1 = INTEGER: 600
//Printer-MIB::prtMarkerNorthMargin.1.1 = INTEGER: 1968
//Printer-MIB::prtMarkerSouthMargin.1.1 = INTEGER: 1968
//Printer-MIB::prtMarkerWestMargin.1.1 = INTEGER: 1968
//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);
//print_vars($oids);
$count = count($oids);
$total_printed_allow = TRUE;
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));
$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']);
// Lifetime counter (should be always single)
$descr = "Total $marker_descr";
$oid_name = 'prtMarkerLifeCount';
$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)
{
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'])
{
$descr .= ' - ' . rewrite_entity_name(snmp_hexstring($prt_supplies[$index]['prtMarkerSuppliesDescription']));
}
$oid_name = 'prtMarkerPowerOnCount';
$oid = '.1.3.6.1.2.1.43.10.2.1.5.' . $index;
$value = $entry[$oid_name];
discover_counter($device, 'printersupply', $mib, $oid_name, $oid, $index, rewrite_entity_name($descr), 1, $value, $options);
// prtMarkerStatus
// FIXME, binary statuses currently unsupported
}
// EOF

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,19 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// Discover arbitrary graphs by MIB
$include_dir = "includes/discovery/graphs/";
include("includes/include-dir-mib.inc.php");
// EOF

View File

@ -0,0 +1,57 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage poller
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
echo("Juniper Firewall Counters");
$fws = array();
$fws = snmpwalk_cache_threepart_oid($device, "jnxFWCounterDisplayType", $fws, "JUNIPER-FIREWALL-MIB");
if (count($fws))
{
$oid = 'jnxFWCounterDisplayType';
}
/*
else
{
$fws = snmpwalk_cache_twopart_oid($device, "jnxFWType", $fws, "JUNIPER-FIREWALL-MIB");
if (count($fws))
{
$oid = 'jnxFWType';
}
}
*/
$array = array();
foreach ($fws as $filter => $counters)
{
foreach ($counters AS $counter => $types)
{
foreach($types as $type => $data)
{
$array[$filter][$counter][$type] = 1;
}
}
}
echo("\n");
if (count($array))
{
set_entity_attrib('device', $device['device_id'], 'juniper-firewall-mib', json_encode($array));
}
unset($fws, $filter, $counters, $counter, $data);
// EOF

View File

@ -0,0 +1,23 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
$valid['inventory'] = array();
$include_dir = "includes/discovery/inventory";
include($config['install_dir']."/includes/include-dir-mib.inc.php");
check_valid_inventory($device);
$GLOBALS['module_stats'][$module]['status'] = safe_count($valid[$module]);
if (OBS_DEBUG && $GLOBALS['module_stats'][$module]['status']) { print_vars($valid[$module]); }
// EOF

View File

@ -0,0 +1,164 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$oids = snmp_cache_table($device, 'cpqRackServerBladeTable', NULL, 'CPQRACK-MIB'); // This table also used in statuses
// Chassis
$index = 1;
$inventory[$index] = array(
'entPhysicalName' => $device['hardware'].' Chassis',
'entPhysicalDescr' => $device['hostname'],
'entPhysicalClass' => 'chassis',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $device['hardware'],
'entPhysicalSerialNum' => $device['serial'],
'entPhysicalFirmwareRev' => $device['version'],
'entPhysicalAssetID' => $device['asset_tag'],
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'HP'
);
discover_inventory($device, $index, $inventory[$index], $mib);
// Blades
foreach ($oids as $tmp => $entry)
{
if ($entry['cpqRackServerBladeEntry'] == "0") { continue; }
if ($entry['cpqRackServerBladeSlotsUsed'] == "0") { continue; }
$index += 2;
$inventory[$index] = array(
'entPhysicalName' => 'Slot '.$entry['cpqRackServerBladePosition'],
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $entry['cpqRackServerBladePosition'],
'entPhysicalMfgName' => 'HP'
);
$model = $entry['cpqRackServerBladeProductId'];
if ($entry['cpqRackServerBladePowered'] === "off")
{
$model .= ' (OFF)';
}
$inventory[$index+1] = array(
'entPhysicalName' => $entry['cpqRackServerBladeName'],
'entPhysicalDescr' => $entry['cpqRackServerBladeName'],
'entPhysicalClass' => 'module',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $model,
'entPhysicalSerialNum' => $entry['cpqRackServerBladeSerialNum'],
'entPhysicalContainedIn' => $index,
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'HP'
);
discover_inventory($device, $index, $inventory[$index], $mib);
discover_inventory($device, $index+1, $inventory[$index+1], $mib);
unset($model);
}
$oids = snmp_cache_table($device, 'cpqRackPowerSupplyTable', NULL, 'CPQRACK-MIB'); // This table also used in sensors
foreach ($oids as $pwr => $entry)
{
$index += 2;
$inventory[$index] = array(
'entPhysicalName' => 'Power Supply Module ' . $pwr,
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $pwr,
'entPhysicalMfgName' => 'HP'
);
$inventory[$index+1] = array(
'entPhysicalName' => 'Power Supply ' . $pwr,
'entPhysicalDescr' => 'Power Supply ' . $pwr,
'entPhysicalClass' => 'power',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $entry['cpqRackPowerSupplyPartNumber'],
'entPhysicalSerialNum' => $entry['cpqRackPowerSupplySerialNum'],
'entPhysicalContainedIn' => $index,
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'HP'
);
discover_inventory($device, $index, $inventory[$index], $mib);
discover_inventory($device, $index+1, $inventory[$index+1], $mib);
}
$nets = snmpwalk_cache_oid($device, 'cpqRackNetConnectorTable', array(), 'CPQRACK-MIB');
foreach ($nets as $net => $entry)
{
if ($entry['cpqRackNetConnectorPresent'] == "absent") { continue; }
$index += 2;
$inventory[$index] = array(
'entPhysicalName' => 'Network Connector Module ' . $net,
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $net,
'entPhysicalMfgName' => 'HP'
);
$inventory[$index+1] = array(
'entPhysicalName' => 'Network Connector ' . $net,
'entPhysicalDescr' => 'Network Connector ' . $net,
'entPhysicalClass' => 'port',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $entry['cpqRackNetConnectorModel'],
'entPhysicalSerialNum' => $entry['cpqRackNetConnectorSerialNum'],
'entPhysicalContainedIn' => $index,
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'HP'
);
discover_inventory($device, $index, $inventory[$index], $mib);
discover_inventory($device, $index+1, $inventory[$index+1], $mib);
}
$oas = snmpwalk_cache_oid($device, 'cpqRackCommonEnclosureManagerTable', array(), 'CPQRACK-MIB');
foreach ($oas as $oa => $entry)
{
if ($entry['cpqRackCommonEnclosureManagerPresent'] == "absent") { continue; }
$index += 2;
$inventory[$index] = array(
'entPhysicalName' => 'Onboard Administrator Module ' . $oa,
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $oa,
'entPhysicalMfgName' => 'HP'
);
$oa_state = $entry['cpqRackCommonEnclosureManagerRole'];
$inventory[$index+1] = array(
'entPhysicalName' => 'Onboard Administrator ' . $oa . ' [' . $oa_state . ']',
'entPhysicalDescr' => 'Onboard Administrator ' . $oa,
'entPhysicalClass' => 'module',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $entry['cpqRackCommonEnclosureManagerEnclosureName'],
'entPhysicalSerialNum' => $entry['cpqRackCommonEnclosureManagerSerialNum'],
'entPhysicalFirmwareRev' => $entry['cpqRackCommonEnclosureManagerFWRev'],
'entPhysicalContainedIn' => $index,
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'HP'
);
discover_inventory($device, $index, $inventory[$index], $mib);
discover_inventory($device, $index+1, $inventory[$index+1], $mib);
}
unset($power, $net, $oa, $oa_state);
// EOF

View File

@ -0,0 +1,81 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2015 Observium Limited
*
*/
// Only run this mib for chassis systems
// DELL-RAC-MIB::drsProductType.0 = INTEGER: cmc(8)
$type = snmp_get_oid($device, "drsProductType.0", "DELL-RAC-MIB");
if ( strstr($type, "cmc") || strstr($type, "CMC") )
{
$oids = snmp_cache_table($device, 'drsChassisServerGroup', NULL, 'DELL-RAC-MIB'); // This table also used in statuses
$index = 1;
$inventory[$index] = array(
'entPhysicalName' => $device['hardware'].' Chassis',
'entPhysicalDescr' => $device['hostname'],
'entPhysicalClass' => 'chassis',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $device['hardware'],
'entPhysicalSerialNum' => $device['serial'],
'entPhysicalHardwareRev' => snmp_get($device, "drsProductVersion.0", "-Oqv", "DELL-RAC-MIB"),
'entPhysicalFirmwareRev' => $device['version'],
'entPhysicalAssetID' => $device['asset_tag'],
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'Dell'
);
discover_inventory($device, $index, $inventory[$index], $mib);
foreach ($oids as $tmp => $entry)
{
if ($entry['drsServerSlotNumber'] === "N/A") { continue; }
$index += 2;
// Full height blades take up two slots and are marked as Extension
if (!strstr($entry[drsServerSlotName],"Extension")) {
$serial = $entry['drsServerServiceTag'];
$inventory[$index] = array(
'entPhysicalName' => 'Slot '.$entry['drsServerSlotNumber'],
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $entry['drsServerSlotNumber'],
'entPhysicalMfgName' => 'Dell'
);
$model = $entry['drsServerModel'];
if ( $entry['drsServerMonitoringCapable'] === "off") {
$model .= ' (OFF)';
}
$inventory[$index+1] = array(
'entPhysicalName' => $entry['drsServerSlotName'],
'entPhysicalDescr' => $entry['drsServerSlotName'],
'entPhysicalClass' => 'module',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $model,
'entPhysicalSerialNum' => $serial,
'entPhysicalContainedIn' => $index,
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'Dell'
);
discover_inventory($device, $index, $inventory[$index], $mib);
discover_inventory($device, $index+1, $inventory[$index+1], $mib);
unset($serial, $model);
} else {
$i = $index-2;
$inventory[$i]['entPhysicalName'] = $inventory[$i]['entPhysicalName'] . '+' . $entry['drsServerSlotNumber'];
discover_inventory($device, $i, $inventory[$i], $mib);
}
}
}
// EOF

View File

@ -0,0 +1,134 @@
<?php
if (is_device_mib($device, 'DES-1210-28ME-B2')) {
$vendor_mib = 'DES-1210-28ME-B2';
$vendor_oids = snmpwalk_cache_oid($device, "sfpVendorInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
print_debug_vars($vendor_oids);
$copperports = 24;
$comboports = 2;
$fiberports = 2;
} else {
return;
}
echo($vendor_mib);
$revision = snmp_get_oid($device, 'probeHardwareRev.0', 'RMON2-MIB');
$system_index = 1;
$inventory[$system_index] = [
'entPhysicalDescr' => $device['sysDescr'],
'entPhysicalClass' => 'chassis',
'entPhysicalName' => $device['hardware'],
'entPhysicalHardwareRev' => $revision,
'entPhysicalSoftwareRev' => $device['version'],
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $device['hardware'],
'entPhysicalSerialNum' => $device['serial'],
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'D-Link',
];
discover_inventory($device, $system_index, $inventory[$system_index], $vendor_mib);
/*
DES-1210-28ME-B2::companySfpVendorInfo
sfpPortIndex.27 = 27
sfpPortIndex.28 = 28
sfpConnectorType.27 = SFP - MT-RJ
sfpConnectorType.28 = SFP - SC
sfpTranceiverCode.27 =
sfpTranceiverCode.28 = Unallocated
sfpBaudRate.27 = d
sfpBaudRate.28 = d
sfpVendorName.27 =
sfpVendorName.28 =
sfpVendorOui.27 = 0:90:65
sfpVendorOui.28 = 0: 0: 0
sfpVendorPn.27 = SFP-1.25G-1310
sfpVendorPn.28 = TBSF15d1012gSC3c
sfpVendorRev.27 = A0
sfpVendorRev.28 = A
sfpWavelength.27 = 51e
sfpWavelength.28 = 60e
sfpVendorSn.27 = SC91750197
sfpVendorSn.28 = F201705111103
sfpDateCode.27 = 120904
sfpDateCode.28 = 170512
DES-1210-28ME-B2::sfpPortIndex.25 = INTEGER: 25
DES-1210-28ME-B2::sfpPortIndex.26 = INTEGER: 26
DES-1210-28ME-B2::sfpPortIndex.28 = INTEGER: 28
DES-1210-28ME-B2::sfpConnectorType.25 = STRING: "SFP - SC"
DES-1210-28ME-B2::sfpConnectorType.26 = STRING: "SFP - SC"
DES-1210-28ME-B2::sfpConnectorType.28 = STRING: "SFP - SC"
DES-1210-28ME-B2::sfpTranceiverCode.25 = STRING: "Unallocated"
DES-1210-28ME-B2::sfpTranceiverCode.26 = STRING: "Single Mode"
DES-1210-28ME-B2::sfpTranceiverCode.28 = STRING: "Single Mode"
DES-1210-28ME-B2::sfpBaudRate.25 = STRING: "d"
DES-1210-28ME-B2::sfpBaudRate.26 = STRING: "d"
DES-1210-28ME-B2::sfpBaudRate.28 = STRING: "d"
DES-1210-28ME-B2::sfpVendorName.25 = ""
DES-1210-28ME-B2::sfpVendorName.26 = ""
DES-1210-28ME-B2::sfpVendorName.28 = ""
DES-1210-28ME-B2::sfpVendorOui.25 = STRING: " 0: 0: 0"
DES-1210-28ME-B2::sfpVendorOui.26 = STRING: " 0: 0: 0"
DES-1210-28ME-B2::sfpVendorOui.28 = STRING: " 0: 0: 0"
DES-1210-28ME-B2::sfpVendorPn.25 = STRING: "TBSF13312gSC3cDD"
DES-1210-28ME-B2::sfpVendorPn.26 = STRING: "SFP-BIDI "
DES-1210-28ME-B2::sfpVendorPn.28 = STRING: "AP-B53121-3CS3 "
DES-1210-28ME-B2::sfpVendorRev.25 = STRING: "A "
DES-1210-28ME-B2::sfpVendorRev.26 = STRING: "1.0 "
DES-1210-28ME-B2::sfpVendorRev.28 = STRING: "1.00"
DES-1210-28ME-B2::sfpWavelength.25 = STRING: "51e"
DES-1210-28ME-B2::sfpWavelength.26 = STRING: "60e"
DES-1210-28ME-B2::sfpWavelength.28 = STRING: "60e"
DES-1210-28ME-B2::sfpVendorSn.25 = STRING: "F201705113806 "
DES-1210-28ME-B2::sfpVendorSn.26 = STRING: "G181687 "
DES-1210-28ME-B2::sfpVendorSn.28 = STRING: "SG53E20800234 "
DES-1210-28ME-B2::sfpDateCode.25 = STRING: "170517 "
DES-1210-28ME-B2::sfpDateCode.26 = STRING: "180916 "
DES-1210-28ME-B2::sfpDateCode.28 = STRING: "120224 "
*/
$totalports = $copperports + $comboports + $fiberports;
for ($i = 1; $i <= $totalports; $i++) {
$system_index = 100 + $i;
if ($i <= $copperports) {
$inventory[$system_index] = [
'entPhysicalDescr' => '100Base-T Copper Port',
'entPhysicalClass' => 'port',
'entPhysicalName' => 'Port '.$i,
'entPhysicalIsFRU' => 'false',
'entPhysicalModelName' => 'Copper Port',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $i,
'ifIndex' => $i,
];
} else {
if ($i <= $copperports + $comboports) {
$portdescr = 'Combo Port';
} else {
$portdescr = 'SFP Port';
}
$inventory[$system_index] = [
'entPhysicalDescr' => $portdescr,
'entPhysicalClass' => 'port',
'entPhysicalName' => 'Port '.$i,
'entPhysicalIsFRU' => 'false',
'entPhysicalModelName' => trim($vendor_oids[$i]['sfpTranceiverCode']),
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $i,
'ifIndex' => $i,
'entPhysicalVendorType' => trim($vendor_oids[$i]['sfpConnectorType']),
'entPhysicalSerialNum' => trim($vendor_oids[$i]['sfpVendorSn']),
'entPhysicalHardwareRev' => trim($vendor_oids[$i]['sfpVendorPn']),
'entPhysicalFirmwareRev' => trim($vendor_oids[$i]['sfpVendorRev']),
'entPhysicalMfgName' => trim($vendor_oids[$i]['sfpVendorName']),
];
}
discover_inventory($device, $system_index, $inventory[$system_index], $vendor_mib);
}
print_debug_vars($inventory);
// EOF

View File

@ -0,0 +1,15 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
include __DIR__ . '/des3026-l2mgmt-mib.inc.php';
// EOF

View File

@ -0,0 +1,102 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
if (is_device_mib($device, 'DES3026-L2MGMT-MIB')) {
$desmib = 'DES3026-L2MGMT-MIB';
$copperports = 24;
} elseif (is_device_mib($device, 'DES3018-L2MGMT-MIB')) {
$desmib = 'DES3018-L2MGMT-MIB';
$copperports = 16;
} else {
return;
}
echo($desmib);
$revision = snmp_get_oid($device, 'probeHardwareRev.0', 'RMON2-MIB');
$system_index = 1;
$inventory[$system_index] = array(
'entPhysicalDescr' => $device['sysDescr'],
'entPhysicalClass' => 'chassis',
'entPhysicalName' => $device['hardware'],
'entPhysicalHardwareRev' => $revision,
'entPhysicalSoftwareRev' => $device['version'],
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $device['hardware'],
'entPhysicalSerialNum' => $device['serial'],
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'D-Link',
);
discover_inventory($device, $system_index, $inventory[$system_index], $desmib);
for ($i = 1; $i <= $copperports; $i++) {
$system_index = 100 + $i;
$inventory[$system_index] = array(
'entPhysicalDescr' => '100Base-T Copper Port',
'entPhysicalClass' => 'port',
'entPhysicalName' => 'Port '.$i,
'entPhysicalIsFRU' => 'false',
'entPhysicalModelName' => 'Copper Port',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $i,
'ifIndex' => $i,
);
discover_inventory($device, $system_index, $inventory[$system_index], $desmib);
}
for ($slot = 1; $slot <= 2; $slot++) {
// Slot 1
$system_index = 100 + $i;
$inventory[$system_index] = array(
'entPhysicalDescr' => 'DES-3018/3026 extended Slot',
'entPhysicalClass' => 'container',
'entPhysicalName' => 'Slot '.$slot,
'entPhysicalIsFRU' => 'false',
'entPhysicalModelName' => 'Extended Slot',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $i,
);
discover_inventory($device, $system_index, $inventory[$system_index], $desmib);
if ($slot == 1) {
$des30xxswL2ModuleXType = snmp_get_oid($device, 'swL2Module-1-Type.0', $desmib);
} else {
$des30xxswL2ModuleXType = snmp_get_oid($device, 'swL2Module-2-Type.0', $desmib);
}
$system2_index = 200 + $i;
$inventory[$system2_index] = array(
'entPhysicalDescr' => $des30xxswL2ModuleXType,
'entPhysicalClass' => 'module',
'entPhysicalName' => 'Module '.$slot,
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => $system_index,
'entPhysicalParentRelPos' => 0,
'entPhysicalMfgName' => 'D-Link',
);
discover_inventory($device, $system2_index, $inventory[$system2_index], $desmib);
$system3_index = 300 + $i;
$inventory[$system3_index] = array(
'entPhysicalDescr' => 'Gigabit Ethernet',
'entPhysicalClass' => 'port',
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $system2_index,
'entPhysicalParentRelPos' => 0,
'ifIndex' => $i,
);
discover_inventory($device, $system3_index, $inventory[$system3_index], $desmib);
// Slot 2
$i++;
}
print_debug_vars($inventory);
// EOF

View File

@ -0,0 +1,75 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// This device not have self Indexes.
// Use workaround ($base_vendor_index * 100000) + ($e7CardBank * 1000) + $e7CardIndex
$base_vendor_index = 6321;
// System
$e7SystemId = snmp_get($device, 'e7SystemId.0', '-OQUs', 'E7-Calix-MIB');
if ($e7SystemId)
{
$e7SystemChassisSerialNumber = snmp_get($device, '.1.3.6.1.4.1.6321.1.2.2.2.1.7.10.0', '-Oqvn');
$system_index = $base_vendor_index * 100000;
$inventory[$system_index] = array(
'entPhysicalDescr' => 'Calix Networks, E7 Ethernet Service Access Platform',
'entPhysicalClass' => 'chassis',
'entPhysicalName' => 'E7 ESAP',
'entPhysicalSerialNum' => $e7SystemChassisSerialNumber,
'entPhysicalAssetID' => $e7SystemId,
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => 0,
'entPhysicalMfgName' => 'Calix'
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
// Cards
$E7CardEntry = snmpwalk_cache_twopart_oid($device, 'E7CardEntry', array(), 'E7-Calix-MIB');
foreach ($E7CardEntry as $e7CardBank => $entries)
{
$bank_index = $system_index + $e7CardBank * 1000;
$inventory[$bank_index] = array(
'entPhysicalDescr' => 'E7 ESAP Bank',
'entPhysicalClass' => 'container',
'entPhysicalName' => 'Bank '.$e7CardBank,
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $system_index,
'entPhysicalParentRelPos' => $e7CardBank,
'entPhysicalMfgName' => 'Calix'
);
discover_inventory($device, $bank_index, $inventory[$bank_index], $mib);
foreach ($entries as $e7CardIndex => $entry)
{
$card_index = $bank_index + $e7CardIndex;
$inventory[$card_index] = array(
'entPhysicalDescr' => 'E7 ESAP Card',
'entPhysicalClass' => 'other',
'entPhysicalName' => 'Card '.ucfirst($entry['e7CardActualType']),
'entPhysicalVendorType' => $entry['e7CardActualType'],
'entPhysicalSerialNum' => $entry['e7CardSerialNumber'],
'entPhysicalSoftwareRev' => $entry['e7CardSoftwareVersion'],
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $bank_index,
'entPhysicalParentRelPos' => $e7CardIndex,
'entPhysicalMfgName' => 'Calix'
);
discover_inventory($device, $card_index, $inventory[$card_index], $mib);
}
}
print_debug_vars($inventory);
}
// EOF

View File

@ -0,0 +1,208 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
echo("ENTITY-MIB ");
$snmp_flags = OBS_SNMP_ALL;
//snmp_log_error(OBS_SNMP_ERROR_OID_NOT_INCREASING, FALSE); // disable log error for next snmpwalk
$entity_array = snmpwalk_cache_oid($device, "entPhysicalEntry", [], snmp_mib_entity_vendortype($device, 'ENTITY-MIB'));
if (!snmp_status()) {
if (snmp_error_code() === OBS_SNMP_ERROR_OID_NOT_INCREASING) {
// Try refetch with NOINCREASE
$snmp_flags |= OBS_SNMP_NOINCREASE;
print_debug("WARNING! snmpwalk error 'OID not increasing' detected, try snmpwalk with -Cc option.");
$entity_array = snmpwalk_cache_oid($device, "entPhysicalEntry", $entity_array, snmp_mib_entity_vendortype($device, 'ENTITY-MIB'), NULL, $snmp_flags);
if (!snmp_status()) { return; }
} else {
return;
}
}
$entity_array = snmpwalk_cache_twopart_oid($device, "entAliasMappingIdentifier", $entity_array, 'ENTITY-MIB:IF-MIB', NULL, $snmp_flags);
$GLOBALS['cache']['snmp']['ENTITY-MIB'][$device['device_id']] = $entity_array; // Cache this array for sensors discovery (see in cisco-entity-sensor-mib or entity-sensor-mib)
// Some vendor specific inventory expander's
$vendor_oids = [];
$vendor_mib = NULL;
if (is_device_mib($device, 'ELTEX-MES-PHYSICAL-DESCRIPTION-MIB')) {
$vendor_mib = 'ELTEX-MES-PHYSICAL-DESCRIPTION-MIB';
$vendor_oids = snmpwalk_cache_oid($device, "eltPhdTransceiverInfoTable", $vendor_oids, $vendor_mib, NULL, $snmp_flags);
//print_vars($entity_array);
//print_debug_vars($vendor_oids);
} elseif (is_device_mib($device, 'DGS3627G-L2MGMT-MIB')) {
$vendor_mib = 'DGS3627G-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, 'DGS3120-24SC-L2MGMT-MIB')) {
$vendor_mib = 'DGS3120-24SC-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);
}
foreach ($entity_array as $entPhysicalIndex => $entry) {
unset($entAliasMappingIdentifier);
foreach ([ 0, 1, 2 ] as $i) {
if (isset($entity_array[$entPhysicalIndex][$i]['entAliasMappingIdentifier'])) {
$entAliasMappingIdentifier = $entity_array[$entPhysicalIndex][$i]['entAliasMappingIdentifier'];
break;
}
}
if (isset($entAliasMappingIdentifier) && str_contains_array($entAliasMappingIdentifier, 'fIndex')) {
list(, $ifIndex) = explode('.', $entAliasMappingIdentifier);
$entry['ifIndex'] = $ifIndex;
}
// Some vendor specific inventory expander's
if ($vendor_mib === 'ELTEX-MES-PHYSICAL-DESCRIPTION-MIB' && isset($vendor_oids[$entry['ifIndex']])) {
//$entry = array_merge($entry, $vendor_oids[$entry['ifIndex']]);
print_debug_vars($vendor_oids[$entry['ifIndex']]);
/*
[entPhysicalDescr] => string(20) "gigabitethernet1/0/2"
[entPhysicalVendorType] => string(17) "cevPortDCUATMPort"
[entPhysicalContainedIn] => string(8) "68424704"
[entPhysicalClass] => string(4) "port"
[entPhysicalParentRelPos] => string(1) "4"
[entPhysicalName] => string(7) "gi1/0/2"
[entPhysicalHardwareRev] => string(0) ""
[entPhysicalFirmwareRev] => string(0) ""
[entPhysicalSoftwareRev] => string(0) ""
[entPhysicalSerialNum] => string(0) ""
[entPhysicalMfgName] => string(0) ""
[entPhysicalModelName] => string(0) ""
[entPhysicalAlias] => string(0) ""
[entPhysicalAssetID] => string(0) ""
[entPhysicalIsFRU] => string(5) "false"
*/
/*
[eltPhdTransceiverInfoConnectorType] => string(2) "sc"
[eltPhdTransceiverInfoType] => string(11) "sfp-sfpplus"
[eltPhdTransceiverInfoComplianceCode] => string(11) "1000BASE-LX"
[eltPhdTransceiverInfoWaveLength] => string(4) "1550"
[eltPhdTransceiverInfoVendorName] => string(16) "OptiCin "
[eltPhdTransceiverInfoSerialNumber] => string(16) "PF4D870547 "
[eltPhdTransceiverInfoFiberDiameterType] => string(6) "fiber9"
[eltPhdTransceiverInfoTransferDistance] => string(4) "3000"
[eltPhdTransceiverInfoDiagnostic] => string(5) "false"
[eltPhdTransceiverInfoPartNumber] => string(16) "SFP-WDM5.03 "
[eltPhdTransceiverInfoVendorRev] => string(4) " "
*/
// entPhysicalVendorType -> eltPhdTransceiverInfoType
// entPhysicalHardwareRev -> eltPhdTransceiverInfoPartNumber
// entPhysicalFirmwareRev -> eltPhdTransceiverInfoVendorRev
// entPhysicalSoftwareRev -> ??
// entPhysicalSerialNum -> eltPhdTransceiverInfoSerialNumber
// entPhysicalMfgName -> eltPhdTransceiverInfoVendorName
// entPhysicalModelName -> eltPhdTransceiverInfoComplianceCode
// entPhysicalAlias -> ??
// entPhysicalAssetID -> ??
$entry['entPhysicalVendorType'] = trim($vendor_oids[$entry['ifIndex']]['eltPhdTransceiverInfoType']);
$entry['entPhysicalHardwareRev'] = trim($vendor_oids[$entry['ifIndex']]['eltPhdTransceiverInfoPartNumber']);
$entry['entPhysicalFirmwareRev'] = trim($vendor_oids[$entry['ifIndex']]['eltPhdTransceiverInfoVendorRev']);
$entry['entPhysicalSerialNum'] = trim($vendor_oids[$entry['ifIndex']]['eltPhdTransceiverInfoSerialNumber']);
$entry['entPhysicalMfgName'] = trim($vendor_oids[$entry['ifIndex']]['eltPhdTransceiverInfoVendorName']);
$entry['entPhysicalModelName'] = trim($vendor_oids[$entry['ifIndex']]['eltPhdTransceiverInfoComplianceCode']);
} elseif (str_starts($vendor_mib, 'DGS') && $entry['entPhysicalModelName'] === 'Fiber Port' &&
isset($vendor_oids[$entry['entPhysicalParentRelPos']]) &&
is_numeric($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoDateCode'])) {
//$entry = array_merge($entry, $vendor_oids[$entry['ifIndex']]);
print_debug_vars($vendor_oids[$entry['entPhysicalParentRelPos']]);
/*
[13] => array(
[entPhysicalDescr] => string(29) "1000_TXGBIC_COMBO Copper Port"
[entPhysicalVendorType] => string(11) "zeroDotZero"
[entPhysicalContainedIn] => string(1) "2"
[entPhysicalClass] => string(4) "port"
[entPhysicalParentRelPos] => string(2) "21"
[entPhysicalName] => string(7) "Port 21"
[entPhysicalHardwareRev] => string(0) ""
[entPhysicalFirmwareRev] => string(0) ""
[entPhysicalSoftwareRev] => string(0) ""
[entPhysicalSerialNum] => string(0) ""
[entPhysicalMfgName] => string(0) ""
[entPhysicalModelName] => string(11) "Copper Port"
[entPhysicalAlias] => string(0) ""
[entPhysicalAssetID] => string(0) ""
[entPhysicalIsFRU] => string(5) "false"
)
...
[37] => array(
[entPhysicalDescr] => string(28) "1000_TXGBIC_COMBO Fiber Port"
[entPhysicalVendorType] => string(11) "zeroDotZero"
[entPhysicalContainedIn] => string(1) "2"
[entPhysicalClass] => string(4) "port"
[entPhysicalParentRelPos] => string(2) "21"
[entPhysicalName] => string(7) "Port 21"
[entPhysicalHardwareRev] => string(0) ""
[entPhysicalFirmwareRev] => string(0) ""
[entPhysicalSoftwareRev] => string(0) ""
[entPhysicalSerialNum] => string(0) ""
[entPhysicalMfgName] => string(0) ""
[entPhysicalModelName] => string(10) "Fiber Port"
[entPhysicalAlias] => string(0) ""
[entPhysicalAssetID] => string(0) ""
[entPhysicalIsFRU] => string(5) "false"
)
*/
/*
[21] => array(
[swL2PortSfpInfoPortIndex] => string(2) "21"
[swL2PortSfpInfoConnectType] => string(6) "SFP LC"
[swL2PortSfpInfoVendorName] => string(3) "OEM"
[swL2PortSfpInfoVendorPN] => string(10) "SFP-BX-U31"
[swL2PortSfpInfoVendorSN] => string(8) "F10GU046"
[swL2PortSfpInfoVendorOUI] => string(6) "0:0:0."
[swL2PortSfpInfoVendorRev] => string(3) "1.0"
[swL2PortSfpInfoDateCode] => string(6) "090701"
[swL2PortSfpInfoFiberType] => string(16) "Single Mode (SM)"
[swL2PortSfpInfoBaudRate] => string(4) "1300"
[swL2PortSfpInfoWavelength] => string(4) "1310"
)
*/
$entry['entPhysicalVendorType'] = trim($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoConnectType']);
$entry['entPhysicalHardwareRev'] = trim($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoVendorPN']);
$entry['entPhysicalFirmwareRev'] = trim($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoVendorRev']);
$entry['entPhysicalSerialNum'] = trim($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoVendorSN']);
$entry['entPhysicalMfgName'] = trim($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoVendorName']);
$entry['entPhysicalModelName'] = trim($vendor_oids[$entry['entPhysicalParentRelPos']]['swL2PortSfpInfoFiberType']);
}
if ($entry['entPhysicalDescr'] || $entry['entPhysicalName']) {
discover_inventory($device, $entPhysicalIndex, $entry, $mib);
}
}
// EOF

View File

@ -0,0 +1,271 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2015 Observium Limited
*
*/
echo(" F5-BIGIP-SYSTEM-MIB ");
$index = 1; $chassis_pos = 0;
$inventory[$index] = array(
'entPhysicalName' => $device['hardware'].' Chassis',
'entPhysicalDescr' => $device['hostname'],
'entPhysicalClass' => 'chassis',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $device['hardware'],
'entPhysicalSerialNum' => $device['serial'],
'entPhysicalHardwareRev' => snmp_get($device, "sysGeneralHwName.0", "-Oqv", "F5-BIGIP-SYSTEM-MIB"),
'entPhysicalFirmwareRev' => $device['version'],
'entPhysicalAssetID' => $device['asset_tag'],
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'F5'
);
discover_inventory($device, $index, $inventory[$index], $mib);
if (!isset($cache_discovery['f5-bigip-system-mib']))
{
$cache_discovery['f5-bigip-system-mib']['chassis']['port'] = snmpwalk_cache_oid($device, 'sysInterfaceTable', array(), 'F5-BIGIP-SYSTEM-MIB');
$cache_discovery['f5-bigip-system-mib']['chassis']['powerSupply'] = snmpwalk_cache_oid($device, 'sysChassisPowerSupplyTable', array(), 'F5-BIGIP-SYSTEM-MIB');
$cache_discovery['f5-bigip-system-mib']['chassis']['fan'] = snmpwalk_cache_oid($device, 'sysChassisFanTable', array(), 'F5-BIGIP-SYSTEM-MIB');
$cache_discovery['f5-bigip-system-mib']['chassis']['temp'] = snmpwalk_cache_oid($device, 'sysChassisTempTable', array(), 'F5-BIGIP-SYSTEM-MIB');
$cache_discovery['f5-bigip-system-mib']['slot']['voltage'] = snmpwalk_cache_oid($device, 'sysBladeVoltageTable', array(), 'F5-BIGIP-SYSTEM-MIB');
$cache_discovery['f5-bigip-system-mib']['slot']['cpu'] = snmpwalk_cache_oid($device, 'sysCpuSensorTable', array(), 'F5-BIGIP-SYSTEM-MIB');
$cache_discovery['f5-bigip-system-mib']['slot']['disk'] = snmpwalk_cache_oid($device, 'sysPhysicalDiskTable', array(), 'F5-BIGIP-SYSTEM-MIB');
$cache_discovery['f5-bigip-system-mib']['slot']['temp'] = snmpwalk_cache_oid($device, 'sysBladeTempTable', array(), 'F5-BIGIP-SYSTEM-MIB');
}
$cache_ports = dbFetchRows('SELECT `ifName`,`ifIndex` FROM `ports` WHERE `device_id` = ?', array($device['device_id']));
foreach ($cache_ports as $row => $port)
{
$cache_ports[$port['ifName']] = $port['ifIndex'];
}
$fru = array(
'fan' => 'false',
'powerSupply' => 'true',
'temp' => 'false',
'disk' => 'false',
'port' => 'false',
);
$class = array(
'fan' => 'fan',
'powerSupply' => 'powerSupply',
'temp' => 'sensor',
'disk' => 'disk',
'port' => 'port',
);
foreach ($cache_discovery['f5-bigip-system-mib']['chassis'] as $type => $cache)
{
if (!count($cache)) continue;
$index++; $chassis_pos++;
$container = $index;
$inventory[$index] = array(
'entPhysicalName' => 'Chassis '.ucfirst($type).' Container',
'entPhysicalDescr' => $device['hostname'].' - Chassis '.ucfirst($type).' Container',
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => $fru[$type],
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $chassis_pos,
'entPhysicalMfgName' => 'F5'
);
discover_inventory($device, $index, $inventory[$index], $mib);
$pos = 0;
foreach ($cache as $id => $entry)
{
$index++; $pos++;
$name = ucfirst($type).' '.$id;
$serial = NULL;
$ifindex = NULL;
if ($type == 'port')
{
$ifindex = $cache_ports[$id];
}
$inventory[$index] = array(
'entPhysicalName' => $name,
'entPhysicalDescr' => $device['hostname'].' - '.$name,
'entPhysicalClass' => $class[$type],
'entPhysicalIsFRU' => $fru[$type],
'entPhysicalSerialNum' => $serial,
'entPhysicalContainedIn' => $container,
'entPhysicalParentRelPos' => $pos,
'entPhysicalMfgName' => 'F5',
'ifIndex' => $ifindex
);
discover_inventory($device, $index, $inventory[$index], $mib);
unset($ifIndex);
}
}
// Build and array of stuff by slot
foreach ($cache_discovery['f5-bigip-system-mib']['slot'] as $type => $sensors)
{
foreach ($sensors as $tmp => $sensor)
switch ($type)
{
case 'cpu':
$slots[$sensor['sysCpuSensorSlot']]['cpu'] = $sensor;
break;
case 'disk':
$slots[$sensor['sysPhysicalDiskSlotId']]['disk'] = $sensor;
break;
case 'temp':
$slots[$sensor['sysBladeTempSlot']]['temp'][$sensor['sysBladeTempIndex']] = $sensor;
break;
case 'voltage':
$slots[$sensor['sysBladeVoltageSlot']]['voltage'][$sensor['sysBladeVoltageIndex']] = $sensor;
break;
}
}
foreach ($slots as $slot => $sensors)
{
$index++; $chassis_pos++;
$slot_container = $index;
$pos = 0;
$inventory[$index] = array(
'entPhysicalName' => 'Blade Slot '.$slot.' Container',
'entPhysicalDescr' => $device['hostname'].' - Blade Slot '.$slot.' Container',
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $chassis_pos,
'entPhysicalMfgName' => 'F5'
);
discover_inventory($device, $index, $inventory[$index], $mib);
foreach ($sensors as $type => $entry)
{
$index++;
if ($type == 'disk')
{
$pos++;
$name = $entry['sysPhysicalDiskName'];
$serial = $entry['sysPhysicalDiskSerialNumber'];
$inventory[$index] = array(
'entPhysicalName' => $name,
'entPhysicalDescr' => $device['hostname'].' - '.$name,
'entPhysicalClass' => $class[$type],
'entPhysicalIsFRU' => $fru[$type],
'entPhysicalSerialNum' => $serial,
'entPhysicalContainedIn' => $slot_container,
'entPhysicalParentRelPos' => $pos,
'entPhysicalMfgName' => 'F5',
);
discover_inventory($device, $index, $inventory[$index], $mib);
}
else if ($type == 'cpu')
{
$pos++;
$cpu_container = $index;
$inventory[$index] = array(
'entPhysicalName' => 'Blade Slot '.$slot.' CPU Container',
'entPhysicalDescr' => $device['hostname'].' - Chassis Slot '.$slot.' CPU Container',
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $slot_container,
'entPhysicalParentRelPos' => $pos,
'entPhysicalMfgName' => 'F5'
);
discover_inventory($device, $index, $inventory[$index], $mib);
$index++;
$name = $entry['sysCpuSensorName'].' Temperature';
$inventory[$index] = array(
'entPhysicalName' => $name,
'entPhysicalDescr' => $device['hostname'].' - '.$name,
'entPhysicalClass' => 'sensor',
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $cpu_container,
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'F5',
);
discover_inventory($device, $index, $inventory[$index], $mib);
$index++;
$name = $entry['sysCpuSensorName'].' Fan';
$inventory[$index] = array(
'entPhysicalName' => $name,
'entPhysicalDescr' => $device['hostname'].' - '.$name,
'entPhysicalClass' => 'fan',
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $cpu_container,
'entPhysicalParentRelPos' => 2,
'entPhysicalMfgName' => 'F5',
);
discover_inventory($device, $index, $inventory[$index], $mib);
}
else if ($type == 'temp')
{
$pos++;
$temp_container = $index;
$inventory[$index] = array(
'entPhysicalName' => 'Blade Slot '.$slot.' Temp Container',
'entPhysicalDescr' => $device['hostname'].' - Chassis Slot '.$slot.' Temp Container',
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $slot_container,
'entPhysicalParentRelPos' => $pos,
'entPhysicalMfgName' => 'F5'
);
discover_inventory($device, $index, $inventory[$index], $mib);
foreach ($entry as $temp_index => $temp_sensor)
{
$index++;
$inventory[$index] = array(
'entPhysicalName' => $temp_sensor['sysBladeTempLocation'],
'entPhysicalDescr' => $device['hostname'].' - '.$temp_sensor['sysBladeTempLocation'],
'entPhysicalClass' => 'sensor',
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $temp_container,
'entPhysicalParentRelPos' => $temp_index,
'entPhysicalMfgName' => 'F5',
);
discover_inventory($device, $index, $inventory[$index], $mib);
}
}
else if ($type == 'voltage')
{
$pos++;
$voltage_container = $index;
$inventory[$index] = array(
'entPhysicalName' => 'Blade Slot '.$slot.' Voltage Container',
'entPhysicalDescr' => $device['hostname'].' - Chassis Slot '.$slot.' Voltage Container',
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $slot_container,
'entPhysicalParentRelPos' => $pos,
'entPhysicalMfgName' => 'F5'
);
discover_inventory($device, $index, $inventory[$index], $mib);
$volt_pos = 0;
foreach ($entry as $volt_index => $volt_sensor)
{
$index++; $volt_pos++;
$inventory[$index] = array(
'entPhysicalName' => $volt_index,
'entPhysicalDescr' => $device['hostname'].' - '.$volt_index,
'entPhysicalClass' => 'sensor',
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => $voltage_container,
'entPhysicalParentRelPos' => $volt_pos,
'entPhysicalMfgName' => 'F5',
);
discover_inventory($device, $index, $inventory[$index], $mib);
}
}
}
}
unset($cache_ports, $slots, $name, $index, $container, $pos, $slot_container, $cpu_container, $temp_container, $voltage_container);
// EOF

View File

@ -0,0 +1,71 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$snChasProductType = snmp_get($device, 'snChasProductType.0', '-OQv', 'FOUNDRY-SN-AGENT-MIB');
if ($snChasProductType)
{
$snChasSerNum = snmp_get($device, 'snChasSerNum.0', '-OQv', 'FOUNDRY-SN-AGENT-MIB');
// Insert chassis as index 1, everything hangs off of this.
$system_index = 1;
$inventory[$system_index] = array(
'entPhysicalDescr' => $snChasProductType,
'entPhysicalClass' => 'chassis',
'entPhysicalName' => 'Chassis',
'entPhysicalSerialNum' => $snChasSerNum,
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'Brocade'
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
// Now fetch data for the rest of the hardware in the chassis
$data = snmpwalk_cache_oid($device, 'snAgentBrdTable', array(), 'FOUNDRY-SN-AGENT-MIB');
$relPos = 0;
foreach ($data as $part)
{
$system_index = $part['snAgentBrdIndex']*256;
if ($system_index != 0)
{
$containedIn = 1; // Attach to chassis inserted above
// snAgentBrdModuleStatus.6 = moduleRunning
// snAgentBrdModuleStatus.7 = moduleEmpty
if ($part['snAgentBrdModuleStatus'] != 'moduleEmpty')
{
$relPos++;
$inventory[$system_index] = array(
'entPhysicalDescr' => $part['snAgentBrdMainBrdDescription'],
'entPhysicalClass' => 'module',
'entPhysicalName' => $part['snAgentBrdMainBrdDescription'],
'entPhysicalSerialNum' => $part['snAgentBrdSerialNumber'],
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => $containedIn,
'entPhysicalParentRelPos' => $relPos,
'entPhysicalMfgName' => 'Brocade'
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
}
}
}
}
// EOF

View File

@ -0,0 +1,133 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$productTitle = snmp_get($device, 'productTitle.0', '-OQv', 'GEIST-MIB-V3');
if ($productTitle)
{
// Insert chassis as index 1, everything hangs off of this.
$system_index = 1;
$inventory[$system_index] = array(
'entPhysicalDescr' => $productTitle,
'entPhysicalClass' => 'chassis',
'entPhysicalName' => 'Chassis',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'Geist',
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
$relPos = 1;
// Note: sensors without example SNMP output have not been tested.
$geist_sensors = array(
// GEIST-MIB-V3::climateSerial.1 = STRING: 28F123456700000D
// GEIST-MIB-V3::climateName.1 = STRING: RSMINI163
// GEIST-MIB-V3::climateAvail.1 = Gauge32: 1
array('descr' => 'Climate Monitor', 'prefix' => 'climate', 'oid' => 2, 'class' => 'sensor'),
// GEIST-MIB-V3::powMonSerial.1 = STRING: 3B0000007BF12345
// GEIST-MIB-V3::powMonName.1 = STRING: Outlet
// GEIST-MIB-V3::powMonAvail.1 = Gauge32: 1
array('descr' => 'Power Monitor', 'prefix' => 'powMon', 'oid' => 3, 'class' => 'powerSupply', 'avail' => 1),
array('descr' => 'Temperature Sensor', 'prefix' => 'tempSensor', 'oid' => 4, 'class' => 'sensor'),
// GEIST-MIB-V3::airFlowSensorSerial.1 = STRING: 2000000012345678
// GEIST-MIB-V3::airFlowSensorName.1 = STRING: AF/HTD Sensor
// GEIST-MIB-V3::airFlowSensorAvail.1 = Gauge32: 1
array('descr' => 'AF/HTD Sensor', 'prefix' => 'airFlowSensor', 'oid' => 5, 'class' => 'airflowSensor'),
array('descr' => 'DELTA 3 Channel Controller', 'prefix' => 'ctrl3ChDELTA', 'oid' => 6, 'class' => 'sensor'),
// GEIST-MIB-V3::doorSensorSerial.1 = STRING: 0E00000123456789
// GEIST-MIB-V3::doorSensorName.1 = STRING: Door Sensor
// GEIST-MIB-V3::doorSensorAvail.1 = Gauge32: 1
array('descr' => 'Door Sensor', 'prefix' => 'doorSensor', 'oid' => 7, 'class' => 'sensor'),
array('descr' => 'Water Sensor', 'prefix' => 'waterSensor', 'oid' => 8, 'class' => 'sensor'),
array('descr' => 'Current Sensor', 'prefix' => 'currentSensor', 'oid' => 9, 'class' => 'sensor'),
array('descr' => 'Millivolt Sensor', 'prefix' => 'millivoltSensor', 'oid' => 10, 'class' => 'sensor'),
array('descr' => '3 Channel Power Sensor', 'prefix' => 'power3ChSensor', 'oid' => 11, 'class' => 'sensor'),
array('descr' => 'Outlet', 'prefix' => 'outlet', 'oid' => 12, 'class' => 'outlet'),
array('descr' => 'Fan Controller Monitor', 'prefix' => 'vsfc', 'oid' => 13, 'class' => 'sensor'),
array('descr' => '3 Channel Power Monitor', 'prefix' => 'ctrl3Ch', 'oid' => 14, 'class' => 'sensor'),
array('descr' => 'Amperage Controller', 'prefix' => 'analogSensor', 'oid' => 15, 'class' => 'powerSupply'),
// GEIST-MIB-V3::ctrlOutletName.1 = STRING: Outlet 1
array('descr' => 'Controlled outlet', 'prefix' => 'ctrlOutlet', 'oid' => 16, 'class' => 'outlet', 'avail' => 1),
array('descr' => 'Dew Point Sensor', 'prefix' => 'dewpointSensor', 'oid' => 17, 'class' => 'sensor'),
// GEIST-MIB-V3::digitalSensorSerial.1 = STRING: 8C00000493782754
// GEIST-MIB-V3::digitalSensorName.1 = STRING: CCAT
// GEIST-MIB-V3::digitalSensorAvail.1 = Gauge32: 1
array('descr' => 'Digital Sensor', 'prefix' => 'digitalSensor', 'oid' => 18, 'class' => 'sensor'),
array('descr' => 'DSTS Controller Sensor', 'prefix' => 'dstsSensor', 'oid' => 19, 'class' => 'sensor'),
array('descr' => 'City Power Sensor', 'prefix' => 'cpmSensor', 'oid' => 20, 'class' => 'sensor'),
// GEIST-MIB-V3::smokeAlarmSerial.1 = STRING: D900000498765432
// GEIST-MIB-V3::smokeAlarmName.1 = STRING: Smoke Alarm
// GEIST-MIB-V3::smokeAlarmAvail.1 = Gauge32: 1
array('descr' => 'Smoke Alarm Sensor', 'prefix' => 'smokeAlarm', 'oid' => 21, 'class' => 'sensor'),
array('descr' => '-48VDC Sensor', 'prefix' => 'neg48VdcSensor', 'oid' => 22, 'class' => 'sensor'),
array('descr' => '+30VDC Sensor', 'prefix' => 'pos30VdcSensor', 'oid' => 23, 'class' => 'sensor'),
array('descr' => 'Analog Sensor', 'prefix' => 'analogSensor', 'oid' => 24, 'class' => 'sensor'),
// GEIST-MIB-V3::ctrl3ChIECSerial.1 = STRING: 0000777654567777
// GEIST-MIB-V3::ctrl3ChIECName.1 = STRING: my-geist-pdu0
// GEIST-MIB-V3::ctrl3ChIECAvail.1 = Gauge32: 1
array('descr' => '3 Channel IEC Power Monitor', 'prefix' => 'ctrl3ChIEC', 'oid' => 25, 'class' => 'powerSupply'),
// GEIST-MIB-V3::climateRelaySerial.1 = STRING: 2878924802000000
// GEIST-MIB-V3::climateRelayName.1 = STRING: GRSO
// GEIST-MIB-V3::climateRelayAvail.1 = Gauge32: 1
array('descr' => 'Climate Relay Monitor', 'prefix' => 'climateRelay', 'oid' => 26, 'class' => 'sensor'),
// GEIST-MIB-V3::ctrlRelayName.1 = STRING: Relay-1
array('descr' => 'Controlled Relay', 'prefix' => 'ctrlRelay', 'oid' => 27, 'class' => 'relay', 'avail' => 1),
array('descr' => 'Airspeed Switch Sensor', 'prefix' => 'airSpeedSwitchSensor', 'oid' => 28, 'class' => 'sensor'),
// GEIST-MIB-V3::powerDMSerial.1 = STRING: E200000076221234
// GEIST-MIB-V3::powerDMName.1 = STRING: DM16 PDU
// GEIST-MIB-V3::powerDMAvail.1 = Gauge32: 1
array('descr' => 'DM16/48 Current Sensor', 'prefix' => 'powerDM', 'oid' => 29, 'class' => 'sensor'),
array('descr' => 'I/O Expander', 'prefix' => 'ioExpander', 'oid' => 30, 'class' => 'sensor'),
array('descr' => 'T3HD Sensor', 'prefix' => 't3hdSensor', 'oid' => 31, 'class' => 'sensor'),
array('descr' => 'THD Sensor', 'prefix' => 'thdSensor', 'oid' => 32, 'class' => 'sensor'),
array('descr' => '+60VDC Sensor', 'prefix' => 'pos60VdcSensor', 'oid' => 33, 'class' => 'sensor'),
array('descr' => '3Phase Outlet Control', 'prefix' => 'ctrl2CirTot', 'oid' => 34, 'class' => 'outlet'),
array('descr' => 'SC10 Sensor', 'prefix' => 'sc10Sensor', 'oid' => 35, 'class' => 'sensor'),
);
foreach ($geist_sensors as $sensor)
{
$oids = snmp_cache_table($device, $sensor['prefix'].'Table', array(), 'GEIST-MIB-V3');
foreach ($oids as $index => $entry)
{
// Index can only be int in the database, so we create our own from, this sensor is at 21239.2.$oid.
$system_index = $sensor['oid'] * 256 + $index;
if ($sensor['avail'] || $entry[$sensor['prefix'].'Avail'])
{
$inventory[$system_index] = array(
'entPhysicalDescr' => $sensor['descr'],
'entPhysicalClass' => $sensor['class'],
'entPhysicalName' => $entry[$sensor['prefix'].'Name'],
'entPhysicalSerialNum' => $entry[$sensor['prefix'].'Serial'],
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $relPos,
'entPhysicalMfgName' => 'Geist',
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
$relPos++;
}
}
}
}
unset($geist_sensors);
// EOF

View File

@ -0,0 +1,78 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
/// FIXME. Full rewrite and move to inventory stuff
$hrDevice_oids = array('hrDeviceEntry','hrProcessorEntry');
$hrDevices = array();
foreach ($hrDevice_oids as $oid) { $hrDevices = snmpwalk_cache_oid($device, $oid, $hrDevices, "HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES"); }
print_debug_vars($hrDevices);
if (is_array($hrDevices)) {
foreach ($hrDevices as $hrDevice) {
if (!is_numeric($hrDevice['hrDeviceIndex'])) {
print_debug("Empty hrDevice entry skipped:");
print_debug_vars($hrDevice, 1);
continue;
}
if ($hrDevice['hrDeviceType'] === 'hrDevicePrinter' &&
$hrDevice['hrDeviceStatus'] === 'unknown' &&
$hrDevice['hrPrinterStatus'] === 'unknown') {
print_debug("Broken hrDevice entry skipped:");
print_debug_vars($hrDevice, 1);
continue;
}
//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']))
{
$hrDevice['hrDeviceDescr'] = "Processor";
}
$update_array = array('hrDeviceType' => $hrDevice['hrDeviceType'],
'hrDeviceDescr' => $hrDevice['hrDeviceDescr'],
'hrDeviceStatus' => $hrDevice['hrDeviceStatus'],
'hrDeviceErrors' => $hrDevice['hrDeviceErrors']);
if ($hrDevice['hrDeviceType'] === "hrDeviceProcessor")
{
$update_array['hrProcessorLoad'] = $hrDevice['hrProcessorLoad'];
} else {
$update_array['hrProcessorLoad'] = array('NULL');
}
dbUpdate($update_array, 'hrDevice', 'device_id = ? AND hrDeviceIndex = ?', array($device['device_id'], $hrDevice['hrDeviceIndex']));
// FIXME -- check if it has updated, and print a U instead of a .
echo(".");
} else {
$inserted = dbInsert(array('hrDeviceIndex' => $hrDevice['hrDeviceIndex'], 'device_id' => $device['device_id'], 'hrDeviceType' => $hrDevice['hrDeviceType'], 'hrDeviceDescr' => $hrDevice['hrDeviceDescr'], 'hrDeviceStatus' => $hrDevice['hrDeviceStatus'], 'hrDeviceErrors' => $hrDevice['hrDeviceErrors']), 'hrDevice');
echo("+");
}
$valid_hrDevice[$hrDevice['hrDeviceIndex']] = 1;
}
}
foreach (dbFetchRows('SELECT * FROM `hrDevice` WHERE `device_id` = ?', array($device['device_id'])) as $test_hrDevice)
{
if (!$valid_hrDevice[$test_hrDevice['hrDeviceIndex']])
{
$deleted = dbDelete('hrDevice', '`hrDevice_id` = ?', array($test_hrDevice['hrDevice_id']));
echo("-");
if (OBS_DEBUG > 1) { print_vars($test_hrDevice); echo($deleted . " deleted"); }
}
}
unset($valid_hrDevice);
// EOF

View File

@ -0,0 +1,111 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$domain = snmpwalk_cache_oid($device, 'vcDomain', NULL, 'HPVC-MIB');
$domain = $domain[0];
// Domain
$array = array(
'entPhysicalName' => $domain['vcDomainName'],
'entPhysicalClass' => 'domain',
'entPhysicalIsFRU' => 'true',
'entPhysicalDescr' => $domain['vcDomainPrimaryAddressType'],
'entPhysicalAssetID' => $domain['vcDomainPrimaryAddress'],
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'HPE'
);
discover_inventory($device, '-1', $array, $mib);
$entries = snmpwalk_cache_oid($device, 'vcEnclosureTable', NULL, 'HPVC-MIB');
foreach ($entries as $index => $entry)
{
$array = array(
'entPhysicalName' => $entry['vcEnclosureName'],
'entPhysicalClass' => 'chassis',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 0,
'entPhysicalDescr' => $entry['vcEnclosureAddressType'],
'entPhysicalSerialNum' => $entry['vcEnclosureUUID'],
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'HPE'
);
if(isset($entry['vcEnclosureIndex']))
{
discover_inventory($device, $index, $array, $mib);
}
}
unset($entries, $array, $domain);
$entries = snmpwalk_cache_oid($device, 'vcPhysicalServerTable', NULL, 'HPVC-MIB');
// Blades
foreach ($entries as $index => $entry)
{
$array = array(
'entPhysicalName' => 'Slot '.$entry['vcPhysicalServerLocation.'],
'entPhysicalClass' => 'container',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $entry['vcPhysicalServerLocation.'],
'entPhysicalContainedIn' => $entry['vcPhysicalServerEnclosureIndex'],
'entPhysicalMfgName' => 'HPE'
);
//discover_inventory($device, '999'.$index, $array, $mib);
$array = array(
'entPhysicalName' => $entry['vcPhysicalServerProductName'],
//'entPhysicalDescr' => $entry['vcPhysicalServerProductName'],
'entPhysicalClass' => 'module',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $entry['vcPhysicalServerPartNumber'],
'entPhysicalSerialNum' => $entry['vcPhysicalServerSerialNumber'],
'entPhysicalContainedIn' => $entry['vcPhysicalServerEnclosureIndex'],
'entPhysicalParentRelPos' => 1,
'entPhysicalMfgName' => 'HPE'
);
if(isset($entry['vcPhysicalServerEnclosureIndex']))
{
discover_inventory($device, $index, $array, $mib);
}
}
$entries = snmpwalk_cache_oid($device, 'vcModuleTable', NULL, 'HPVC-MIB');
// Modules
foreach ($entries as $index => $entry)
{
list($entry['type'], $entry['index']) = explode('.', $entry['vcModuleEnclosurePointer']);
$array = array(
'entPhysicalName' => $entry['vcModuleProductName'],
//'entPhysicalDescr' => $entry['vcPhysicalServerProductName'],
'entPhysicalClass' => 'module',
'entPhysicalIsFRU' => 'true',
'entPhysicalModelName' => $entry['vcModulePartNumber'],
'entPhysicalSerialNum' => $entry['vcModuleSerialNumber'],
'entPhysicalContainedIn' => $entry['index'],
'entPhysicalParentRelPos' => $entry['vcModuleLocation'],
'entPhysicalMfgName' => 'HPE'
);
if(isset($entry['vcModuleLocation']))
{
discover_inventory($device, '999'.$index, $array, $mib);
}
}

View File

@ -0,0 +1,79 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
$jnxBoxDescr = snmp_get_oid($device, 'jnxBoxDescr.0', 'JUNIPER-MIB');
if ($jnxBoxDescr) {
$jnxBoxSerialNo = snmp_get_oid($device, 'jnxBoxSerialNo.0', 'JUNIPER-MIB');
// Insert chassis as index 1, everything hangs off of this.
$system_index = 1;
$inventory[$system_index] = array(
'entPhysicalDescr' => $jnxBoxDescr,
'entPhysicalClass' => 'chassis',
'entPhysicalName' => 'Chassis',
'entPhysicalSerialNum' => $jnxBoxSerialNo,
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'Juniper'
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
// Now fetch data for the rest of the hardware in the chassis
$data = snmpwalk_cache_oid($device, 'jnxContentsTable', array(), 'JUNIPER-MIB:JUNIPER-CHASSIS-DEFINES-MIB');
$data = snmpwalk_cache_oid($device, 'jnxFruTable', $data, 'JUNIPER-MIB:JUNIPER-CHASSIS-DEFINES-MIB');
$global_relPos = 0;
foreach ($data as $part) {
// Index can only be int in the database, so we create our own from 7.1.1.0:
$system_index = $part['jnxContentsContainerIndex'] * 16777216 + $part['jnxContentsL1Index'] * 65536 + $part['jnxContentsL2Index'] * 256 + $part['jnxContentsL3Index'];
if ($system_index != 0) {
if ($part['jnxContentsL2Index'] == 0 && $part['jnxContentsL3Index'] == 0) {
$containedIn = 1; // Attach to chassis inserted above
$global_relPos++; $relPos = $global_relPos;
} else {
$containerIndex = $part['jnxContentsContainerIndex'];
if ($containerIndex == 8) { $containerIndex--; } // Convert PIC (8) to FPC (7) parent
$containedIn = $containerIndex * 16777216 + $part['jnxContentsL1Index'] * 65536;
$relPos = $part['jnxContentsL2Index'];
}
// [jnxFruTemp] => 45 - Could link to sensor somehow? (like we do for ENTITY-SENSOR-MIB)
$inventory[$system_index] = array(
'entPhysicalDescr' => ucfirst($part['jnxContentsDescr']),
'entPhysicalHardwareRev' => $part['jnxContentsRevision'],
'entPhysicalClass' => isset($part['jnxFruType']) ? $part['jnxFruType'] : 'chassis',
'entPhysicalName' => ucfirst($part['jnxFruName'] ?: $part['jnxContentsDescr']),
'entPhysicalSerialNum' => str_replace([ 'S/N ', 'BUILTIN' ], '', $part['jnxContentsSerialNo']),
'entPhysicalModelName' => str_replace('BUILTIN', '', $part['jnxContentsPartNo']),
'entPhysicalVendorType' => $part['jnxContentsType'], //$part['jnxContentsModel'],
'entPhysicalIsFRU' => isset($part['jnxFruType']) ? 'true' : 'false',
'entPhysicalContainedIn' => $containedIn,
'entPhysicalParentRelPos' => $relPos,
'entPhysicalMfgName' => 'Juniper'
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
}
}
}
// EOF

View File

@ -0,0 +1,42 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mtxrBoardName = snmp_get_oid($device, 'mtxrBoardName.0', 'MIKROTIK-MIB');
$mtxrSerialNumber = snmp_get_oid($device, 'mtxrSerialNumber.0', 'MIKROTIK-MIB');
$mtxrLicSoftwareId = snmp_get_oid($device, 'mtxrLicSoftwareId.0', 'MIKROTIK-MIB');
$mtxrLicVersion = snmp_get_oid($device, 'mtxrLicVersion.0', 'MIKROTIK-MIB');
$mtxrFirmwareVersion = snmp_get_oid($device, 'mtxrFirmwareVersion.0', 'MIKROTIK-MIB');
$system_index = 1;
if ($mtxrSerialNumber)
{
$inventory[$system_index] = array(
'entPhysicalDescr' => 'MikroTik RouterBoard',
'entPhysicalClass' => 'chassis',
'entPhysicalName' => '',
'entPhysicalModelName' => $mtxrBoardName,
'entPhysicalSerialNum' => $mtxrSerialNumber,
'entPhysicalAssetID' => $mtxrLicSoftwareId,
'entPhysicalIsFRU' => 'false',
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => 0,
'entPhysicalFirmwareRev' => $mtxrFirmwareVersion,
'entPhysicalSoftwareRev' => $mtxrLicVersion,
'entPhysicalMfgName' => 'MikroTik'
);
discover_inventory($device, $system_index, $inventory[$system_index], "MIKROTIK-MIB");
print_debug_vars($inventory);
}
// EOF

View File

@ -0,0 +1,36 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$oids = snmpwalk_cache_oid($device, 'oacExpIMSysHwComponentsTable', array(), 'ONEACCESS-SYS-MIB');
foreach ($oids as $index => $entry)
{
//print_r($entry);
$index = (int)$entry['oacExpIMSysHwcIndex'] + 1;
$inventory[$index] = array(
'entPhysicalDescr' => $entry['oacExpIMSysHwcDescription'],
'entPhysicalName' => $entry['oacExpIMSysHwcProductName'],
'entPhysicalClass' => $entry['oacExpIMSysHwcClass'],
'entPhysicalModelName' => $entry['oacExpIMSysHwcType'],
//'entPhysicalAssetID' => $entry['oacExpIMSysHwcManufacturer'],
'entPhysicalSerialNum' => $entry['oacExpIMSysHwcSerialNumber'],
'entPhysicalIsFRU' => 'false',
'entPhysicalMfgName' => 'OneAccess',
'entPhysicalContainedIn' => ($entry['oacExpIMSysHwcIndex'] == 0 ? 0 : 1),
'entPhysicalParentRelPos' => ($entry['oacExpIMSysHwcIndex'] == 0 ? -1 : (int)$entry['oacExpIMSysHwcIndex']),
);
discover_inventory($device, $index, $inventory[$index], $mib);
}
// EOF

View File

@ -0,0 +1,104 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$ChasProductType = snmp_get_oid($device, 'chassisModelName.1', 'PERLE-MCR-MGT-MIB');
if ($ChasProductType)
{
$ChasDesc = snmp_get_oid($device, 'chassisModelDesc.1', 'PERLE-MCR-MGT-MIB');
$ChasSerNum = snmp_get_oid($device, 'chassisSerialNumber.1', 'PERLE-MCR-MGT-MIB');
$ChasMgmtSlot = snmp_get_oid($device, 'chassisCfgMgmtSlot.1', 'PERLE-MCR-MGT-MIB');
// Insert chassis as index 1, everything hangs off of this.
$system_index = 1;
$inventory[$system_index] = array(
'entPhysicalDescr' => $ChasProductType,
'entPhysicalClass' => 'chassis',
'entPhysicalName' => $ChasDesc,
'entPhysicalSerialNum' => $ChasSerNum,
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 0,
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'Perle'
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
// Now fetch data for the rest of the hardware in the chassis
$data = snmpwalk_cache_oid($device, 'mcrChassisSlotTable', array(), 'PERLE-MCR-MGT-MIB');
$data_sfp = snmpwalk_cache_oid($device, 'mcrSfpDmiModuleTable', array(), 'PERLE-MCR-MGT-MIB');
$relPos = 0;
foreach ($data as $part)
{
$system_index = $part['mcrChassisSlotIndex'] * 256;
$slotindex = $part['mcrChassisSlotIndex'];
if ($system_index != 0)
{
$containedIn = 1; // Attach to chassis inserted above
// snAgentBrdModuleStatus.6 = moduleRunning
// snAgentBrdModuleStatus.7 = moduleEmpty
if ($part['mcrModuleModelName'] != '')
{
$relPos++;
$inventory[$system_index] = array(
'entPhysicalDescr' => $part['mcrUserDefinedModuleName'] . "(".$part['mcrModuleModelDesc'].")",
'entPhysicalClass' => 'module',
'entPhysicalName' => $part['mcrModuleModelName'],
'entPhysicalSerialNum' => $part['mcrModuleSerialNumber'],
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => $containedIn,
'entPhysicalParentRelPos' => $relPos,
'entPhysicalFirmwareRev' => $part['mcrModuleBootloaderVersion'],
'entPhysicalSoftwareRev' => $part['mcrModuleFirmwareVersion'],
'entPhysicalMfgName' => 'Perle',
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
}
foreach ($data_sfp as $part_sfp)
{
if ($part_sfp['sfpDmiSlotIndex'] == $slotindex) {
$system_index_sfp = $part_sfp['sfpDmiSlotIndex'] * 256 + 1;
$relPos++;
if ($part_sfp['sfpDmiLinkReach625125'] != 0) { $range = $part_sfp['sfpDmiLinkReach625125']."m"; }
if ($part_sfp['sfpDmiLinkReach50125'] != 0) { $range = $part_sfp['sfpDmiLinkReach50125']."m"; }
if ($part_sfp['sfpDmiLinkReach9125'] != 0) { $range = ($part_sfp['sfpDmiLinkReach9125']/1000)."km"; }
$inventory[$system_index] = array(
'entPhysicalDescr' => $part_sfp['sfpDmiVendorName'] . " SFP (".$part_sfp['sfpDmiFiberWaveLength']."nm ".$range." ".$part_sfp['sfpDmiNominalBitRate']."Mbps)",
'entPhysicalClass' => 'module',
'entPhysicalName' => $part_sfp['sfpDmiVendorPartNumber'],
'entPhysicalSerialNum' => $part_sfp['sfpDmiVendorSerialNumber'],
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => $system_index,
'entPhysicalParentRelPos' => $relPos,
'entPhysicalMfgName' => $part_sfp['sfpDmiVendorName'],
);
discover_inventory($device, $system_index_sfp, $inventory[$system_index], $mib);
}
}
}
}
}
// EOF

View File

@ -0,0 +1,40 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mib = 'RAISECOM-FANMONITOR-MIB';
$serials = snmp_get_oid($device, 'raisecomFanCardSerialNumber.0', $mib); // STRING: "serial1;serial2"
$system_index = 101;
$i = 1;
foreach (explode(';', $serials) as $fan_card_serial)
{
if ($fan_card_serial != 'NULL') // the serial number is string 'NULL' when the fan card is absent
{
$inventory[$system_index] = array(
'entPhysicalDescr' => '',
'entPhysicalClass' => 'module',
'entPhysicalName' => "Fan Card $i",
'entPhysicalSerialNum' => $fan_card_serial,
'entPhysicalAssetID' => '',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 1, // ENTITY-MIB exposes the chassis with index 1.
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'Raisecom'
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
}
$system_index++;
$i++;
}
unset($mib, $serials, $system_index, $i, $fan_card_serial);
// EOF

View File

@ -0,0 +1,40 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$oids = snmpwalk_cache_oid($device, 'raisecomPowerSerialNumber', NULL, $mib);
$oids = snmpwalk_cache_oid($device, 'raisecomPowerType', $oids, $mib);
$system_index = 201;
foreach ($oids as $id => $entry)
{
$psu_type = strtoupper($entry['raisecomPowerType']);
if ($psu_type == 'AC' || $psu_type == 'DC')
{
$inventory[$system_index] = array(
'entPhysicalDescr' => "{$psu_type} Power Supply Unit",
'entPhysicalClass' => 'module',
'entPhysicalName' => "PSU $id",
'entPhysicalSerialNum' => $entry['raisecomPowerSerialNumber'],
'entPhysicalAssetID' => '',
'entPhysicalIsFRU' => 'true',
'entPhysicalContainedIn' => 1, // ENTITY-MIB exposes the chassis with index 1.
'entPhysicalParentRelPos' => -1,
'entPhysicalMfgName' => 'Raisecom'
);
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
}
$system_index++;
}
unset($mib, $system_index, $id, $entry, $psu_type);
// EOF

View File

@ -0,0 +1,45 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
echo("SNR-SWITCH-MIB ");
$ports_array = snmpwalk_cache_oid($device, "priPortTable", [], 'SNR-SWITCH-MIB', NULL, OBS_SNMP_ALL_MULTILINE);
print_debug_vars($ports_array);
if (safe_count($ports_array)) {
//$portCount = snmp_get_oid($device, 'portCount.0', 'SNR-SWITCH-MIB');
$ddminfo_array = snmpwalk_cache_oid($device, "ddmTranscBasicInfoTable", [], 'SNR-SWITCH-MIB');
print_debug_vars($ddminfo_array);
foreach ($ports_array as $index => $entry) {
$local_index = 100 + $entry['portIndex'];
$inventory[$local_index] = [
'entPhysicalDescr' => $entry['portType']." ".$ddminfo_array[$entry['portIndex']]['ddmTransSerialWaveLength'],
'entPhysicalClass' => 'port',
'entPhysicalName' => $entry['portName'],
'entPhysicalIsFRU' => 'false',
'entPhysicalModelName' => $ddminfo_array[$entry['portIndex']]['ddmTransSerialModelName'],
'entPhysicalVendorType' => $ddminfo_array[$entry['portIndex']]['ddmTransSerialTypeName'],
'entPhysicalContainedIn' => 1,
'entPhysicalParentRelPos' => $entry['portIndex'],
'entPhysicalSerialNum' => $entry['transceiverSn'],
'ifIndex' => $entry['portIndex'],
'entPhysicalMfgName' => $ddminfo_array[$entry['portIndex']]['ddmTransSerialVendorName'],
];
discover_inventory($device, $local_index, $inventory[$local_index], 'SNR-SWITCH-MIB');
}
}
print_debug_vars($inventory);
// EOF

View File

@ -0,0 +1,37 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
*
*/
$oids = snmp_cache_table($device, 'tmnxHwTable', NULL, 'TIMETRA-CHASSIS-MIB');
foreach ($oids as $index => $entry) {
list($chassis, $system_index) = explode('.', $index);
$inventory[$system_index] = array(
'entPhysicalDescr' => $entry['tmnxHwName'],
'entPhysicalClass' => $entry['tmnxHwClass'],
'entPhysicalName' => $entry['tmnxHwName'],
'entPhysicalAlias' => $entry['tmnxHwAlias'],
'entPhysicalAssetID' => $entry['tmnxHwAssetID'],
'entPhysicalIsFRU' => $entry['tmnxHwIsFRU'],
'entPhysicalSerialNum' => $entry['tmnxHwSerialNumber'],
'entPhysicalContainedIn' => $entry['tmnxHwContainedIn'],
'entPhysicalParentRelPos' => $entry['tmnxHwParentRelPos'],
'entPhysicalMfgName' => $entry['tmnxHwMfgString'] // 'Alcatel-Lucent'
);
if ($entry['tmnxHwContainedIn'] === '0' && $entry['tmnxHwParentRelPos'] === '-1') {
$inventory[$system_index]['entPhysicalName'] .= ' '.$chassis;
}
discover_inventory($device, $system_index, $inventory[$system_index], $mib);
}
// EOF

View File

@ -0,0 +1,303 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
/**
* @var array $config
* @var array $device
* @var string $module
* @global array $ip_data
*/
global $ip_data;
$ip_data = array('ipv4' => array(),
'ipv6' => array());
//$valid['ip-addresses'] = array();
$include_dir = 'includes/discovery/ip-addresses';
$include_order = 'default'; // Use MIBs from default os definitions by first!
include($config['install_dir'] . "/includes/include-dir-mib.inc.php");
foreach (get_device_mibs_permitted($device) as $mib)
{
// Detect addresses by definitions
if (is_array($config['mibs'][$mib]['ip-address']))
{
print_cli_data_field($mib);
foreach ($config['mibs'][$mib]['ip-address'] as $oid_data)
{
discover_ip_address_definition($device, $mib, $oid_data);
}
print_cli(PHP_EOL);
}
}
// Try discovery IP addresses in VRF SNMP contexts (currently actual only on Cisco Nexus)
if (safe_empty($device['snmp_context']) && // Device not already with context
isset($config['os'][$device['os']]['snmp']['virtual']) && $config['os'][$device['os']]['snmp']['virtual'] && // Context permitted for os
$vrf_contexts = safe_json_decode(get_entity_attrib('device', $device, 'vrf_contexts'))) { // SNMP VRF context discovered for device
// Keep original device array
$device_original = $device;
foreach ($vrf_contexts as $vrf_name => $snmp_virtual) {
print_message("Addresses in Virtual Routing: $vrf_name...");
$device = snmp_virtual_device($device_original, $snmp_virtual);
//$device['snmp_context'] = $snmp_context;
if (!$device['snmp_retries']) {
// force less retries on vrf requests.. if not set in db
$device['snmp_retries'] = 1;
}
$include_dir = 'includes/discovery/ip-addresses';
$include_order = 'default'; // Use MIBs from default os definitions by first!
include($config['install_dir']."/includes/include-dir-mib.inc.php");
}
// Clean
$device = $device_original;
unset($device_original);
}
// Process IP Addresses
$table_rows = array();
$check_networks = array();
foreach (array('ipv4', 'ipv6') as $ip_version)
{
print_debug_vars($ip_data[$ip_version]);
// Caching old IP addresses table
$query = 'SELECT * FROM `'.$ip_version.'_addresses`
WHERE `device_id` = ?';
foreach (dbFetchRows($query, array($device['device_id'])) as $entry)
{
if (!strlen($entry['ifIndex']))
{
// Compatibility
$ifIndex = dbFetchCell('SELECT `ifIndex` FROM `ports` WHERE `port_id` = ? AND `deleted` = ?', array($entry['port_id'], 0));
} else {
$ifIndex = $entry['ifIndex'];
}
$old_table[$ip_version][$ifIndex][$entry[$ip_version.'_address']] = $entry;
}
if (!safe_count($ip_data[$ip_version]) && !safe_count($old_table[$ip_version]))
{
// Skip if walk and DB empty
continue;
}
// Process founded IP addresses
foreach ($ip_data[$ip_version] as $ifIndex => $addresses)
{
$port = get_port_by_index_cache($device, $ifIndex);
if (is_array($port) && !$port['deleted'])
{
$port_id = $port['port_id'];
} else {
// Allow to store IP addresses without associated port, but ifIndex available
// ie, Nortel/Avaya devices have hidden vlan ifIndexes
$port_id = '0';
}
print_debug_vars($port);
print_debug_vars($addresses);
foreach ($addresses as $ip_address => $entry)
{
if ($ip_version === 'ipv4')
{
// IPv4
$ip_prefix = $entry['prefix'];
$ip_origin = $entry['origin'];
$ip_compressed = $ip_address; // just for compat with IPv6
$ip_type = $entry['type'];
$addr = Net_IPv4::parseAddress($ip_address.'/'.$ip_prefix);
$ip_cidr = $addr->bitmask;
$ip_network = $addr->network . '/' . $ip_cidr;
$full_address = $ip_address . '/' . $ip_cidr;
$new_address = [
'port_id' => $port_id,
'ifIndex' => $ifIndex,
'device_id' => $device['device_id'],
'ipv4_address' => $ip_address,
'ipv4_binary' => inet_pton($ip_address),
'ipv4_prefixlen' => $ip_cidr,
'ipv4_type' => $ip_type
];
} else {
// IPv6
$ip_prefix = $entry['prefix'];
$ip_origin = $entry['origin'];
$ip_compressed = Net_IPv6::compress($ip_address, TRUE);
$full_address = $ip_compressed.'/'.$ip_prefix;
$ip_type = $entry['type'];
$ip_network = Net_IPv6::getNetmask($full_address) . '/' . $ip_prefix;
//$full_compressed = $ip_compressed.'/'.$ipv6_prefixlen;
$new_address = [
'port_id' => $port_id,
'ifIndex' => $ifIndex,
'device_id' => $device['device_id'],
'ipv6_address' => $ip_address,
'ipv6_binary' => inet_pton($ip_address),
'ipv6_compressed' => $ip_compressed,
'ipv6_prefixlen' => $ip_prefix,
'ipv6_type' => $ip_type,
'ipv6_origin' => $ip_origin
];
}
// VRFs
$sql = "SELECT `vrf_id` FROM `vrfs` WHERE `device_id` = ? AND `vrf_name` = ?";
if (strlen($entry['vrf']) &&
$vrf_id = dbFetchCell($sql, [ $device['device_id'], $entry['vrf'] ]))
{
$new_address['vrf_id'] = $vrf_id;
}
// Check network
$ip_network_id = dbFetchCell('SELECT `'.$ip_version.'_network_id` FROM `'.$ip_version.'_networks` WHERE `'.$ip_version.'_network` = ?', array($ip_network));
if (empty($ip_network_id))
{
// Add new network
$ip_network_id = dbInsert(array($ip_version.'_network' => $ip_network), $ip_version.'_networks');
//echo('N');
}
$new_address[$ip_version.'_network_id'] = $ip_network_id;
// Add to display table
$table_rows[] = array($ifIndex, truncate($port['ifDescr'], 30), nicecase($ip_version), $full_address, $ip_network, $entry['type'], $ip_origin);
// Check IP in DB
$update_array = array();
if (isset($old_table[$ip_version][$ifIndex][$ip_address]))
{
$old_address = &$old_table[$ip_version][$ifIndex][$ip_address];
$ip_address_id = $old_address[$ip_version.'_address_id'];
$params = array_diff(array_keys($old_address), [ 'device_id', $ip_version.'_address_id' ]);
foreach ($params as $param)
{
if ($param === 'ipv6_binary')
{
// Compare decoded binary IPv6 address
if (inet_ntop($old_address[$param]) != $new_address['ipv6_compressed']) { $update_array[$param] = $new_address[$param]; }
}
elseif ($param === 'ipv4_binary')
{
// Compare decoded binary IPv4 address
if (inet_ntop($old_address[$param]) != $new_address['ipv4_address']) { $update_array[$param] = $new_address[$param]; }
} else {
// All other params as string
if ($old_address[$param] != $new_address[$param])
{
if (in_array($param, [ 'vrf_id', 'ifIndex', $ip_version.'_type' ]) && !strlen($new_address[$param]))
{
$update_array[$param] = [ 'NULL' ];
} else {
$update_array[$param] = $new_address[$param];
}
}
}
}
$update_count = count($update_array);
if ($update_count === 1 && (isset($update_array['ipv4_binary']) || isset($update_array['ipv6_binary'])))
{
// Silent update binary address after upgrade
dbUpdate($update_array, $ip_version.'_addresses', '`'.$ip_version.'_address_id` = ?', array($old_address[$ip_version.'_address_id']));
$GLOBALS['module_stats'][$module]['unchanged']++;
}
elseif ($update_count)
{
// Updated
dbUpdate($update_array, $ip_version.'_addresses', '`'.$ip_version.'_address_id` = ?', array($old_address[$ip_version.'_address_id']));
if (!$port_id)
{
log_event("IP address changed: $ip_compressed/".$old_address[$ip_version.'_prefixlen']." -> $full_address", $device, 'device', $device['device_id']);
}
else if (isset($update_array['port_id']))
{
// Address moved to another port
log_event("IP address removed: $ip_compressed/".$old_address[$ip_version.'_prefixlen'], $device, 'port', $old_address['port_id']);
log_event("IP address added: $full_address", $device, 'port', $port_id);
} else {
// Changed prefix/cidr
log_event("IP address changed: $ip_compressed/".$old_address[$ip_version.'_prefixlen']." -> $full_address", $device, 'port', $port_id);
}
$GLOBALS['module_stats'][$module]['updated']++; //echo "U";
$check_networks[$ip_version][$ip_network_id] = 1;
} else {
// Not changed
$GLOBALS['module_stats'][$module]['unchanged']++; //echo ".";
}
} else {
// New IP
$update_array = $new_address;
$ip_address_id = dbInsert($update_array, $ip_version.'_addresses');
if ($port_id)
{
log_event("IP address added: $full_address", $device, 'port', $port_id);
} else {
log_event("IP address added: $full_address", $device, 'device', $device['device_id']);
}
$GLOBALS['module_stats'][$module]['added']++; //echo "+";
}
$valid[$ip_version][$ip_address_id] = $full_address . ':' . $port_id;
}
}
// Refetch and clean IP addresses from DB
foreach (dbFetchRows($query, array($device['device_id'])) as $entry)
{
$ip_address_id = $entry[$ip_version.'_address_id'];
if (!isset($valid[$ip_version][$ip_address_id]))
{
$full_address = ($ip_version === 'ipv4' ? $entry['ipv4_address'] : $entry['ipv6_compressed']);
$full_address .= '/' . $entry[$ip_version.'_prefixlen'];
// Delete IP
dbDelete($ip_version.'_addresses', '`'.$ip_version.'_address_id` = ?', array($ip_address_id));
if ($port_id)
{
log_event("IP address removed: $full_address", $device, 'port', $entry['port_id']);
} else {
log_event("IP address removed: $full_address", $device, 'device', $entry['device_id']);
}
$GLOBALS['module_stats'][$module]['deleted']++; //echo "-";
$check_networks[$ip_version][$entry[$ip_version.'_network_id']] = 1;
}
}
// Clean networks
foreach ($check_networks[$ip_version] as $ip_network_id => $n)
{
//$count = dbFetchCell('SELECT COUNT(*) FROM `'.$ip_version.'_addresses` WHERE `'.$ip_version.'_network_id` = ?', array($ip_network_id));
//if (empty($count))
if (!dbExist($ip_version.'_addresses', '`'.$ip_version.'_network_id` = ?', array($ip_network_id)))
{
dbDelete($ip_version.'_networks', '`'.$ip_version.'_network_id` = ?', array($ip_network_id));
//echo('n');
}
}
}
$table_headers = array('%WifIndex%n', '%WifDescr%n', '%WIP: Version%n', '%WAddress%n', '%WNetwork%n', '%WType%n', '%WOrigin%n');
print_cli_table($table_rows, $table_headers);
// Clean
unset($ip_data, $check_networks, $check_ipv6_mib, $update_array, $old_table, $table_rows, $table_headers);
// EOF

View File

@ -0,0 +1,66 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
$ip_version = 'ipv6';
if (!safe_count($ip_data[$ip_version])) {
// Get IP addresses from CISCO-IETF-IP-MIB
//cIpAddressIfIndex.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:02" = 450
//cIpAddressPrefix.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:02" = cIpAddressPfxOrigin.450.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:00".64
//cIpAddressOrigin.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:02" = manual
//Origins: 1:other, 2:manual, 4:dhcp, 5:linklayer, 6:random
$flags = OBS_SNMP_ALL ^ OBS_QUOTES_STRIP;
$oid_data = array();
foreach (array('cIpAddressIfIndex', 'cIpAddressPrefix', 'cIpAddressType', 'cIpAddressOrigin') as $oid)
{
$oid_data = snmpwalk_cache_twopart_oid($device, $oid.'.'.$ip_version, $oid_data, 'CISCO-IETF-IP-MIB', NULL, $flags);
if ($oid == 'cIpAddressIfIndex' && snmp_status() === FALSE)
{
break; // Stop walk, not exist table
}
}
//print_vars($oid_data);
// IPv6z
if (isset($oid_data[$ip_version . 'z']))
{
$oid_data[$ip_version] = array_merge((array)$oid_data[$ip_version], $oid_data[$ip_version . 'z']);
}
// Rewrite CISCO-IETF-IP-MIB array
foreach ($oid_data[$ip_version] as $ip_snmp => $entry)
{
$ip_address = hex2ip($ip_snmp);
$ifIndex = $entry['cIpAddressIfIndex'];
$tmp_prefix = explode('.', $entry['cIpAddressPrefix']);
$entry['cIpAddressPrefix'] = end($tmp_prefix);
/*
$ip_data[$ip_version][$ifIndex][$ip_address] = array('ifIndex' => $ifIndex,
'ip' => $ip_address,
'prefix' => $entry['cIpAddressPrefix'],
'type' => $entry['cIpAddressType'],
'origin' => $entry['cIpAddressOrigin']);
*/
$data = [
'ifIndex' => $ifIndex,
'ip' => $ip_address,
'prefix' => $entry['cIpAddressPrefix'],
'type' => $entry['cIpAddressType'],
'origin' => $entry['cIpAddressOrigin']
];
discover_add_ip_address($device, $mib, $data);
}
}
unset($ifIndex, $ip_address, $tmp_prefix, $oid_data, $flags);
// EOF

View File

@ -0,0 +1,72 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
*
*/
// DNOS-SWITCHING-MIB::agentNetworkIPAddress.0 = IpAddress: 192.168.1.195
// DNOS-SWITCHING-MIB::agentNetworkSubnetMask.0 = IpAddress: 255.255.254.0
// DNOS-SWITCHING-MIB::agentNetworkDefaultGateway.0 = IpAddress: 192.168.1.100
// DNOS-SWITCHING-MIB::agentNetworkBurnedInMacAddress.0 = Hex-STRING: 68 4F 64 D6 DF BB
// DNOS-SWITCHING-MIB::agentNetworkLocalAdminMacAddress.0 = Hex-STRING: 00 00 00 00 00 00
// DNOS-SWITCHING-MIB::agentNetworkMacAddressType.0 = INTEGER: burned-in(1)
// DNOS-SWITCHING-MIB::agentNetworkConfigProtocol.0 = INTEGER: none(1)
// DNOS-SWITCHING-MIB::agentNetworkConfigProtocolDhcpRenew.0 = INTEGER: normalOperation(0)
// DNOS-SWITCHING-MIB::agentNetworkMgmtVlan.0 = INTEGER: 4
$oids = snmp_get_multi_oid($device, 'agentNetworkIPAddress.0 agentNetworkSubnetMask.0 agentNetworkBurnedInMacAddress.0 agentNetworkMgmtVlan.0', [], $mib);
print_debug_vars($oids);
$entry = $oids[0];
if ($port_id = get_port_id_by_ifDescr($device['device_id'], 'Vl'.$entry['agentNetworkMgmtVlan']))
{
// By Vlan
$port = get_port_by_id_cache($port_id);
$ifIndex = $port['ifIndex'];
}
elseif ($port_id = get_port_id_by_mac($device['device_id'], $entry['agentNetworkBurnedInMacAddress']))
{
// By MAC address
$port = get_port_by_id_cache($port_id);
$ifIndex = $port['ifIndex'];
} else {
$ifIndex = 0;
}
$data = [
'ifIndex' => $ifIndex,
'ip' => $entry['agentNetworkIPAddress'],
'mask' => $entry['agentNetworkSubnetMask']
];
discover_add_ip_address($device, $mib, $data);
// DNOS-SWITCHING-MIB::agentNetworkIpv6AdminMode.0 = INTEGER: enabled(1)
// DNOS-SWITCHING-MIB::agentNetworkIpv6AddrPrefixLength."........jOd....." = INTEGER: 64
// DNOS-SWITCHING-MIB::agentNetworkIpv6AddrEuiFlag."........jOd....." = INTEGER: enabled(1)
// DNOS-SWITCHING-MIB::agentNetworkIpv6AddrStatus."........jOd....." = INTEGER: active(1)
// DNOS-SWITCHING-MIB::agentNetworkIpv6AddressAutoConfig.0 = INTEGER: disable(2)
// DNOS-SWITCHING-MIB::agentNetworkIpv6ConfigProtocol.0 = INTEGER: none(1)
if (snmp_get_oid($device, 'agentNetworkIpv6AdminMode.0', $mib) === 'enabled')
{
// IPv6
$oids = snmpwalk_cache_oid($device, 'agentNetworkIpv6AddrPrefixLength', [], $mib, NULL, OBS_SNMP_ALL_TABLE);
$oids = snmpwalk_cache_oid($device, 'agentNetworkIpv6AddrStatus', $oids, $mib, NULL, OBS_SNMP_ALL_TABLE);
print_debug_vars($oids);
foreach ($oids as $ip_address => $entry)
{
if ($entry['agentNetworkIpv6AddrStatus'] !== 'active') { continue; }
$data = [
'ifIndex' => $ifIndex,
'ip' => $ip_address,
'prefix' => $entry['agentNetworkIpv6AddrPrefixLength']
];
discover_add_ip_address($device, $mib, $data);
}
}
// EOF

View File

@ -0,0 +1,104 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// F5-BIGIP-SYSTEM-MIB
//if (!count($ip_data['ipv4']) && !count($ip_data['ipv6']))
//{
// Note, F5-BIGIP support IP-MIB, but on some firmware versions return not correct ifIndexes, this MIB uses correct indexes
$mib = 'F5-BIGIP-SYSTEM-MIB';
// Get IP addresses from F5-BIGIP-SYSTEM-MIB
//F5-BIGIP-SYSTEM-MIB::sysSelfIpAddrType."/Common/157.122.148.244" = INTEGER: ipv4(1)
//F5-BIGIP-SYSTEM-MIB::sysSelfIpAddrType."/Common/vlan2422HeFei-CU1G" = INTEGER: ipv4(1)
//F5-BIGIP-SYSTEM-MIB::sysSelfIpAddr."/Common/157.122.148.244" = Hex-STRING: 9D 7A 94 F4
//F5-BIGIP-SYSTEM-MIB::sysSelfIpAddr."/Common/vlan2422HeFei-CU1G" = Hex-STRING: 2A 9D 09 42
//F5-BIGIP-SYSTEM-MIB::sysSelfIpNetmask."/Common/vlan2422HeFei-CU1G" = Hex-STRING: FF FF FF F8
//F5-BIGIP-SYSTEM-MIB::sysSelfIpNetmask."/Common/vlan3682HeFei-CU2G" = Hex-STRING: FF FF FF F0
//F5-BIGIP-SYSTEM-MIB::sysSelfIpVlanName."/Common/157.122.148.244" = STRING: /Common/vlan3617
//F5-BIGIP-SYSTEM-MIB::sysSelfIpVlanName."/Common/vlan2422HeFei-CU1G" = STRING: /Common/vlan2422HeFei_CU1G
//F5-BIGIP-SYSTEM-MIB::sysSelfIpUnitId."/Common/157.122.148.244" = INTEGER: 1
//F5-BIGIP-SYSTEM-MIB::sysSelfIpUnitId."/Common/vlan2422HeFei-CU1G" = INTEGER: 0
//$flags = OBS_SNMP_ALL ^ OBS_QUOTES_STRIP;
$flags = OBS_SNMP_ALL;
$oid_data = array();
foreach (array('sysSelfIpAddrType', 'sysSelfIpVlanName', 'sysSelfIpUnitId', 'sysSelfIpAddr', 'sysSelfIpNetmask') as $oid)
{
$oid_data = snmpwalk_cache_oid($device, $oid, $oid_data, $mib, NULL, $flags);
if ($oid == 'sysSelfIpAddrType' && $GLOBALS['snmp_status'] === FALSE)
{
break; // Stop walk, not exist table
}
}
//print_vars($oid_data);
$query = 'SELECT `port_id`, `ifIndex`, `ifDescr` FROM `ports` WHERE `device_id` = ? AND `deleted` = ?';
foreach (dbFetchRows($query, array($device['device_id'], 0)) as $entry)
{
$ports_ifDescr[$entry['ifDescr']] = $entry;
}
// Rewrite F5-BIGIP-SYSTEM-MIB array
foreach ($oid_data as $ip_name => $entry)
{
if ($entry['sysSelfIpUnitId'] != '0') { continue; } // Skip all except self Unit addresses
$ifName = $entry['sysSelfIpVlanName'];
if (isset($ports_ifDescr[$ifName]))
{
$ifIndex = $ports_ifDescr[$ifName]['ifIndex'];
$ip_version = $entry['sysSelfIpAddrType'];
$ip_address = hex2ip($entry['sysSelfIpAddr']);
$ip_mask = hex2ip($entry['sysSelfIpNetmask']);
if ($ip_version == 'ipv4')
{
$ip_mask_fix = explode('.', $ip_mask);
if (empty($ip_mask) || count($ip_mask_fix) != 4)
{
$ip_mask = '255.255.255.255';
}
} else {
// IPv6 - not tested
$prefix = 0;
$m = str_split($ip_mask);
foreach ($m as $c) {
if ($c == ":") { continue; }
if ($c == "0") { break; }
$bin = base_convert($c, 16, 2);
$bin = trim($bin,"0");
$prefix += strlen($bin);
}
}
/*
$ip_data[$ip_version][$ifIndex][$ip_address] = array('ifIndex' => $ifIndex,
'ip' => $ip_address,
'mask' => $ip_mask,
'prefix' => $prefix);
*/
$data = [
'ifIndex' => $ifIndex,
'ip' => $ip_address,
'mask' => $ip_mask,
'prefix' => $prefix
];
discover_add_ip_address($device, $mib, $data);
}
unset($ifName, $ifIndex, $ip_version, $ip_address, $ip_mask, $prefix);
}
//}
unset($ports_ifDescr, $ifIndex, $ip_address, $ip_mask_fix, $oid_data, $flags);
// EOF

View File

@ -0,0 +1,222 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
// IPv4 addresses
$ip_version = 'ipv4';
// NOTE. By default used old tables IP-MIB, because some weird vendors use "random" data in new tables:
//ipAddressIfIndex.ipv4."94.142.242.194" = 2
//ipAddressIfIndex.ipv4."127.0.0.1" = 1
//ipAddressPrefix.ipv4."94.142.242.194" = ipAddressPrefixOrigin.2.ipv4."88.0.0.0".5
//ipAddressPrefix.ipv4."127.0.0.1" = ipAddressPrefixOrigin.1.ipv4."51.101.48.0".0
// Get IP addresses from IP-MIB (old table)
// Normal:
//IP-MIB::ipAdEntIfIndex.10.0.0.130 = 193
//IP-MIB::ipAdEntNetMask.10.0.0.130 = 255.255.255.252
// Cisco Nexus (seems as first number is interface index):
//IP-MIB::ipAdEntIfIndex.4.10.44.44.110 = 151192525
//IP-MIB::ipAdEntNetMask.4.10.44.44.110 = 255.255.255.0
// Bintec Elmeg (seems as last number is counter number 1,2,3,etc)
//IP-MIB::ipAdEntIfIndex.192.168.1.254.0 = 1000
//IP-MIB::ipAdEntNetMask.192.168.1.254.0 = 255.255.255.0
$oid_data = snmpwalk_cache_oid($device, 'ipAdEntIfIndex', [], 'IP-MIB');
if (snmp_status()) {
$oid_data = snmpwalk_cache_oid($device, 'ipAdEntNetMask', $oid_data, 'IP-MIB');
if (is_numeric(array_key_first($oid_data))) {
// Some devices report just numbers instead ip address:
// IP-MIB::ipAdEntAddr.0 = IpAddress: 0.0.0.0
// IP-MIB::ipAdEntAddr.2130706433 = IpAddress: 127.0.0.1
// IP-MIB::ipAdEntIfIndex.0 = INTEGER: 6620672
// IP-MIB::ipAdEntIfIndex.2130706433 = INTEGER: 6625280
// IP-MIB::ipAdEntNetMask.0 = IpAddress: 255.255.255.0
// IP-MIB::ipAdEntNetMask.2130706433 = IpAddress: 255.255.255.255
// IP-MIB::ipAdEntBcastAddr.0 = INTEGER: 1
// IP-MIB::ipAdEntBcastAddr.2130706433 = INTEGER: 0
$oid_data = snmpwalk_cache_oid($device, 'ipAdEntAddr', $oid_data, 'IP-MIB');
}
}
// Rewrite IP-MIB array
foreach ($oid_data as $ip_address => $entry) {
$ifIndex = $entry['ipAdEntIfIndex'];
$ip_address_fix = explode('.', $ip_address);
switch (count($ip_address_fix)) {
case 4:
break; // Just normal IPv4 address
case 5:
if ($device['os_group'] === 'bintec') {
// Bintec Elmeg, see: http://jira.observium.org/browse/OBSERVIUM-1958
unset($ip_address_fix[4]);
} else {
// Cisco Nexus, see: http://jira.observium.org/browse/OBSERVIUM-728
unset($ip_address_fix[0]);
}
$ip_address = implode('.', $ip_address_fix);
break;
default:
if (isset($entry['ipAdEntAddr']) && get_ip_version($entry['ipAdEntAddr'])) {
$ip_address = $entry['ipAdEntAddr'];
} else {
print_debug("Detected unknown IPv4 address: $ip_address");
continue 2;
}
}
$ip_mask_fix = explode('.', $entry['ipAdEntNetMask']);
if ($ip_mask_fix[0] < 255 && $ip_mask_fix[1] <= '255' && $ip_mask_fix[2] <= '255' && $ip_mask_fix[3] == '255')
{
// On some D-Link used wrong masks: 252.255.255.255, 0.255.255.255
$entry['ipAdEntNetMask'] = $ip_mask_fix[3] . '.' . $ip_mask_fix[2] . '.' . $ip_mask_fix[1] . '.' . $ip_mask_fix[0];
}
if (empty($entry['ipAdEntNetMask']) || safe_count($ip_mask_fix) != 4)
{
$entry['ipAdEntNetMask'] = '255.255.255.255';
}
$data = [
'ifIndex' => $ifIndex,
'ip' => $ip_address,
'mask' => $entry['ipAdEntNetMask']
];
discover_add_ip_address($device, $mib, $data);
}
// Get IP addresses from IP-MIB (new table, both IPv4/IPv6)
$flags = OBS_SNMP_ALL ^ OBS_QUOTES_STRIP;
$oid_data = array();
foreach (array('ipAddressIfIndex', 'ipAddressType', 'ipAddressPrefix', 'ipAddressOrigin') as $oid)
{
$oid_data = snmpwalk_cache_twopart_oid($device, $oid, $oid_data, 'IP-MIB', NULL, $flags);
if ($oid === 'ipAddressIfIndex' && !snmp_status()) {
break; // Stop walk, not exist table
}
}
//print_vars($oid_data);
// IPv4 addresses
if (!safe_count($ip_data[$ip_version])) {
//IP-MIB::ipAddressIfIndex.ipv4."198.237.180.2" = 8
//IP-MIB::ipAddressPrefix.ipv4."198.237.180.2" = ipAddressPrefixOrigin.8.ipv4."198.237.180.2".32
//IP-MIB::ipAddressOrigin.ipv4."198.237.180.2" = manual
//Origins: 1:other, 2:manual, 4:dhcp, 5:linklayer, 6:random
// IPv4z (not sure, never seen)
if (isset($oid_data[$ip_version . 'z'])) {
$oid_data[$ip_version] = array_merge((array)$oid_data[$ip_version], $oid_data[$ip_version . 'z']);
}
// Rewrite IP-MIB array
foreach ($oid_data[$ip_version] as $ip_address => $entry) {
if (in_array($entry['ipAddressType'], $GLOBALS['config']['ip-address']['ignore_type'])) { continue; } // Skip broadcasts
//$ip_address = str_replace($ip_version.'.', '', $key);
$ifIndex = $entry['ipAddressIfIndex'];
// ipAddressOrigin.ipv4.169.254.1.1.23 = manual
$ip_address_fix = explode('.', $ip_address);
$index_prefix = NULL;
switch (safe_count($ip_address_fix)) {
case 5:
// get last number as prefix
$index_prefix = array_pop($ip_address_fix);
$ip_address = implode('.', $ip_address_fix);
break;
case 4:
// Common, no need for changes
break;
default:
print_debug("Unknown IP index: $ip_address");
continue 2;
}
$tmp_prefix = explode('.', $entry['ipAddressPrefix']);
$entry['ipAddressPrefix'] = end($tmp_prefix);
if (!is_intnum($entry['ipAddressPrefix']) && is_intnum($index_prefix)) {
$entry['ipAddressPrefix'] = $index_prefix;
}
$data = [
'ifIndex' => $ifIndex,
'ip' => $ip_address,
'prefix' => $entry['ipAddressPrefix'],
'type' => $entry['ipAddressType'],
'origin' => $entry['ipAddressOrigin']
];
discover_add_ip_address($device, $mib, $data);
}
}
// IPv6 addresses
$ip_version = 'ipv6';
//ipAddressIfIndex.ipv6."00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01" = 1
//ipAddressPrefix.ipv6."00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01" = ipAddressPrefixOrigin.1.ipv6."00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01".128
//ipAddressOrigin.ipv6."00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01" = manual
//Origins: 1:other, 2:manual, 4:dhcp, 5:linklayer, 6:random
// IPv6z
if (isset($oid_data[$ip_version . 'z'])) {
$oid_data[$ip_version] = array_merge((array)$oid_data[$ip_version], $oid_data[$ip_version . 'z']);
}
// Rewrite IP-MIB array
$check_ipv6_mib = FALSE; // Flag for additionally check IPv6-MIB
foreach ($oid_data[$ip_version] as $ip_snmp => $entry) {
if (str_contains($ip_snmp, '.')) {
// incorrect indexes with prefix
// ipAddressOrigin.ipv6.65152.0.0.0.521.4095.65033.51218.27 = manual
$ip_address_fix = explode('.', $ip_snmp);
$index_prefix = NULL;
switch (count($ip_address_fix)) {
case 9:
// get last number as prefix
$index_prefix = array_pop($ip_address_fix);
//break;
case 8:
$ip_address_fix = array_map('dechex', $ip_address_fix);
$ip_address = ip_uncompress(implode(':', $ip_address_fix));
break;
default:
print_debug("Unknown IP index: $ip_snmp");
continue 2;
}
} else {
// Common address index
$ip_address = hex2ip($ip_snmp);
}
$ifIndex = $entry['ipAddressIfIndex'];
if ($entry['ipAddressPrefix'] === 'zeroDotZero') {
// Additionally walk IPV6-MIB, especially in JunOS because they spit at world standards
// See: http://jira.observium.org/browse/OBSERVIUM-1271
$check_ipv6_mib = TRUE;
} else {
$tmp_prefix = explode('.', $entry['ipAddressPrefix']);
$entry['ipAddressPrefix'] = end($tmp_prefix);
}
if (!is_intnum($entry['ipAddressPrefix']) && is_intnum($index_prefix)) {
$entry['ipAddressPrefix'] = $index_prefix;
$check_ipv6_mib = FALSE;
}
$data = [
'ifIndex' => $ifIndex,
'ip' => $ip_address,
'prefix' => $entry['ipAddressPrefix'],
'type' => $entry['ipAddressType'],
'origin' => $entry['ipAddressOrigin']
];
discover_add_ip_address($device, $mib, $data);
}
unset($ifIndex, $ip_address, $tmp_prefix, $oid_data);
// EOF

View File

@ -0,0 +1,55 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
$ip_version = 'ipv6';
if ($check_ipv6_mib || !safe_count($ip_data[$ip_version])) { // Note, $check_ipv6_mib set in IP-MIB discovery
// Get IP addresses from IPV6-MIB
//ipv6AddrPfxLength.20.254.192.0.0.0.0.0.0.0.10.0.0.0.0.0.4 = 64
//ipv6AddrPfxLength.573.42.1.183.64.0.1.130.32.0.0.0.0.0.0.0.2 = 126
//ipv6AddrType.20.254.192.0.0.0.0.0.0.0.10.0.0.0.0.0.4 = stateful
//ipv6AddrType.573.42.1.183.64.0.1.130.32.0.0.0.0.0.0.0.2 = stateful
//ipv6AddrAnycastFlag.20.254.192.0.0.0.0.0.0.0.10.0.0.0.0.0.4 = false
//ipv6AddrAnycastFlag.573.42.1.183.64.0.1.130.32.0.0.0.0.0.0.0.2 = false
//ipv6AddrStatus.20.254.192.0.0.0.0.0.0.0.10.0.0.0.0.0.4 = preferred
//ipv6AddrStatus.573.42.1.183.64.0.1.130.32.0.0.0.0.0.0.0.2 = preferred
//Types: stateless(1), stateful(2), unknown(3)
$oid_data = snmpwalk_cache_twopart_oid($device, 'ipv6AddrEntry', array(), 'IPV6-MIB', NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
//print_vars($oid_data);
// Rewrite IPV6-MIB array
foreach ($oid_data as $ifIndex => $entry1)
{
foreach ($entry1 as $ip_snmp => $entry)
{
$ip_address = snmp2ipv6($ip_snmp);
/*
$ip_data[$ip_version][$ifIndex][$ip_address] = array('ifIndex' => $ifIndex,
'ip' => $ip_address,
'prefix' => $entry['ipv6AddrPfxLength'],
'origin' => $entry['ipv6AddrType']);
*/
$data = [
'ifIndex' => $ifIndex,
'ip' => $ip_address,
'prefix' => $entry['ipv6AddrPfxLength'],
'origin' => $entry['ipv6AddrType']
];
discover_add_ip_address($device, $mib, $data);
}
}
}
unset($ifIndex, $ip_address, $ip_snmp, $entry1, $oid_data);
// EOF

View File

@ -0,0 +1,60 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
if (!safe_count($ip_data['ipv4']) && !safe_count($ip_data['ipv6'])) {
// arubaos-cx not have any other place for fetch IP addresses
$oid_data = snmpwalk_cache_twopart_oid($device, 'lldpLocManAddrTable', [], 'LLDP-MIB', NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
print_debug_vars($oid_data);
// lldpLocManAddrLen.1.4.10.30.3.12 = 4
// lldpLocManAddrIfSubtype.1.4.10.30.3.12 = ifIndex
// lldpLocManAddrIfId.1.4.10.30.3.12 = 326
// lldpLocManAddrOID.1.4.10.30.3.12 = ifName.326
foreach ($oid_data as $ipv => $entry1) {
if ((int)$ipv === 1) {
$ip_version = 'ipv4';
} elseif ((int)$ipv === 2) {
$ip_version = 'ipv6';
} else {
// other types unknown
continue;
}
foreach ($entry1 as $ip_snmp => $entry) {
list($len, $ip_snmp) = explode('.', $ip_snmp, 2);
$ip_address = $ip_version === 'ipv6' ? snmp2ipv6($ip_snmp) : $ip_snmp;
if ($entry['lldpLocManAddrIfSubtype'] === 'ifIndex') {
$ifIndex = $entry['lldpLocManAddrIfId'];
} elseif ($port_id = get_port_id_by_ifDescr($device['device_id'], $entry['lldpLocManAddrIfId'])) {
$port = get_port_by_id_cache($port_id);
$ifIndex = $port['ifIndex'];
} else {
continue;
}
$data = [
'ifIndex' => $ifIndex,
'ip' => $ip_address
];
discover_add_ip_address($device, $mib, $data);
}
}
unset($ifIndex, $ip_address, $ip_snmp, $entry1, $oid_data);
}
// EOF

View File

@ -0,0 +1,54 @@
<?php
/*
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
// NETAPP-MIB::nodeUuid.'WSLNetapp02-01' = STRING: d924dfcf-418e-11eb-91eb-d039ea255860
// NETAPP-MIB::nodeUuid.'WSLNetapp02-02' = STRING: 83eef39c-418e-11eb-b2bc-d039ea2575e5
$nodes = [];
foreach (snmpwalk_cache_oid($device, 'nodeUuid', [], $mib) as $node => $entry) {
$nodes[$entry['nodeUuid']] = $node;
}
print_vars($nodes);
//$flags = OBS_SNMP_ALL;
$oid_data = [];
foreach ([ 'logicalInterfaceNumericId', 'logicalInterfaceCurrNode', 'logicalInterfaceCurrPort',
'logicalInterfaceAddress', 'logicalInterfaceNetmaskLength', 'logicalInterfaceRole' ] as $oid) {
$oid_data = snmpwalk_cache_oid($device, $oid, $oid_data, $mib);
if ($oid === 'logicalInterfaceNumericId' && !snmp_status()) {
break; // Stop walk, not exist table
}
}
foreach ($oid_data as $index => $entry) {
if (isset($nodes[$entry['logicalInterfaceCurrNode']])) {
$ifDescr = $nodes[$entry['logicalInterfaceCurrNode']] . ':' . $entry['logicalInterfaceCurrPort'];
if ($port_id = get_port_id_by_ifDescr($device, $ifDescr)) {
$port = get_port_by_id_cache($port_id);
$ifIndex = $port['ifIndex'];
} else {
print_debug("Port $ifDescr not found.");
$ifIndex = $entry['logicalInterfaceNumericId'];
//continue;
}
}
$data = [
'ifIndex' => $ifIndex,
'ip' => $entry['logicalInterfaceAddress'],
//'mask' => $entry['logicalInterfaceNetmask'],
'prefix' => $entry['logicalInterfaceNetmaskLength'],
'origin' => $entry['logicalInterfaceRole'],
];
discover_add_ip_address($device, $mib, $data);
}
// EOF

View File

@ -0,0 +1,65 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
// IF-MIB::ifDescr.1 = STRING: LAN
// IF-MIB::ifDescr.2 = STRING: WAN 1-SACOFA
// IF-MIB::ifDescr.3 = STRING: WAN 2-TM
// IF-MIB::ifDescr.4 = STRING: WAN 3
// PEPLINK-WAN::wanName.0 = STRING: "WAN 1-SACOFA"
// PEPLINK-WAN::wanName.1 = STRING: "WAN 2-TM"
// PEPLINK-WAN::wanName.2 = STRING: "WAN 3"
// PEPLINK-WAN::wanName.3 = STRING: "Mobile Internet"
// PEPLINK-WAN::wanNetworkIpType.0.0 = INTEGER: static(1)
// PEPLINK-WAN::wanNetworkIpType.1.0 = INTEGER: static(1)
// PEPLINK-WAN::wanNetworkIpType.2.0 = INTEGER: dhcp(0)
// PEPLINK-WAN::wanNetworkIpType.3.0 = INTEGER: pppoe(2)
// PEPLINK-WAN::wanNetworkIpAddress.0.0 = IpAddress: 103.60.24.211
// PEPLINK-WAN::wanNetworkIpAddress.1.0 = IpAddress: 219.93.31.99
// PEPLINK-WAN::wanNetworkIpAddress.2.0 = IpAddress: 0.0.0.0
// PEPLINK-WAN::wanNetworkIpAddress.3.0 = IpAddress: 0.0.0.0
// PEPLINK-WAN::wanNetworkSubnetMask.0.0 = IpAddress: 255.255.255.240
// PEPLINK-WAN::wanNetworkSubnetMask.1.0 = IpAddress: 255.255.255.224
// PEPLINK-WAN::wanNetworkSubnetMask.2.0 = IpAddress: 0.0.0.0
// PEPLINK-WAN::wanNetworkSubnetMask.3.0 = IpAddress: 0.0.0.0
$ip_version = 'ipv4';
if (!safe_count($ip_data[$ip_version])) {
$oids = snmpwalk_cache_twopart_oid($device, 'wanNetworkIpTable', [], 'PEPLINK-WAN');
if (snmp_status()) {
$oids_int = snmpwalk_cache_oid($device, 'wanName', [], 'PEPLINK-WAN');
foreach ($oids as $wanid => $wan) {
$ifIndex = 0;
if (isset($oids_int[$wanid]) &&
$port_id = get_port_id_by_ifDescr($device['device_id'], $oids_int[$wanid]['wanName'])) {
$port = get_port_by_id_cache($port_id);
$ifIndex = $port['ifIndex'];
}
foreach ($wan as $entry) {
$data = [
'ifIndex' => $ifIndex,
'ip' => $entry['wanNetworkIpAddress'],
'mask' => $entry['wanNetworkSubnetMask'],
//'type' => $entry[''],
'origin' => $entry['wanNetworkIpType']
];
discover_add_ip_address($device, $mib, $data);
}
}
}
}
// EOF

View File

@ -0,0 +1,74 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
// IF-MIB::ifDescr.15 = STRING: LA/1
// IF-MIB::ifDescr.16 = STRING: LA/2
// SDX-ROOT-MIB::systemSvmIPAddressType.0 = INTEGER: ipv4(1)
// SDX-ROOT-MIB::systemSvmIPAddress.0 = STRING: "10.48.4.184"
// SDX-ROOT-MIB::systemXenIPAddressType.0 = INTEGER: ipv4(1)
// SDX-ROOT-MIB::systemXenIPAddress.0 = STRING: "10.48.4.186"
// SDX-ROOT-MIB::systemNetmaskType.0 = INTEGER: ipv4(1)
// SDX-ROOT-MIB::systemNetmask.0 = STRING: "255.255.255.0"
// SDX-ROOT-MIB::systemGatewayType.0 = INTEGER: ipv4(1)
// SDX-ROOT-MIB::systemGateway.0 = STRING: "10.48.4.1"
// SDX-ROOT-MIB::systemNetworkInterface.0 = STRING: "LA Management"
if ($data = snmp_get_multi_oid($device, 'systemSvmIPAddress.0 systemXenIPAddress.0 systemNetmask.0 systemNetworkInterface.0', [], 'SDX-ROOT-MIB')) {
$entry = $data[0];
$ifIndex = 0;
if ($port_id = get_port_id_by_ifDescr($device['device_id'], $entry['systemNetworkInterface'])) {
$port = get_port_by_id_cache($port_id);
$ifIndex = $port['ifIndex'];
} else {
list($if) = explode(' ', $entry['systemNetworkInterface']);
if ($port_id = get_port_id_by_ifDescr($device['device_id'], "$if/1")) {
$port = get_port_by_id_cache($port_id);
$ifIndex = $port['ifIndex'];
}
$data = [
'ifIndex' => $ifIndex,
'ip' => $entry['systemXenIPAddress'],
'mask' => $entry['systemNetmask'],
];
discover_add_ip_address($device, $mib, $data);
if ($port_id = get_port_id_by_ifDescr($device['device_id'], "$if/2")) {
$port = get_port_by_id_cache($port_id);
$ifIndex = $port['ifIndex'];
}
$data = [
'ifIndex' => $ifIndex,
'ip' => $entry['systemSvmIPAddress'],
'mask' => $entry['systemNetmask'],
];
discover_add_ip_address($device, $mib, $data);
return;
}
$data = [
'ifIndex' => $ifIndex,
'ip' => $entry['systemXenIPAddress'],
'mask' => $entry['systemNetmask'],
];
discover_add_ip_address($device, $mib, $data);
$data = [
'ifIndex' => $ifIndex,
'ip' => $entry['systemSvmIPAddress'],
'mask' => $entry['systemNetmask'],
];
discover_add_ip_address($device, $mib, $data);
}
// EOF

View File

@ -0,0 +1,64 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
# We're discovering this MIB
# snmpwalk -v2c -c <community> <hostname> -M mibs/junose/ -m Juniper-UNI-ATM-MIB juniAtmVpStatsEntry
// JunOSe ATM vps
if ($device['os'] == "junose" && ($attribs['enable_ports_junoseatmvp'] || ($config['enable_ports_junoseatmvp'] && !isset($attribs['enable_ports_junoseatmvp']))))
{
echo("JunOSe ATM vps : ");
$vp_array = snmpwalk_cache_oid($device, "juniAtmVpStatsInCells", $vp_array, "Juniper-UNI-ATM-MIB");
$valid_vp = array();
if (OBS_DEBUG && count($vp_array)) { print_vars($vp_array); }
if (is_array($vp_array))
{
foreach ($vp_array as $index => $entry)
{
list($ifIndex,$vp_id)= explode('.', $index);
$port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex));
if (is_numeric($port_id) && is_numeric($vp_id))
{
discover_juniAtmvp($valid_vp, $port_id, $vp_id, NULL);
}
} // End Foreach
} // End if array
unset ($vp_array);
// Remove ATM vps which weren't redetected here
// Fix Me - preferred method is to track existance by removing from an array.
if (OBS_DEBUG && count($valid_vp)) { print_vars ($valid_vp); }
foreach (dbFetchRows("SELECT * FROM `ports` AS P, `juniAtmVp` AS J WHERE P.`device_id` = ? AND J.port_id = P.port_id", array($device['device_id'])) as $test)
{
$port_id = $test['port_id'];
$vp_id = $test['vp_id'];
if (OBS_DEBUG > 1) { echo($port_id . " -> " . $vp_id . "\n"); }
if (!$valid_vp[$port_id][$vp_id])
{
echo("-");
dbDelete('juniAtmvp', '`juniAtmVp` = ?', array($test['juniAtmvp']));
}
unset($port_id); unset($vp_id);
}
unset($valid_vp);
echo(PHP_EOL);
}
// EOF

View File

@ -0,0 +1,46 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
// Include all discovery modules
$include_dir = "includes/discovery/lsp";
include("includes/include-dir-mib.inc.php");
if (OBS_DEBUG && count($valid['lsp']))
{
print_vars($valid['lsp']);
}
// Remove lsps which weren't redetected here
$query = 'SELECT * FROM `lsp` WHERE `device_id` = ?';
foreach (dbFetchRows($query, array($device['device_id'])) as $test_lsp)
{
$lsp_index = $test_lsp['lsp_index'];
$lsp_mib = $test_lsp['lsp_mib'];
$lsp_name = $test_lsp['lsp_name'];
print_debug($lsp_index . " -> " . $lsp_mib);
if (!$valid['lsp'][$lsp_mib][$lsp_index])
{
$GLOBALS['module_stats']['lsp']['deleted']++;
dbDelete('lsp', 'lsp_id = ?', array($test_lsp['lsp_id']));
log_event("LSP removed: index $lsp_index, mib $lsp_mib, name $lsp_name", $device, 'lsp', $test_lsp['lsp_id']);
}
}
$GLOBALS['module_stats'][$module]['status'] = safe_count($valid[$module]);
if (OBS_DEBUG && $GLOBALS['module_stats'][$module]['status'])
{
print_vars($valid[$module]);
}
// EOF

View File

@ -0,0 +1,46 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mib = 'MPLS-MIB';
$lsps = snmpwalk_cache_oid($device, "mplsLspInfoEntry", NULL, $mib, mib_dirs('juniper'));
if (OBS_DEBUG && count($lsps))
{
print_vars($lsps);
}
if (count($lsps))
{
foreach ($lsps as $index => $lsp)
{
$proto = "RSVP-TE";
$name = trim($lsp['mplsLspInfoName'], "."); // name has trailing \0's that are converted to dots by snmp
$state = $lsp['mplsLspInfoState'];
$uptime = timeticks_to_sec($lsp['mplsLspInfoTimeUp']);
$total_uptime = timeticks_to_sec($lsp['mplsLspInfoAge']);
$primary_uptime = timeticks_to_sec($lsp['mplsLspInfoPrimaryTimeUp']);
$bandwidth = $lsp['mplsPathInfoBandwidth'] * 1000; // Convert kbps to bps for standardization
$transitions = $lsp['mplsLspInfoTransitions'];
$path_changes = $lsp['mplsLspInfoPathChanges'];
// using the 'Aggr' instances to avoid gaps on frenquently resignalled LSPs
$octets = $lsp['mplsLspInfoAggrOctets'];
$packets = $lsp['mplsLspInfoAggrPackets'];
discover_lsp($valid['lsp'], $device, $index, $mib, $name, $state, $uptime, $total_uptime,
$primary_uptime, $proto, $transitions, $path_changes, $bandwidth, $octets, $packets, time());
}
}
unset($lsps);
// EOF

View File

@ -0,0 +1,61 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mac_list = array();
// Disabled because we can do this better in poller now without performance hit
// CLEANME FIXME do we do it in poller? Can this code go?
if ($device['os_group'] == "cisco")
{
echo("Cisco MAC Accounting : ");
$datas = snmp_walk($device, "cipMacSwitchedBytes", "-OUqsX", "CISCO-IP-STAT-MIB");
foreach (explode("\n", $datas) as $data)
{
list(,$ifIndex,$dir,$mac,) = parse_oid2($data);
list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $mac);
$ah_a = zeropad($a_a);
$ah_b = zeropad($a_b);
$ah_c = zeropad($a_c);
$ah_d = zeropad($a_d);
$ah_e = zeropad($a_e);
$ah_f = zeropad($a_f);
$clean_mac = "$ah_a$ah_b$ah_c$ah_d$ah_e$ah_f";
$mac_list[$ifIndex.'_'.$clean_mac] = array('ifIndex' => $ifIndex, 'mac' => $clean_mac);
}
foreach ($mac_list as $mac_entry)
{
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? LIMIT 1", array($device['device_id'], $mac_entry['ifIndex']));
if ($port)
{
echo($port['ifDescr'] . ' ('.$mac_entry['ifIndex'].') -> '.$mac_entry['mac']);
if (dbFetchCell("SELECT COUNT(*) from `mac_accounting` WHERE `port_id` = ? AND `mac` = ?", array($port['port_id'], $mac_entry['mac'])))
{
echo(".");
} else {
$ma_id = dbInsert(array('port_id' => $port['port_id'], 'device_id' => $device['device_id'], 'mac' => $mac_entry['mac'] ), 'mac_accounting');
echo("+");
}
} else {
echo("Couldn't work out interface!");
}
echo("\n");
}
echo("\n");
} # os_group=cisco
// FIXME - NEEDS TO REMOVE STALE ENTRIES?? :O
// EOF

View File

@ -0,0 +1,230 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
// Include all discovery modules
$include_dir = "includes/discovery/mempools";
include("includes/include-dir-mib.inc.php");
// Detect mempools by simple MIB-based discovery :
// FIXME - this should also be extended to understand multiple entries in a table, and take descr from an OID but this is all I need right now :)
// FIXME. In one day I'll rewrite this ;)
foreach (get_device_mibs_permitted($device) as $mib) {
if (is_array($config['mibs'][$mib]['mempool'])) {
print_cli_data_field($mib);
foreach ($config['mibs'][$mib]['mempool'] as $entry_name => $entry)
{
if (discovery_check_if_type_exist($entry, 'mempool')) { continue; }
// Check array requirements list
if (discovery_check_requires_pre($device, $entry, 'mempool')) { continue; }
$entry['found'] = FALSE;
// Init Precision (scale)
if (isset($entry['scale']) && is_numeric($entry['scale']) && $entry['scale']) {
$scale = $entry['scale'];
} else {
$scale = 1;
}
// Convert strings '3.40 TB' to value
// See QNAP NAS-MIB or HIK-DEVICE-MIB
$unit = isset($entry['unit']) ? $entry['unit'] : NULL;
if ($entry['type'] === 'table' || !isset($entry['type'])) {
/////////////////////
// Table Discovery //
/////////////////////
// If the type is table, walk the table!
if (!isset($entry['table'])) {
$entry['table'] = $entry_name;
}
// FIXME - cache this outside the mempools array and then just array_merge it in. Descr OIDs are probably shared a lot
// Fetch table or Oids
$table_oids = array('oid_used', 'oid_total', 'oid_free', 'oid_perc', 'oid_descr', 'extra_oids');
$mempools_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%
$mempools_count = safe_count($mempools_array);
foreach ($mempools_array as $index => $mempool_entry) {
$oid_num = $entry['oid_num'] . '.' . $index;
// Generate mempool description
$mempool_entry['i'] = $i;
$mempool_entry['index'] = $index;
foreach (explode('.', $index) as $k => $i) {
$mempool_entry['index'.$k] = $i; // Index parts
}
$descr = entity_descr_definition('mempool', $entry, $mempool_entry, $mempools_count);
// Check array requirements list
if (discovery_check_requires($device, $entry, $mempool_entry, 'mempool')) { continue; }
// Init perc/total/used/free
$used = NULL;
$total = NULL;
$free = NULL;
$perc = NULL;
$options = [];
// Hardcoded total
if (!safe_empty($entry['total'])) { $total = $entry['total']; }
// Fetch used, total, free and percentage values, if OIDs are defined for them
foreach(array('oid_used', 'oid_total', 'oid_free') as $oid) {
if (!isset($entry[$oid])) { continue; }
$param = str_replace('oid_', '', $oid);
if (str_contains($entry[$oid], '.')) {
$mempool_entry[$entry[$oid]] = snmp_cache_oid($device, $entry[$oid], $mib);
}
$$param = snmp_fix_numeric($mempool_entry[$entry[$oid]], $unit);
}
//if ($entry['oid_used'] != '') { $used = snmp_fix_numeric($mempool_entry[$entry['oid_used']], $unit); }
//if ($entry['oid_free'] != '') { $free = snmp_fix_numeric($mempool_entry[$entry['oid_free']], $unit); }
if (!safe_empty($entry['oid_perc'])) { $perc = snmp_fix_numeric($mempool_entry[$entry['oid_perc']]); }
// Prefer hardcoded total over SNMP OIDs
//if ($entry['total'] != '') { $total = $entry['total']; }
//elseif ($entry['oid_total'] != '') { $total = snmp_fix_numeric($mempool_entry[$entry['oid_total']], $unit); }
// Extrapolate all values from the ones we have.
$mempool = calculate_mempool_properties($scale, $used, $total, $free, $perc, $options);
print_debug_vars(array($scale, $used, $total, $free, $perc, $options));
print_debug_vars($mempool_entry);
print_debug_vars($mempool);
print_debug_vars(array(is_numeric($mempool['used']),is_numeric($mempool['total'])));
// If we have valid used and total, discover the mempool
if (is_numeric($mempool['used']) && is_numeric($mempool['total'])) {
//print_r(array($valid['mempool'], $device, $index, $mib, $descr, $scale, $mempool['total'], $mempool['used'], $index, array('table' => $entry_name)));
$mempool_hc = 0; // // FIXME mempool_hc = ?? currently keep as 0
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, $scale, $mempool['total'], $mempool['used'], $mempool_hc, array('table' => $entry_name));
$entry['found'] = TRUE;
}
$i++;
}
} else {
////////////////////
// Static mempool //
////////////////////
// Init perc/total/used/free
$used = NULL;
$total = NULL;
$free = NULL;
$perc = NULL;
$index = 0; // FIXME. Need use same indexes style as in sensors
$mempool_entry = array('index' => $index);
if (isset($entry['oid_descr']) && $entry['oid_descr']) {
// Get description from specified OID
$mempool_entry[$entry['oid_descr']] = snmp_get_oid($device, $entry['oid_descr'], $mib);
}
$descr = entity_descr_definition('mempool', $entry, $mempool_entry);
// Hardcoded total
if (!safe_empty($entry['total'])) { $total = $entry['total']; }
// Fetch used, total, free and percentage values, if OIDs are defined for them
foreach(array('oid_used', 'oid_total', 'oid_free') as $oid) {
if (!isset($entry[$oid])) { continue; }
$param = str_replace('oid_', '', $oid);
$$param = snmp_fix_numeric(snmp_get_oid($device, $entry[$oid], $mib), $unit);
}
// Fetch used, total, free and percentage values, if OIDs are defined for them
// if ($entry['oid_used'] != '') {
// $used = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_used'], $mib), $unit);
// }
// Prefer hardcoded total over SNMP OIDs
// if ($entry['total'] != '') {
// $total = $entry['total'];
// } else {
// // No hardcoded total, fetch OID if defined
// if ($entry['oid_total'] != '') {
// $total = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_total'], $mib), $unit);
// }
// }
// if ($entry['oid_free'] != '') {
// $free = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_free'], $mib), $unit);
// }
if (!safe_empty($entry['oid_perc'])) {
$perc = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_perc'], $mib));
}
$mempool = calculate_mempool_properties($scale, $used, $total, $free, $perc, $entry);
// If we have valid used and total, discover the mempool
if (is_numeric($mempool['used']) && is_numeric($mempool['total'])) {
// Rename RRD if requested
if (isset($entry['rename_rrd'])) {
$old_rrd = 'mempool-' . $entry['rename_rrd'];
$new_rrd = 'mempool-' . strtolower($mib) . '-' . $index;
rename_rrd($device, $old_rrd, $new_rrd);
unset($old_rrd, $new_rrd);
}
$mempool_hc = 0; // // FIXME mempool_hc = ?? currently keep as 0
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, $scale, $mempool['total'], $mempool['used'], $mempool_hc, array('table' => $entry_name));
$entry['found'] = TRUE;
}
}
unset($mempools_array, $mempool, $dot_index, $descr, $i); // Clean up
if (isset($entry['stop_if_found']) && $entry['stop_if_found'] && $entry['found']) {
break;
} // Stop loop if mempool found
}
print_cli(PHP_EOL);
}
}
// Remove memory pools which weren't redetected here
foreach (dbFetchRows('SELECT * FROM `mempools` WHERE `device_id` = ?', array($device['device_id'])) as $test_mempool)
{
$mempool_index = $test_mempool['mempool_index'];
$mempool_mib = $test_mempool['mempool_mib'];
$mempool_descr = $test_mempool['mempool_descr'];
print_debug($mempool_index . " -> " . $mempool_mib);
if (!$valid['mempool'][$mempool_mib][$mempool_index])
{
$GLOBALS['module_stats'][$module]['deleted']++; //echo('-');
dbDelete('mempools', '`mempool_id` = ?', array($test_mempool['mempool_id']));
log_event("Memory pool removed: mib $mempool_mib, index $mempool_index, descr $mempool_descr", $device, 'mempool', $test_mempool['mempool_id']);
}
}
$GLOBALS['module_stats'][$module]['status'] = safe_count($valid['mempool']);
if (OBS_DEBUG && $GLOBALS['module_stats'][$module]['status'])
{
print_vars($valid['mempool']);
}
// EOF

View File

@ -0,0 +1,41 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// DGS-3450
// AGENT-GENERAL-MIB::agentDRAMutilizationUnitID.0 = INTEGER: 0
// AGENT-GENERAL-MIB::agentDRAMutilizationTotalDRAM.0 = INTEGER: 262144 KB
// AGENT-GENERAL-MIB::agentDRAMutilizationUsedDRAM.0 = INTEGER: 174899 KB
// AGENT-GENERAL-MIB::agentDRAMutilization.0 = INTEGER: 66
// DES-3550, DES-3526, DES-3028 (and other Stacking switches)
// AGENT-GENERAL-MIB::agentDRAMutilizationUnitID.1 = INTEGER: 1
// AGENT-GENERAL-MIB::agentDRAMutilizationTotalDRAM.1 = INTEGER: 22495072 KB
// AGENT-GENERAL-MIB::agentDRAMutilizationUsedDRAM.1 = INTEGER: 12431462 KB
// AGENT-GENERAL-MIB::agentDRAMutilization.1 = INTEGER: 55
$mempool_array = snmpwalk_cache_oid($device, 'agentDRAMutilizationEntry', [], $mib);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['agentDRAMutilizationUsedDRAM'])) {
$descr = ($index === 0 ? 'Memory' : 'Unit ' . $index);
$used = $entry['agentDRAMutilizationUsedDRAM'];
$total = $entry['agentDRAMutilizationTotalDRAM'];
$precision = (strlen($total) > 7 ? 1 : 1024); // Stacking switches uses wrong units
//$used *= $precision;
//$total *= $precision;
discover_mempool($valid['mempool'], $device, $index, 'AGENT-GENERAL-MIB', $descr, $precision, $total, $used);
}
}
unset($mempool_array, $index, $descr, $precision, $total, $used);
// EOF

View File

@ -0,0 +1,56 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
/*
BIANCA-BRICK-MIBRES-MIB::memoryType.flash.0 = INTEGER: flash(1)
BIANCA-BRICK-MIBRES-MIB::memoryType.dram.1 = INTEGER: dram(2)
BIANCA-BRICK-MIBRES-MIB::memoryType.dpool.2 = INTEGER: dpool(3)
BIANCA-BRICK-MIBRES-MIB::memoryDescr.flash.0 = Hex-STRING: 4F 6E 62 6F 61 72 64 20 46 6C 61 73 68 00
BIANCA-BRICK-MIBRES-MIB::memoryDescr.dram.1 = Hex-STRING: 4D 61 69 6E 20 4D 65 6D 6F 72 79 00
BIANCA-BRICK-MIBRES-MIB::memoryDescr.dpool.2 = STRING: "STREAMS Class 0"
BIANCA-BRICK-MIBRES-MIB::memoryBlockSize.flash.0 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryBlockSize.dram.1 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryBlockSize.dpool.2 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryTotal.flash.0 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 4194304
BIANCA-BRICK-MIBRES-MIB::memoryTotal.dram.1 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 16711680
BIANCA-BRICK-MIBRES-MIB::memoryTotal.dpool.2 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 96
BIANCA-BRICK-MIBRES-MIB::memoryInuse.flash.0 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryInuse.dram.1 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 13639380
BIANCA-BRICK-MIBRES-MIB::memoryInuse.dpool.2 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryDramUse.flash.0 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryDramUse.dram.1 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryDramUse.dpool.2 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 6528
BIANCA-BRICK-MIBRES-MIB::memoryNAllocs.flash.0 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryNAllocs.dram.1 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 3006
BIANCA-BRICK-MIBRES-MIB::memoryNAllocs.dpool.2 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 53354
BIANCA-BRICK-MIBRES-MIB::memoryNFrees.flash.0 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryNFrees.dram.1 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 89
BIANCA-BRICK-MIBRES-MIB::memoryNFrees.dpool.2 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 53434
BIANCA-BRICK-MIBRES-MIB::memoryNFails.flash.0 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryNFails.dram.1 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
BIANCA-BRICK-MIBRES-MIB::memoryNFails.dpool.2 = Wrong Type (should be Gauge32 or Unsigned32): INTEGER: 0
*/
$mempool_array = snmpwalk_cache_oid($device, 'memoryTable', array(), 'BIANCA-BRICK-MIBRES-MIB', NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
foreach ($mempool_array as $index => $entry)
{
if ($entry['memoryType'] == 'dpool') { continue; }
$entry['memoryDescr'] = snmp_hexstring($entry['memoryDescr']);
discover_mempool($valid['mempool'], $device, $index, 'BIANCA-BRICK-MIBRES-MIB', $entry['memoryDescr'], 1, $entry['memoryTotal'], $entry['memoryInuse']);
}
unset ($mempool_array);
// EOF

View File

@ -0,0 +1,25 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$mempool_array = snmpwalk_cache_oid($device, 'sgProxyMem', array(), $mib);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($index) && is_numeric($entry['sgProxyMemAvailable'])) {
$total = $entry['sgProxyMemAvailable'];
$used = $entry['sgProxyMemSysUsage'];
discover_mempool($valid['mempool'], $device, $index, 'BLUECOAT-SG-PROXY-MIB', "Memory $index", 1, $total, $used);
}
}
unset($mempool_array, $index, $total, $used);
// EOF

View File

@ -0,0 +1,29 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// ProxyAV devices hide their CPUs/Memory/Interfaces in here
$av_array = snmpwalk_cache_oid($device, 'deviceUsage', [], $mib);
foreach ($av_array as $index => $entry) {
if (str_contains($entry['deviceUsageName'], 'Memory')) {
$descr = $entry['deviceUsageName'];
$oid = ".1.3.6.1.4.1.3417.2.4.1.1.1.4.$index";
$perc = $entry['deviceUsagePercent'];
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, 1, 100, $perc);
}
}
unset($av_array);
// EOF

View File

@ -0,0 +1,44 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$mempool_array = snmpwalk_cache_oid($device, 'cempMemPoolEntry', [], $mib);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['cempMemPoolUsed']) && $entry['cempMemPoolValid'] === 'true') {
if (is_numeric($entry['cempMemPoolHCUsed'])) {
// Use HC counters
$hc = 1;
print_debug('HC');
$used = $entry['cempMemPoolHCUsed'];
$free = $entry['cempMemPoolHCFree'];
} else {
// Use 32bit counters
$hc = 0;
$used = $entry['cempMemPoolUsed'];
$free = $entry['cempMemPoolFree'];
}
$total = $used + $free;
list($entPhysicalIndex) = explode('.', $index);
$entPhysicalName = trim(snmp_get_oid($device, "entPhysicalName.$entPhysicalIndex", 'ENTITY-MIB'));
$descr = $entPhysicalName.' ('.$entry['cempMemPoolName'].')';
$descr = str_replace([ 'Cisco ', 'Network Processing Engine', 'CPU of' ], '', $descr);
$descr = preg_replace('/Sub-Module (\d+) CFC Card/', "Module \\1 CFC", $descr);
discover_mempool($valid['mempool'], $device, $index, 'CISCO-ENHANCED-MEMPOOL-MIB', $descr, 1, $total, $used, $hc);
}
}
unset($mempool_array, $index, $descr, $total, $used, $free, $entPhysicalIndex, $entPhysicalName);
// EOF

View File

@ -0,0 +1,30 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$mempool_array = snmpwalk_cache_oid($device, 'ceqfpMemoryResourceEntry', [], $mib);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['ceqfpMemoryResInUse'])) {
list($entPhysicalIndex, $entMemoryResource) = explode('.', $index);
$entPhysicalName = snmp_get($device, "entPhysicalName.$entPhysicalIndex", '-Oqv', 'ENTITY-MIB');
$descr = $entPhysicalName.' - '.$entMemoryResource;
$used = $entry['ceqfpMemoryResInUse'];
$total = $entry['ceqfpMemoryResTotal'];
discover_mempool($valid['mempool'], $device, $index, 'CISCO-ENTITY-QFP-MIB', $descr, 1, $total, $used);
}
}
unset($mempool_array, $index, $descr, $total, $used, $free, $entPhysicalIndex, $entPhysicalName, $entMemoryResource);
// EOF

View File

@ -0,0 +1,30 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// Ignore this discovery module if we have already discovered things in CISCO-ENHANCED-MEMPOOL-MIB. Dirty duplication.
if (!isset($valid['mempool']['cisco-enhanced-mempool-mib']) && !isset($valid['mempool']['CISCO-ENHANCED-MEMPOOL-MIB'])) {
$mempool_array = snmpwalk_cache_oid($device, 'ciscoMemoryPool', [], $mib);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['ciscoMemoryPoolUsed']) && is_numeric($index) && $entry['ciscoMemoryPoolValid'] !== 'false') {
$descr = $entry['ciscoMemoryPoolName'];
$used = $entry['ciscoMemoryPoolUsed'];
$free = $entry['ciscoMemoryPoolFree'];
$total = $used + $free;
discover_mempool($valid['mempool'], $device, $index, 'CISCO-MEMORY-POOL-MIB', $descr, 1, $total, $used);
}
}
unset($mempool_array, $index, $descr, $total, $used, $free);
}
// EOF

View File

@ -0,0 +1,42 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// Ignore this discovery module if we have already discovered things in CISCO-ENHANCED-MEMPOOL-MIB. Dirty duplication.
if (!isset($valid['mempool']['cisco-enhanced-mempool-mib']) && !isset($valid['mempool']['CISCO-ENHANCED-MEMPOOL-MIB']) &&
!isset($valid['mempool']['cisco-memory-pool-mib']) && !isset($valid['mempool']['CISCO-MEMORY-POOL-MIB']))
{
$mempool_array = snmpwalk_cache_oid($device, 'cpmCPUMemoryUsed', array(), $mib);
$mempool_array = snmpwalk_cache_oid($device, 'cpmCPUMemoryFree', $mempool_array, $mib);
$mempool_array = snmpwalk_cache_oid($device, 'cpmCPUTotalPhysicalIndex', $mempool_array, $mib);
foreach ($mempool_array as $index => $entry)
{
if (is_numeric($entry['cpmCPUMemoryUsed']) && is_numeric($entry['cpmCPUMemoryFree']))
{
if ($entry['cpmCPUTotalPhysicalIndex'])
{
$descr = snmp_get($device, 'entPhysicalName.' . $entry['cpmCPUTotalPhysicalIndex'], '-Oqv', 'ENTITY-MIB');
} else {
$descr = "Memory Pool $index";
}
$used = $entry['cpmCPUMemoryUsed'];
$free = $entry['cpmCPUMemoryFree'];
$total = $used + $free;
discover_mempool($valid['mempool'], $device, $index, 'CISCO-PROCESS-MIB', $descr, 1024, $total, $used);
}
}
}
// EOF

View File

@ -0,0 +1,50 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// DELL-NETWORKING-CHASSIS-MIB::dellNetCpuUtilMemUsage.stack.1.1 = Gauge32: 41 percent
// DELL-NETWORKING-CHASSIS-MIB::dellNetProcessorMemSize.stack.1.1 = INTEGER: 2029
$mempool_array = snmpwalk_cache_threepart_oid($device, 'dellNetCpuUtilMemUsage', [], $mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
if (!safe_empty($mempool_array)) {
$mempool_array = snmpwalk_cache_threepart_oid($device, 'dellNetProcessorMemSize', $mempool_array, $mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
print_debug_vars($mempool_array);
foreach ($mempool_array as $type => $entry1) {
// Hrm, this is possible for multiple types?
$first_unit = array_key_first($entry1);
foreach ($entry1 as $unit => $entry2) {
$mempool_count = count($entry2);
foreach ($entry2 as $mempool => $entry) {
$index = "{$type}.{$unit}.{$mempool}";
$dot_index = ".{$index}";
$descr = 'Unit ' . ($unit - $first_unit);
if ($mempool_count > 1) {
$descr .= " Memory {$mempool}";
}
$oid_table = 'dellNetCpuUtilTable';
$oid_name = 'dellNetCpuUtilMemUsage';
$precision = 1024 * 1024;
$total = $entry['dellNetProcessorMemSize'];
$percent = $entry['dellNetCpuUtilMemUsage'];
$used = $total * $percent / 100;
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, $precision, $total, $used);
}
}
}
}
unset($mempool_array, $index, $descr, $precision, $total, $used, $percent);
// EOF

View File

@ -0,0 +1,27 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$mempool_array = snmpwalk_cache_oid($device, 'extremeMemoryMonitorSystemTable', [], $mib);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['extremeMemoryMonitorSystemFree']) && is_numeric($index)) {
$descr = "Memory $index";
$free = $entry['extremeMemoryMonitorSystemFree'];
$total = $entry['extremeMemoryMonitorSystemTotal'];
$used = $total - $free;
discover_mempool($valid['mempool'], $device, $index, 'EXTREME-SOFTWARE-MONITOR-MIB', $descr, 1024, $total, $used);
}
}
unset($mempool_array, $index, $descr, $total, $used, $free);
// EOF

View File

@ -0,0 +1,43 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Force10 C-Series
// FIXME. Need snmpwalk for total size: F10-C-SERIES-CHASSIS-MIB::chSysProcessorMemSize
// F10-C-SERIES-CHASSIS-MIB::chRpmMemUsageUtil.1 = 5
$mempool_array = snmpwalk_cache_oid($device, 'chRpmMemUsageUtil', [], $mib);
if (!safe_empty($mempool_array)) {
$total_array = snmpwalk_cache_oid($device, 'chSysProcessorMemSize', [], $mib);
print_debug_vars($total_array);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['chRpmMemUsageUtil'])) {
if (is_numeric($total_array[$index]['chSysProcessorMemSize'])) {
$precision = 1024 * 1024;
$total = $total_array[$index]['chSysProcessorMemSize']; // FTOS display memory in MB
//$total *= $precision;
} else {
$precision = 1;
$total = 1090519040; // Hardcoded total.
}
$percent = $entry['chRpmMemUsageUtil'];
$used = $total * $percent / 100;
$descr = $index == 1 ? 'CP' : 'RP' . ($index - 1);
discover_mempool($valid['mempool'], $device, $index, 'F10-C-SERIES-CHASSIS-MIB', $descr, $precision, $total, $used);
}
}
}
unset($mempool_array, $total_array, $index, $descr, $precision, $total, $used, $percent);
// EOF

View File

@ -0,0 +1,46 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Force10 E-Series
// FIXME. Need snmpwalk for total size: F10-CHASSIS-MIB::chSysProcessorMemSize
// F10-CHASSIS-MIB::chRpmMemUsageUtil.1 = 5
// F10-CHASSIS-MIB::chRpmMemUsageUtil.2 = 36
// F10-CHASSIS-MIB::chRpmMemUsageUtil.3 = 9
$mempool_array = snmpwalk_cache_oid($device, 'chRpmMemUsageUtil', [], $mib);
if (!safe_empty($mempool_array)) {
$total_array = snmpwalk_cache_oid($device, 'chSysProcessorMemSize.1', [], $mib);
print_debug_vars($total_array);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['chRpmMemUsageUtil'])) {
if (is_numeric($total_array['1.'.$index]['chSysProcessorMemSize'])) {
$precision = 1024 * 1024;
$total = $total_array['1.'.$index]['chSysProcessorMemSize']; // FTOS display memory in MB
//$total *= $precision;
} else {
$precision = 1;
$total = 1090519040; // Hardcoded total. See FIXME above.
}
$percent = $entry['chRpmMemUsageUtil'];
$used = $total * $percent / 100;
$descr = $index == 1 ? 'CP' : 'RP' . ($index - 1);
discover_mempool($valid['mempool'], $device, $index, 'F10-CHASSIS-MIB', $descr, $precision, $total, $used);
}
}
}
unset($mempool_array, $total_array, $index, $descr, $precision, $total, $used, $percent);
// EOF

View File

@ -0,0 +1,41 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Force10 M-Series
$mempool_array = snmpwalk_cache_oid($device, 'chStackUnitMemUsageUtil', [], $mib);
if (!safe_empty($mempool_array)) {
$mempool_array = snmpwalk_cache_oid($device, 'chStackUnitSysType', $mempool_array, $mib);
$total_array = snmpwalk_cache_oid($device, 'chSysProcessorMemSize', [], $mib);
print_debug_vars($total_array);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['chStackUnitMemUsageUtil'])) {
if (is_numeric($total_array[$index]['chSysProcessorMemSize'])) {
$precision = 1024 * 1024;
$total = $total_array[$index]['chSysProcessorMemSize']; // FTOS display memory in MB
//$total *= $precision;
} else {
$precision = 1;
$total = 1090519040; // Hardcoded total.
}
$percent = $entry['chStackUnitMemUsageUtil'];
$used = $total * $percent / 100;
$descr = 'Unit ' . ($index - 1) . ' ' . $entry['chStackUnitSysType'];
discover_mempool($valid['mempool'], $device, $index, 'F10-M-SERIES-CHASSIS-MIB', $descr, $precision, $total, $used);
}
}
}
unset($mempool_array, $total_array, $index, $descr, $precision, $total, $used, $percent);
// EOF

View File

@ -0,0 +1,43 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Force10 S-Series
// F10-S-SERIES-CHASSIS-MIB::chStackUnitMemUsageUtil.1 = Gauge32: 86
$mempool_array = snmpwalk_cache_oid($device, 'chStackUnitMemUsageUtil', [], $mib);
if (!safe_empty($mempool_array)) {
$mempool_array = snmpwalk_cache_oid($device, 'chStackUnitSysType', $mempool_array, $mib);
$total_array = snmpwalk_cache_oid($device, 'chSysProcessorMemSize', [], $mib);
print_debug_vars($total_array);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['chStackUnitMemUsageUtil'])) {
if (is_numeric($total_array[$index]['chSysProcessorMemSize'])) {
$precision = 1024 * 1024;
$total = $total_array[$index]['chSysProcessorMemSize']; // FTOS display memory in MB
//$total *= $precision;
} else {
$precision = 1;
$total = 1090519040; // Hardcoded total
}
$percent = $entry['chStackUnitMemUsageUtil'];
$used = $total * $percent / 100;
$descr = 'Unit ' . ($index - 1) . ' ' . $entry['chStackUnitSysType'];
discover_mempool($valid['mempool'], $device, $index, 'F10-S-SERIES-CHASSIS-MIB', $descr, $precision, $total, $used);
}
}
}
unset($mempool_array, $total_array, $index, $descr, $precision, $total, $used, $percent);
// EOF

View File

@ -0,0 +1,29 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$tmm_memory = snmpwalk_cache_oid($device, 'sysTmmStatMemoryUsed', array(), $mib);
$tmm_memory = snmpwalk_cache_oid($device, 'sysTmmStatMemoryTotal', $tmm_memory, $mib);
foreach ($tmm_memory as $index => $entry)
{
$total = $entry['sysTmmStatMemoryTotal'];
if ($total == 0) continue;
$used = $entry['sysTmmStatMemoryUsed'];
$descr = "TMM $index Memory";
discover_mempool($valid['mempool'], $device, $index, 'F5-BIGIP-SYSTEM-MIB', $descr, 1, $total, $used);
}
unset ($mempool_array, $index, $total, $used);
// EOF

View File

@ -0,0 +1,46 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
//snAgGblDynMemUtil OBJECT-TYPE
// STATUS deprecated
// DESCRIPTION
// 'The system dynamic memory utilization, in unit of percentage.
// Deprecated: Refer to snAgSystemDRAMUtil.
// For NI platforms, refer to snAgentBrdMemoryUtil100thPercent'
$percent = snmp_get_oid($device, 'snAgSystemDRAMUtil.0', $mib);
$total = snmp_get_oid($device, 'snAgSystemDRAMTotal.0', $mib);
// This device some time have negative Total
// FOUNDRY-SN-AGENT-MIB::snAgSystemDRAMTotal.0 = -2147483648
if ($total < -1 && is_numeric($total)) { $total = abs($total); }
if (is_numeric($percent) && $total > 0)
{
// Use new OIDs
$hc = 1; // This is fake HC bit.
} else {
// Use old deprecated OIDs
$hc = 0;
$percent = snmp_get_oid($device, 'snAgGblDynMemUtil.0', $mib);
$total = snmp_get_oid($device, 'snAgGblDynMemTotal.0', $mib);
if ($total == -1 && is_numeric($total)) { $total = 100; }
}
if (is_numeric($percent) && is_numeric($total) && $total > 0) {
$used = $total * $percent / 100;
discover_mempool($valid['mempool'], $device, 0, 'FOUNDRY-SN-AGENT-MIB', 'Memory', 1, $total, $used, $hc);
}
unset ($total, $used, $percent, $hc);
// EOF

View File

@ -0,0 +1,43 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// HH3C-ENTITY-EXT-MIB::hh3cEntityExtMemUsage.30 = INTEGER: 58
// HH3C-ENTITY-EXT-MIB::hh3cEntityExtMemUsage.36 = INTEGER: 59
// HH3C-ENTITY-EXT-MIB::hh3cEntityExtMemUsage.42 = INTEGER: 58
// HH3C-ENTITY-EXT-MIB::hh3cEntityExtMemUsage.48 = INTEGER: 58
$oids = [ 'hh3cEntityExtMemUsage', 'hh3cEntityExtMemSize' ];
$mempool_array = [];
foreach ($oids as $oid) {
$mempool_array = snmpwalk_cache_oid($device, $oid, $mempool_array, $mib);
if (!snmp_status()) { break; }
}
if (!safe_empty($mempool_array)) {
$mempool_array = snmpwalk_cache_oid($device, 'entPhysicalName', $mempool_array, 'ENTITY-MIB');
foreach ($mempool_array as $index => $entry) {
$entry['hh3cEntityExtMemSize'] = snmp_dewrap32bit($entry['hh3cEntityExtMemSize']);
if (is_numeric($entry['hh3cEntityExtMemUsage']) && $entry['hh3cEntityExtMemSize'] > 0) {
$descr = $entry['entPhysicalName'];
$percent = $entry['hh3cEntityExtMemUsage'];
$total = $entry['hh3cEntityExtMemSize'];
$used = $total * $percent / 100;
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, 1, $total, $used);
}
}
}
unset($mempool_array, $index, $descr, $total, $used, $chassis_count, $percent);
// EOF

View File

@ -0,0 +1,118 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
$hrStorage = snmp_cache_table($device, "hrStorageEntry", [], "HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES");
//$debug_stats = array('total' => 0, 'used' => 0);
if (!safe_empty($hrStorage)) {
if ($device['os'] === "arista_eos" && $hrStorage[1]['hrStorageDescr'] === 'RAM') {
// Arista EOS derp hack for correct free memory
// https://eos.arista.com/memory-utilization-on-eos-devices/
// hrStorageType.1 = hrStorageRam
// hrStorageType.2 = hrStorageRam
// hrStorageType.3 = hrStorageRam
// hrStorageType.100 = hrStorageRam
// hrStorageDescr.1 = RAM
// hrStorageDescr.2 = RAM (Buffers)
// hrStorageDescr.3 = RAM (Cache)
// hrStorageDescr.100 = RAM (Unavailable)
// hrStorageAllocationUnits.1 = 1024
// hrStorageAllocationUnits.2 = 1024
// hrStorageAllocationUnits.3 = 1024
// hrStorageAllocationUnits.100 = 1024
// hrStorageSize.1 = 8152456
// hrStorageSize.2 = 8152456
// hrStorageSize.3 = 8152456
// hrStorageSize.100 = 8152456
// hrStorageUsed.1 = 7376060
// hrStorageUsed.2 = 288472
// hrStorageUsed.3 = 2984372
// hrStorageUsed.100 = 1811664
$hrStorage[1]['hrStorageUsed'] = snmp_dewrap32bit($hrStorage[1]['hrStorageUsed']);
foreach ($hrStorage as $idx => $entry) {
if ($idx != '1' && $entry['hrStorageType'] === 'hrStorageRam' &&
str_starts($entry['hrStorageDescr'], 'RAM') && !str_contains($entry['hrStorageDescr'], 'Unavailable')) {
// Use only Buffers and Cache
$hrStorage[1]['hrStorageUsed'] -= snmp_dewrap32bit($entry['hrStorageUsed']);
unset($hrStorage[$idx]);
}
}
unset($idx);
}
foreach ($hrStorage as $index => $entry) {
$descr = $entry['hrStorageDescr'];
$units = $entry['hrStorageAllocationUnits'];
$total = snmp_dewrap32bit($entry['hrStorageSize']);
$used = snmp_dewrap32bit($entry['hrStorageUsed']);
$deny = TRUE;
switch($entry['hrStorageType']) {
case 'hrStorageVirtualMemory':
case 'hrStorageRam':
case 'hrStorageOther':
case 'hrStorageTypes.20':
case 'nwhrStorageDOSMemory':
case 'nwhrStorageMemoryAlloc':
case 'nwhrStorageMemoryPermanent':
case 'nwhrStorageCacheBuffers':
case 'nwhrStorageCacheMovable':
case 'nwhrStorageCacheNonMovable':
case 'nwhrStorageCodeAndDataMemory':
case 'nwhrStorageIOEngineMemory':
case 'nwhrStorageMSEngineMemory':
case 'nwhrStorageUnclaimedMemory':
$deny = FALSE;
break;
}
if ($device['os'] === "routeros" && $descr === "main memory") {
$deny = FALSE;
} elseif ($device['os'] === "mcd") {
// Yes, hardcoded logic for mcd, because they do not use standard
// See: http://jira.observium.org/browse/OBSERVIUM-1269
if ($index === 1) {
// hrStorageType.1 = hrStorageRam
// hrStorageDescr.1 = System Free Memory
// hrStorageAllocationUnits.1 = 1
// hrStorageSize.1 = 160481280
// hrStorageUsed.1 = 160481280
$descr = "Memory";
$free = $total;
$total = 536870912; // 512Mb, Really total memory calculates as summary of all memory pools from this mib
$used = $total - $free;
discover_mempool($valid['mempool'], $device, $index, "host-resources-mcd", $descr, $units, $total, $used);
}
$deny = TRUE;
continue;
}
if ($deny ||
str_contains_array($descr, [ "MALLOC", "UMA" ]) || // Ignore FreeBSD INSANITY
str_contains_array($descr, [ "procfs", "/proc" ]) || // Ignore ProcFS
in_array($descr, [ "Cached memory", "Shared memory", "Physical memory" ], TRUE)) { // Ignore worthless data on Unix hosts
continue;
}
if (is_numeric($entry['hrStorageSize']) && $total) {
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, $units, $total, $used);
//$debug_stats['total'] += $total;
//$debug_stats['used'] += $used;
}
}
}
unset($index, $descr, $total, $used, $units, $deny);
// EOF

View File

@ -0,0 +1,43 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// HPN-ICF-ENTITY-EXT-MIB::hpnicfEntityExtMemUsage.30 = INTEGER: 58
// HPN-ICF-ENTITY-EXT-MIB::hpnicfEntityExtMemUsage.36 = INTEGER: 59
// HPN-ICF-ENTITY-EXT-MIB::hpnicfEntityExtMemUsage.42 = INTEGER: 58
// HPN-ICF-ENTITY-EXT-MIB::hpnicfEntityExtMemUsage.48 = INTEGER: 58
$oids = [ 'hpnicfEntityExtMemUsage', 'hpnicfEntityExtMemSize' ];
$mempool_array = [];
foreach ($oids as $oid) {
$mempool_array = snmpwalk_cache_oid($device, $oid, $mempool_array, 'ENTITY-MIB:HPN-ICF-ENTITY-EXT-MIB');
if (!snmp_status()) { break; }
}
if (!safe_empty($mempool_array)) {
$mempool_array = snmpwalk_cache_oid($device, 'entPhysicalName', $mempool_array, 'ENTITY-MIB:HPN-ICF-ENTITY-EXT-MIB');
foreach ($mempool_array as $index => $entry) {
$entry['hpnicfEntityExtMemSize'] = snmp_dewrap32bit($entry['hpnicfEntityExtMemSize']);
if (is_numeric($entry['hpnicfEntityExtMemUsage']) && $entry['hpnicfEntityExtMemSize'] > 0) {
$descr = $entry['entPhysicalName'];
$percent = $entry['hpnicfEntityExtMemUsage'];
$total = $entry['hpnicfEntityExtMemSize'];
$used = $total * $percent / 100;
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, 1, $total, $used);
}
}
}
unset($mempool_array, $index, $descr, $total, $used, $chassis_count, $percent);
// EOF

View File

@ -0,0 +1,47 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// Huawei VRP mempools
$mempool_array = snmpwalk_cache_oid($device, "hwEntityMemUsage", [], $mib);
if (!safe_empty($mempool_array)) {
$mempool_array = snmpwalk_cache_oid($device, "hwEntityMemSize", $mempool_array, $mib);
$mempool_array = snmpwalk_cache_oid($device, "hwEntityMemUsageThreshold", $mempool_array, $mib);
$mempool_array = snmpwalk_cache_oid($device, "entPhysicalName", $mempool_array, 'ENTITY-MIB');
foreach ($mempool_array as $index => $entry) {
if (isset($entry['hwEntityMemSize'])) {
// not all platforms have hwEntityMemSize.. what tf
if ($entry['hwEntityMemSize'] == 0) {
print_debug("Entity is not support Memory usage:");
print_debug_vars($entry);
continue;
}
} elseif (isset($entry['hwEntityMemUsageThreshold']) && $entry['hwEntityMemUsageThreshold'] == 0 && $entry['hwEntityMemUsage'] == 0) {
print_debug("Entity is not support Memory usage:");
print_debug_vars($entry);
continue;
}
$descr = rewrite_entity_name($entry['entPhysicalName']);
$percent = $entry['hwEntityMemUsage'];
if (!safe_empty($descr) && !str_contains($descr, 'No') && !str_contains($percent, 'No')) {
$total = isset($entry['hwEntityMemSize']) && $entry['hwEntityMemSize'] > 0 ? $entry['hwEntityMemSize'] : 100;
$used = $total * $percent / 100;
discover_mempool($valid['mempool'], $device, $index, 'HUAWEI-ENTITY-EXTENT-MIB', $descr, 1, $total, $used);
}
}
}
unset($mempool_array, $index, $descr, $total, $used, $percent);
// EOF

View File

@ -0,0 +1,40 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$mempool_array = snmpwalk_cache_oid($device, 'jnxOperatingBuffer', [], $mib);
if (!safe_empty($mempool_array)) {
$mempool_array = snmpwalk_cache_oid($device, 'jnxOperatingMemory', $mempool_array, $mib);
$mempool_array = snmpwalk_cache_oid($device, 'jnxOperatingDRAMSize', $mempool_array, $mib);
$mempool_array = snmpwalk_cache_oid($device, 'jnxOperatingDescr', $mempool_array, $mib);
foreach ($mempool_array as $index => $entry) {
$descr = $entry['jnxOperatingDescr'];
if (!is_numeric($entry['jnxOperatingBuffer']) || str_icontains_array($descr, [ 'sensor', 'fan', 'pcmcia', 'no' ])) { continue; }
if ($entry['jnxOperatingDRAMSize']) {
$precision = 1;
$total = $entry['jnxOperatingDRAMSize']; // Size in bytes
} elseif ($entry['jnxOperatingMemory']) {
$precision = 1024 * 1024;
$total = $entry['jnxOperatingMemory']; // Size in megabytes
} else {
continue;
}
$percent = $entry['jnxOperatingBuffer'];
$used = $total * $percent / 100;
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, $precision, $total, $used);
}
}
unset($mempool_array, $index, $descr, $precision, $total, $used, $percent);
// EOF

View File

@ -0,0 +1,33 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$srx_spu_array = array();
$srx_spu_array = snmpwalk_cache_oid($device, 'jnxJsSPUMonitoringNodeDescr', $srx_spu_array, $mib);
$srx_spu_array = snmpwalk_cache_oid($device, 'jnxJsSPUMonitoringFPCIndex', $srx_spu_array, $mib);
$srx_spu_array = snmpwalk_cache_oid($device, 'jnxJsSPUMonitoringMemoryUsage', $srx_spu_array, $mib);
$srx_spu_array = snmpwalk_cache_oid($device, 'jnxJsSPUMonitoringNodeDescr', $srx_spu_array, $mib);
foreach ($srx_spu_array as $index => $entry)
{
if (is_numeric($entry['jnxJsSPUMonitoringMemoryUsage']))
{
$descr = ($entry['jnxJsSPUMonitoringNodeDescr'] == 'single' ? '' : $entry['jnxJsSPUMonitoringNodeDescr'] . ' ') . 'SPC slot ' . $entry['jnxJsSPUMonitoringFPCIndex'];
$usage = $entry['jnxJsSPUMonitoringMemoryUsage'];
discover_mempool($valid['mempool'], $device, $index, 'JUNIPER-SRX5000-SPU-MONITORING-MIB', $descr, 1, 100, $usage);
}
}
unset ($srx_spu_array, $index, $descr, $usage);
// EOF

View File

@ -0,0 +1,41 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// NETSWITCH-MIB::hpLocalMemSlotIndex.1 = INTEGER: 1
// NETSWITCH-MIB::hpLocalMemSlabCnt.1 = Counter32: 3966
// NETSWITCH-MIB::hpLocalMemFreeSegCnt.1 = Counter32: 166
// NETSWITCH-MIB::hpLocalMemAllocSegCnt.1 = Counter32: 3803
// NETSWITCH-MIB::hpLocalMemTotalBytes.1 = INTEGER: 11337704
// NETSWITCH-MIB::hpLocalMemFreeBytes.1 = INTEGER: 9669100
// NETSWITCH-MIB::hpLocalMemAllocBytes.1 = INTEGER: 1668732
// NETSWITCH-MIB::hpGlobalMemSlotIndex.1 = INTEGER: 1
// NETSWITCH-MIB::hpGlobalMemSlabCnt.1 = Counter32: 3966
// NETSWITCH-MIB::hpGlobalMemFreeSegCnt.1 = Counter32: 166
// NETSWITCH-MIB::hpGlobalMemAllocSegCnt.1 = Counter32: 3803
// NETSWITCH-MIB::hpGlobalMemTotalBytes.1 = INTEGER: 11337704
// NETSWITCH-MIB::hpGlobalMemFreeBytes.1 = INTEGER: 9669104
// NETSWITCH-MIB::hpGlobalMemAllocBytes.1 = INTEGER: 1668728
$mempool_array = snmpwalk_cache_oid($device, 'hpLocal', [], $mib);
foreach ($mempool_array as $index => $entry) {
if (is_numeric($index) && is_numeric($entry['hpLocalMemTotalBytes'])) {
$total = $entry['hpLocalMemTotalBytes'];
$used = $entry['hpLocalMemAllocBytes'];
discover_mempool($valid['mempool'], $device, $index, 'NETSWITCH-MIB', "Memory $index", 1, $total, $used);
}
}
unset($mempool_array, $index, $total, $used);
// EOF

View File

@ -0,0 +1,30 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mempool_array = snmpwalk_cache_oid($device, 'oacSysMemStatistics', array(), $mib);
foreach ($mempool_array as $index => $entry)
{
if (is_numeric($index) && is_numeric($entry['oacSysMemoryTotal']))
{
$free = $entry['oacSysMemoryFree'];
$used = $entry['oacSysMemoryAllocated'];
$total = $entry['oacSysMemoryTotal'];
$descr = 'System Memory';
discover_mempool($valid['mempool'], $device, $index, 'ONEACCESS-SYS-MIB', $descr, 1, $total, $used);
}
}
unset ($mempool_array, $index, $total, $used);
// EOF

View File

@ -0,0 +1,27 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
//PEAKFLOW-SP-MIB::devicePhysicalMemory.0 = INTEGER: 8293156
//PEAKFLOW-SP-MIB::devicePhysicalMemoryInUse.0 = INTEGER: 2493368
//PEAKFLOW-SP-MIB::devicePhysicalMemoryUsage.0 = INTEGER: 30
if (!is_device_mib($device, 'HOST-RESOURCES-MIB')) // Memory pools already available in HOST-RESOURCES-MIB
{
$mempool_array = snmp_get_multi_oid($device, 'devicePhysicalMemory.0 devicePhysicalMemoryInUse.0', array(), $mib);
discover_mempool($valid['mempool'], $device, 0, 'PEAKFLOW-SP-MIB', 'Physical Memory', 1024, $mempool_array[0]['devicePhysicalMemory'], $mempool_array[0]['devicePhysicalMemoryInUse']);
unset ($mempool_array);
}
// EOF

View File

@ -0,0 +1,39 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
// S5-CHASSIS-MIB::s5ChasUtilMemoryTotalMB.3.10.0 = Gauge32: 128 MegaBytes
// S5-CHASSIS-MIB::s5ChasUtilMemoryAvailableMB.3.10.0 = Gauge32: 65 MegaBytes
$mempool_array = snmpwalk_cache_oid($device, 's5ChasUtilEntry', array(), $mib);
//$mempool_array = snmpwalk_cache_oid($device, 's5ChasComTable', $mempool_array, 'S5-CHASSIS-MIB:S5-REG-MIB');
//print_vars($mempool_array);
if (!safe_empty($mempool_array)) {
$i = 1;
foreach ($mempool_array as $index => $entry) {
if (is_numeric($entry['s5ChasUtilMemoryAvailableMB']) && is_numeric($entry['s5ChasUtilMemoryTotalMB'])) {
$precision = 1024 * 1024;
$total = $entry['s5ChasUtilMemoryTotalMB'];
//$total *= $precision;
$free = $entry['s5ChasUtilMemoryAvailableMB'];
//$free *= $precision;
$used = $total - $free;
$descr = "Memory Unit $i";
discover_mempool($valid['mempool'], $device, $index, 'S5-CHASSIS-MIB', $descr, $precision, $total, $used);
$i++;
}
}
}
unset($mempool_array, $index, $descr, $precision, $total, $used, $free, $i);
// EOF

View File

@ -0,0 +1,30 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mempool_array = snmpwalk_cache_oid($device, 'memory', array(), $mib);
foreach ($mempool_array as $index => $entry)
{
if (is_numeric($index) && is_numeric($entry['memTotalBytes']))
{
$free = $entry['memFreeBytes'];
$used = $entry['memAllocatedBytes'];
$total = $free + $used; # memTotalBytes is 0 !
$descr = $entry['memDescr'];
discover_mempool($valid['mempool'], $device, $index, 'SMARTNODE-MIB', $descr, 1, $total, $used);
}
}
unset ($mempool_array, $index, $total, $used);
// EOF

View File

@ -0,0 +1,44 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// TIMETRA-SYSTEM-MIB::sgiMemoryUsed.0 = Gauge32: 300145144 bytes
// TIMETRA-SYSTEM-MIB::sgiMemoryAvailable.0 = Gauge32: 518611632 bytes
// TIMETRA-SYSTEM-MIB::sgiMemoryPoolAllocated.0 = Gauge32: 320917080 bytes
// TIMETRA-SYSTEM-MIB::sgiMemoryUsed.0 = Gauge32: 305605608 bytes
// TIMETRA-SYSTEM-MIB::sgiMemoryAvailable.0 = Gauge32: 600985024 bytes
// TIMETRA-SYSTEM-MIB::sgiMemoryPoolAllocated.0 = Gauge32: 325038952 bytes
/*
If the value is greater than the maximum value reportable by this
object then this object reports its maximum value (4,294,967,295)
and sgiKbMemoryPoolAllocated must be used to determine the total
memory allocated in memory-pools.
FIXME: sgiKbMemoryUsed, sgiKbMemoryAvailable, sgiKbMemoryPoolAllocated (use HC bit)
Used is used memory, Available is memory not assigned to pools, PoolAllocated is memory assigned to poools.
Total is calculated with Available+PoolAllocated
*/
$mempool_array = snmpwalk_cache_oid($device, 'sgiMemoryAvailable', array(), $mib);
$mempool_array = snmpwalk_cache_oid($device, 'sgiMemoryUsed', $mempool_array, $mib);
$mempool_array = snmpwalk_cache_oid($device, 'sgiMemoryPoolAllocated', array(), $mib);
if (is_numeric($mempool_array[0]['sgiMemoryUsed']))
{
discover_mempool($valid['mempool'], $device, 0, 'TIMETRA-SYSTEM-MIB', 'Memory', 1, ($mempool_array[0]['sgiMemoryAvailable']+$mempool_array[0]['sgiMemoryPoolAllocated']), $mempool_array[0]['sgiMemoryUsed']);
}
unset ($mempool_array);
// EOF

View File

@ -0,0 +1,115 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// Poll mem for load memory utilisation stats on UNIX-like hosts running UCD/Net-SNMPd
#UCD-SNMP-MIB::memIndex.0 = INTEGER: 0
#UCD-SNMP-MIB::memErrorName.0 = STRING: swap
#UCD-SNMP-MIB::memTotalSwap.0 = INTEGER: 32762248 kB
#UCD-SNMP-MIB::memAvailSwap.0 = INTEGER: 32199396 kB
#UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 8187696 kB
#UCD-SNMP-MIB::memAvailReal.0 = INTEGER: 1211056 kB
#UCD-SNMP-MIB::memTotalFree.0 = INTEGER: 33410452 kB
#UCD-SNMP-MIB::memMinimumSwap.0 = INTEGER: 16000 kB
#UCD-SNMP-MIB::memBuffer.0 = INTEGER: 104388 kB
#UCD-SNMP-MIB::memCached.0 = INTEGER: 2595556 kB
#UCD-SNMP-MIB::memShared.0 = INTEGER: 595556 kB
#UCD-SNMP-MIB::memSwapError.0 = INTEGER: noError(0)
#UCD-SNMP-MIB::memSwapErrorMsg.0 = STRING:
//$snmpdata = snmpwalk_cache_oid($device, "mem", array(), "UCD-SNMP-MIB");
//$data = $snmpdata[0];
$data = snmp_get_multi_oid($device, 'memTotalReal.0 memAvailReal.0 memBuffer.0 memCached.0', array(), 'UCD-SNMP-MIB');
$data = $data[0];
//if(is_array($data) && isset($data['memTotalReal']) && isset($data['memBuffer']) && isset($data['memCached']) && isset($data['memAvailReal']) &&
// $data['memCached'] >= 0 && $data['memBuffer'] >= 0 && $data['memAvailReal'] >= 0 && $data['memTotalReal'] >= 0)
if (is_array($data) && isset($data['memTotalReal']) && isset($data['memAvailReal']) &&
$data['memAvailReal'] >= 0 && $data['memTotalReal'] >= 0)
{
$mempool['total'] = $data['memTotalReal'] * 1024;
$mempool_hc = 0;
/* BEGIN REDHAT BUG */
// CLEANME. remove in r11000, but not before CE 20.8
/**
* New RedHat net-snmp version updated memory calculations:
* https://bugzilla.redhat.com/show_bug.cgi?id=1250060
* https://bugzilla.redhat.com/show_bug.cgi?id=1779609
* See: https://jira.observium.org/browse/OBS-3090
* https://jira.observium.org/browse/OBS-3100
*
* 2019-12-09 - Josef Ridky <jridky@redhat.com> - 1:5.7.2-47
* - revert calculation of free space (#1779609)
* ...
* 2019-05-22 - Josef Ridky <jridky@redhat.com> - 1:5.7.2-43
* - fix available memory calculation (#1250060)
*/
$ucd_version = snmp_get_multi_oid($device, 'versionTag.0 versionCDate.0 versionConfigureOptions.0', array(), 'UCD-SNMP-MIB');
$ucd_version = $ucd_version[0];
// Detect if there redhat locally changed net-snmp package, this patch was added at 2019-05-22
// UCD-SNMP-MIB::versionTag.0 = 5.7.2
// UCD-SNMP-MIB::versionCDate.0 = Wed Sep 18 15:12:36 2019
// UCD-SNMP-MIB::versionConfigureOptions.0 = '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--disable-dependency-tracking' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-static' '--enable-shared' '--with-cflags=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_RPM_4_4_COMPAT' '--with-ldflags=-Wl,-z,relro -Wl,-z,now' '--with-sys-location=Unknown' '--with-logfile=/var/log/snmpd.log' '--with-persistent-directory=/var/lib/net-snmp' '--with-mib-modules=host agentx smux ucd-snmp/diskio tcp-mib udp-mib mibII/mta_sendmail ip-mib/ipv4InterfaceTable ip-mib/ipv6InterfaceTable ip-mib/ipAddressPrefixTable/ipAddressPrefixTable ip-mib/ipDefaultRouterTable/ipDef
if (is_array($ucd_version) && str_contains_array($ucd_version['versionConfigureOptions'], '-redhat-') &&
version_compare($ucd_version['versionTag'], '5.7.2', '>=')
&& strtotime($ucd_version['versionCDate']) > 1558483200)
{
if (strtotime($ucd_version['versionCDate']) >= 1575849600)
{
del_entity_attrib('device', $device['device_id'], 'ucd_memory_bad');
} else {
$mempool['free'] = $data['memAvailReal'] * 1024;
$mempool_hc = 1;
set_entity_attrib('device', $device['device_id'], 'ucd_memory_bad', 1); // Set this attrib for poller/graph
}
}
/* END REDHAT BUG */
if ($mempool_hc === 0)
{
$mempool['free'] = ($data['memAvailReal'] + ($data['memBuffer'] + $data['memCached'])) * 1024;
}
$mempool['used'] = $mempool['total'] - $mempool['free'];
$mempool['perc'] = percent($mempool['free'], $mempool['total'], FALSE);
$index = '0';
$descr = 'Physical Memory';
discover_mempool($valid['mempool'], $device, $index, 'UCD-SNMP-MIB', $descr, 1, $mempool['total'], $mempool['used'], $mempool_hc);
}
/**
This is already collected from HOST-RESOURCES-MIB accurately.
$data = snmp_get_multi_oid($device, 'memTotalSwap.0 memAvailSwap.0', array(), 'UCD-SNMP-MIB');
$data = $data[0];
if(is_array($data) && isset($data['memTotalSwap']) && isset($data['memAvailSwap']) && $data['memTotalSwap'] != 0)
{
$total = $data['memTotalSwap'] * 1024;
$free = $data['memAvailSwap'] * 1024;
$used = $total - $free;
$perc = $free / $total * 100;
$index = 'swap';
$descr = 'Swap memory';
discover_mempool($valid['mempool'], $device, $index, 'UCD-SNMP-MIB', $descr, "1", $total, $used);
}
**/
// EOF

View File

@ -0,0 +1,41 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
// ZHONE-CARD-RESOURCES-MIB::cardRuntimeTable
// ZHONE-CARD-RESOURCES-MIB::cardPeakMemUsage.1.1 = INTEGER: 80762
// ZHONE-CARD-RESOURCES-MIB::cardAvailMem.1.1 = INTEGER: 145131
// ZHONE-CARD-RESOURCES-MIB::cardTotalMem.1.1 = INTEGER: 225421
// ZHONE-CARD-RESOURCES-MIB::cardMemStatus.1.1 = INTEGER: ramMemOK(1)
$mempool_array = snmpwalk_cache_oid($device, "cardAvailMem", array(), $mib);
$mempool_array = snmpwalk_cache_oid($device, "cardTotalMem", $mempool_array, $mib);
$mempool_count = count($mempool_array);
foreach ($mempool_array as $index => $entry)
{
$descr = "Memory";
if ($mempool_count > 1)
{
list($zhoneShelfIndex, $zhoneSlotIndex) = explode('.', $index);
$descr .= " - Shelf $zhoneShelfIndex, Slot $zhoneSlotIndex";
}
$oid_name = 'cardAvailMem';
$used = $entry['cardTotalMem'] - $entry[$oid_name];
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, 1024, $entry['cardTotalMem'], $used);
}
unset ($mempool_array);
// EOF

View File

@ -0,0 +1,41 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mempool_array = snmpwalk_cache_oid($device, 'zxr10SystemUnitTable', array(), $mib);
$mempool_count = count($mempool_array);
if (OBS_DEBUG > 1 && $mempool_count) { print_vars($mempool_array); }
foreach ($mempool_array as $index => $entry)
{
if ($entry['zxr10SystemUnitRunStatus'] == 'down') { continue; }
$descr = 'Memory';
if ($mempool_count > 1)
{
$descr = 'Unit ' . $index . ' ' . $descr;
}
$oid_name = 'zxr10SystemMemUsed'; // Percent
$oid_num = '.1.3.6.1.4.1.3902.3.3.1.1.4.'.$index;
$type = $mib . '-' . $oid_name;
$percent = $entry[$oid_name];
$total = $entry['zxr10SystemMemSize'];
$used = $total * $percent / 100;
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, 1, $total, $used);
}
unset ($mempool_array, $index, $descr, $precision, $total, $used, $percent);
// EOF

View File

@ -0,0 +1,39 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
//ZYXEL-SYS-MEMORY-MIB::zySysMemoryPoolName.1 = STRING: "common"
//ZYXEL-SYS-MEMORY-MIB::zySysMemoryPoolTotalSize.1 = Gauge32: 17636992
//ZYXEL-SYS-MEMORY-MIB::zySysMemoryPoolUsedSize.1 = Gauge32: 7209008
//ZYXEL-SYS-MEMORY-MIB::zySysMemoryPoolUtilization.1 = Gauge32: 40
$mempool_array = snmpwalk_cache_oid($device, 'zyxelSysMemoryPoolEntry', array(), $mib);
print_debug_vars($mempool_array);
foreach ($mempool_array as $index => $entry)
{
$descr = $entry['zySysMemoryPoolName'];
$oid_name = 'zySysMemoryPoolUsedSize';
$oid_num = '.1.3.6.1.4.1.890.1.15.3.50.1.1.1.4.'.$index;
$type = $mib . '-' . $oid_name;
$total = $entry['zySysMemoryPoolTotalSize'];
$used = $entry[$oid_name];
discover_mempool($valid['mempool'], $device, $index, $mib, $descr, 1, $total, $used);
}
unset($mempool_array, $index, $descr, $precision, $total, $used);
// EOF

View File

@ -0,0 +1,392 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
// Init vars
$identities = [];
$identities_found = [];
$mibs_found = []; // 'MIB' => 'where founded' (sysorid, sysordescr, discovery)
$mibs_disable = []; // List mibs for disable
$mibs_rename = [
'ETHERLIKE-MIB' => 'EtherLike-MIB', // Fix camel-case mib name
'Printer-MIB' => 'SKIP-Printer-MIB', // do not discover it by AGENT-CAPABILITIES, that incorrect
'Job-Monitoring-MIB' => 'SKIP-Job-Monitoring-MIB', // do not discover it by AGENT-CAPABILITIES, that incorrect
];
// Agent capabilities for the CISCO-SIP-UA-MIB. LAST-UPDATED 200506220000Z ciscoSipUaCapabilityV12R0402T AGENT-CAPABILITIES SUPPORTS CISCO-SIP-UA-MIB File name: sys
$sysordescr_patterns[] = '/AGENT-CAPABILITIES\s+SUPPORTS\s+(?<mib>\S+)/';
//LLDP-V2-MIB, REVISION 200906080000Z
//ENTITY-MIB, RFC 4133
$sysordescr_patterns[] = '/^(?<mib>\S+), (REVISION \d{12}[A-Z]|RFC \d+)$/i';
$device_sysORID = snmpwalk_oid_num($device, 'sysORID', array(), 'SNMPv2-MIB');
$device_sysORID = snmpwalk_cache_oid($device, 'sysORDescr', $device_sysORID, 'SNMPv2-MIB', NULL, OBS_SNMP_ALL_MULTILINE);
print_debug_vars($device_sysORID);
foreach ($device_sysORID as $entry) {
// Collect founded identities
if (strlen($entry['sysORID'])) {
$identities[] = $entry['sysORID'];
}
// Collect founded MIBs by sysORDescr
foreach ($sysordescr_patterns as $pattern) {
if (preg_match($pattern, $entry['sysORDescr'], $matches)) {
$mib = array_str_replace($mibs_rename, $matches['mib']);
if (!isset($mibs_found[$mib])) {
$mibs_found[$mib] = [ 'source' => 'sysORDescr' ];
// If identity found, append
if (strlen($entry['sysORID'])) {
$mibs_found[$mib]['identity'] = $entry['sysORID'];
}
} else {
print_debug("MIB [$mib] already found");
}
break;
}
}
}
// OS defined sysORID
$os_identities = [];
if (isset($config['os'][$device['os']]['sysorid'])) {
// Ekinops example
// EKINOPS-MGNT2-MIB::mgnt2RootOIDInventory.1 = OID: EKINOPS-Pm200frs02-MIB::pm200frs02ri
// EKINOPS-MGNT2-MIB::mgnt2RootOIDInventory.2 = OID: EKINOPS-PmPassive-MIB::pmpassiveri
$device_sysORID = snmpwalk_oid_num($device, $config['os'][$device['os']]['sysorid'], [], NULL);
print_debug_vars($device_sysORID);
foreach ($device_sysORID as $entry) {
// Collect founded identities
$oid_num = array_shift($entry);
if (preg_match(OBS_PATTERN_SNMP_OID_NUM, $oid_num)) {
$os_identities[] = $oid_num;
}
}
print_debug_vars($os_identities);
}
unset($device_sysORID);
$device_mibs = get_device_mibs($device, FALSE); // MIBs defined by os/model
$device_mibs_bl = get_device_mibs_blacklist($device); // MIBs blacklisted for os/model
// Loop all known MIBs, discovery by snmp requests and validate founded MIB
$GLOBALS['table_rows'] = [];
foreach ($config['mibs'] as $mib => $mib_def) {
if (in_array($mib, $device_mibs_bl)) { continue; } // Skip blacklisted MIB
// Detect MIB by identities
if (!empty($mib_def['identity_num']) && !isset($mibs_found[$mib])) {
foreach ((array)$mib_def['identity_num'] as $identity_num) {
if (in_array($identity_num, $identities)) {
$mibs_found[$mib] = [ 'source' => 'sysORID', 'identity' => $identity_num ];
break;
}
}
if (!isset($mibs_found[$mib]) && count($os_identities)) {
foreach ($os_identities as $identity_num) {
if (match_oid_num($identity_num, $mib_def['identity_num'])) {
$mibs_found[$mib] = [ 'source' => 'OSsysORID', 'identity' => $identity_num ];
break;
}
}
}
}
// Discovery MIB by additional snmp walks
if (isset($mib_def['discovery']) && !isset($mibs_found[$mib])) {
$mib_defined = in_array($mib, $device_mibs); // MIB already defined for os/model
foreach ($mib_def['discovery'] as $def) {
// When MIB defined in os/model, match discovery without filter os/group
// if ($mib_defined)
// {
// unset($def['os'], $def['os_group']);
// }
if (match_discovery_oids($device, $def)) {
$mibs_found[$mib] = [ 'source' => 'Discovery' ];
// If identity found, append
if (!safe_empty($mib_def['identity_num'])) {
$mibs_found[$mib]['identity'] = is_array($mib_def['identity_num']) ? array_shift($mib_def['identity_num']) : $mib_def['identity_num'];
}
break;
}
}
// If mib discovery not found, but os/model have mib defined, opposite disable it
// See FS.COM FS-SWITCH-MIB
// HP
if (!isset($mibs_found[$mib]) && $mib_defined) {
$mibs_disable[$mib] = [ 'source' => 'Discovery' ];
}
}
}
// Just show model specific MIBs
$model = get_model_array($device);
if (isset($model['mibs'])) {
//print_vars($model);
foreach ($model['mibs'] as $mib) {
$mibs_found[$mib] = ['source' => 'Model'];
// If identity found, append
$mib_def = $config['mibs'][$mib];
if (!empty($mib_def['identity_num'])) {
$mibs_found[$mib]['identity'] = is_array($mib_def['identity_num']) ? array_shift($mib_def['identity_num']) : $mib_def['identity_num'];
}
}
}
// Show matched discovery mibs
if (safe_count($GLOBALS['table_rows'])) {
//$table_opts = array('max-table-width' => 200);
$table_headers = array('%WOID%n', '%WMatched definition%n', '%WValue%n');
print_cli_table($GLOBALS['table_rows'], $table_headers);
}
unset($GLOBALS['table_rows']);
/* Detect correct (new) version of FASTPATH mibs */
$old_fastpath_mibs = [
'BROADCOM-POWER-ETHERNET-MIB',
'FASTPATH-BOXSERVICES-PRIVATE-MIB',
'FASTPATH-SWITCHING-MIB',
'FASTPATH-ISDP-MIB'
];
if (safe_count($mibs_found) && !empty(array_intersect(array_keys($mibs_found), $old_fastpath_mibs))) {
$use_fastpath_new = FALSE;
// OID tree: .1.3.6.1.4.1.4413.1.1
// FASTPATH is old reference BROADCOM mibs
// First detect by CPU by 'EdgeSwitch-SWITCHING-MIB'
//FASTPATH-SWITCHING-MIB::agentSwitchCpuProcessGroup.9.0 = STRING: " 5 Secs ( 99.9999%) 60 Secs ( 99.6646%) 300 Secs ( 99.2548%)"
//EdgeSwitch-SWITCHING-MIB::agentSwitchCpuProcessTotalUtilization.0 = STRING: " 5 Secs ( 99.9999%) 60 Secs ( 99.9224%) 300 Secs ( 99.4892%)"
$data = snmp_get_oid($device, 'agentSwitchCpuProcessTotalUtilization.0', 'EdgeSwitch-SWITCHING-MIB');
$use_fastpath_new = preg_match('/300 Secs \(\s*(?<proc>[\d\.]+)%\)/', $data);
// Second detect by Temperature indexes by 'EdgeSwitch-BOXSERVICES-PRIVATE-MIB'
if (empty($data)) {
$oids = snmpwalk_cache_oid($device, 'boxServicesTempSensorsTable', array(), 'EdgeSwitch-BOXSERVICES-PRIVATE-MIB');
// By first detect if device used old FAST-BOXSERVICES-PRIVATE-MIB, it use single key in boxServicesTempSensorsTable
$first_key = current(array_keys($oids));
$use_fastpath_new = count(explode('.', $first_key)) > 1;
}
// Rewrite all founded FASTPATH MIBs
if ($use_fastpath_new) {
foreach ($old_fastpath_mibs as $mib) {
if (isset($mibs_found[$mib])) {
$new_mib = str_replace(array('BROADCOM', 'FASTPATH'), 'EdgeSwitch', $mib);
$mibs_found[$new_mib] = $mibs_found[$mib];
$mibs_found[$new_mib]['source'] .= ' (FASTPATH)';
unset($mibs_found[$mib]);
print_debug("FASTPATH detect hack, mib renamed: $mib -> $new_mib");
}
}
}
}
unset($new_mib, $use_fastpath_new, $data, $first_key);
/* End of FASTPATH hack */
// Now filter known MIBs and pretty print
print_cli_data_field('MIBs discovered');
$table_rows = [];
foreach ($mibs_found as $mib => $entry) {
$identity_num = $entry['identity'];
$identities_found[] = $identity_num;
if (in_array($mib, $device_mibs_bl)) {
// MIB is in our blacklist, bail out
$table_rows[] = [ $identity_num, $mib, $entry['source'], '%mMIB blacklisted%n' ];
unset($mibs_found[$mib]);
continue;
} elseif (!isset($config['mibs'][$mib])) {
// MIB is currently unsupported by Observium
$table_rows[] = [ $identity_num, $mib, $entry['source'], 'MIB not used' ];
unset($mibs_found[$mib]);
continue;
} elseif (isset($config['mibs'][$mib]['enable']) && !$config['mibs'][$mib]['enable']) {
// MIB is currently unsupported by Observium
$table_rows[] = [ $identity_num, $mib, $entry['source'], '%rMIB disabled globally%n' ];
unset($mibs_found[$mib]);
continue;
} elseif (in_array($mib, $device_mibs)) {
// Already mapped
$table_rows[] = [ $identity_num, "%y$mib%n", $entry['source'], '%yMIB already defined%n' ];
unset($mibs_found[$mib]);
continue;
}
// Checks ended, this MIB will add
echo("$mib ");
$table_rows[] = array($identity_num, "%g$mib%n", $entry['source'], '%gMIB added%n');
}
foreach ($mibs_disable as $mib => $entry) {
// MIB defined for os/model, but not discovered by snmp check
$table_rows[] = array('', "%r$mib%n", $entry['source'], '%rMIB defined for os but not found%n');
// Not correctly for cases when discovery limited with os/group
// Currently only inform
//set_device_mib_disable($device, $mib);
}
// Clean cached device mibs
if (safe_count($mibs_disable) && isset($cache['devices']['mibs_disabled'][$device['device_id']])) {
//$cache['devices']['mibs'][$device['device_id']] = array_diff($cache['devices']['mibs'][$device['device_id']], array_keys($mibs_disable));
unset($cache['devices']['mibs_disabled'][$device['device_id']]);
}
// Additionally filter found identities, just for show that exist but unknown
$identities = array_diff((array)$identities, (array)$identities_found);
foreach ($identities as $identity_num) {
$table_rows[] = array($identity_num, '-', 'sysORID', '%cUnknown Identity%n');
}
// Set device attribute if we found any new MIBs, else delete the attribute
if (count($mibs_found)) {
$sysORID_db = safe_json_decode(get_entity_attrib('device', $device, 'sysORID'));
$sysORID_mibs = array_keys($mibs_found);
$update_array = array_diff($sysORID_mibs, (array)$sysORID_db);
$delete_array = array_diff((array)$sysORID_db, $sysORID_mibs);
//print_vars($sysORID_db);
//print_vars($sysORID_mibs);
//print_vars($update_array);
//print_vars($delete_array);
if (count($update_array)) {
set_entity_attrib('device', $device, 'sysORID', safe_json_encode($sysORID_mibs));
log_event("MIBs discovered: '" . implode("', '", $update_array) . "'", $device, 'device', $device['device_id']);
// reset cache
if (isset($GLOBALS['cache']['devices']['mibs'][$device['device_id']])) {
unset($GLOBALS['cache']['devices']['mibs'][$device['device_id']]);
unset($GLOBALS['cache']['entity_attribs']['device'][$device['device_id']]['sysORID']);
}
} elseif (count($delete_array)) {
set_entity_attrib('device', $device, 'sysORID', safe_json_encode($sysORID_mibs));
log_event("MIBs removed: '" . implode("', '", $delete_array) . "'", $device, 'device', $device['device_id']);
// reset cache
if (isset($GLOBALS['cache']['devices']['mibs'][$device['device_id']])) {
unset($GLOBALS['cache']['devices']['mibs'][$device['device_id']]);
unset($GLOBALS['cache']['entity_attribs']['device'][$device['device_id']]['sysORID']);
}
}
} else {
echo('<empty>');
del_entity_attrib('device', $device, 'sysORID');
// reset cache
if (isset($GLOBALS['cache']['devices']['mibs'][$device['device_id']])) {
unset($GLOBALS['cache']['devices']['mibs'][$device['device_id']]);
unset($GLOBALS['cache']['entity_attribs']['device'][$device['device_id']]['sysORID']);
}
}
if (count($table_rows)) {
echo(PHP_EOL);
$table_headers = array('%WIdentity%n', '%WMIB%n', '%WSource%n', '%WStatus%n');
print_cli_table($table_rows, $table_headers);
}
// Need to check if module disabled?
if (FALSE) {
// sysORID table disabled, delete the attribute
del_entity_attrib('device', $device, 'sysORID');
}
print_debug_vars(get_device_mibs_permitted($device), 1);
///FIXME. This is not exactly related to mibs, but this need check before all other discovery modules
// Detect (if possible) exist snmp contexts on device (currently only on Cisco IOS, IOS-XE and NX-OS
/* DISABLED, while not know what TODO with this,
* currently same functionality only for Cisco Nexis in VRF module
if (isset($config['os'][$device['os']]['snmp']['virtual_oid']))
{
$contexts = [];
foreach (snmpwalk_values($device, $config['os'][$device['os']]['snmp']['virtual_oid'], []) as $context)
{
if ($context !== '')
{
$contexts[] = $context;
}
}
$contexts = array_unique($contexts);
print_debug_vars($contexts);
// Add non VLAN contexts to device array, for use in discovery modules
foreach ($contexts as $context)
{
// Detect Vlan specific contexts
if (preg_match('/^(vlan\-)?(?<vlan>\d{1,4})$/', $context, $matches) &&
$matches['vlan'] > 0 && $matches['vlan'] < 4096)
{
continue;
}
$device['snmp_contexts'][] = $context;
}
$contexts_db = safe_json_decode(get_entity_attrib('device', $device, 'snmp_contexts'));
print_debug_vars($contexts_db);
$update_array = array_diff($contexts, (array)$contexts_db);
print_debug_vars($update_array);
$delete_array = array_diff((array)$contexts_db, $contexts);
print_debug_vars($delete_array);
if (count($contexts_db) && empty($contexts))
{
del_entity_attrib('device', $device, 'snmp_contexts');
log_event("SNMP contexts removed.", $device, 'device', $device['device_id']);
}
elseif (count($update_array))
{
set_entity_attrib('device', $device, 'snmp_contexts', safe_json_encode($contexts));
$update_vlans = [];
foreach ($update_array as $k => $context)
{
// Detect Vlan specific contexts
if (preg_match('/^(vlan\-)?(?<vlan>\d{1,4})$/', $context, $matches) &&
$matches['vlan'] > 0 && $matches['vlan'] < 4096)
{
$update_vlans[] = $matches['vlan'];
unset($update_array[$k]);
}
}
print_debug_vars($update_vlans);
$log_msg = 'SNMP contexts found: ';
if ($update_array)
{
log_event("SNMP contexts found: '" . implode("', '", $update_array) . "'", $device, 'device', $device['device_id']);
}
if ($update_vlans)
{
log_event("SNMP contexts found: VLANs " . range_to_list(array_unique($update_vlans), ', '), $device, 'device', $device['device_id']);
}
}
elseif (count($delete_array))
{
set_entity_attrib('device', $device, 'snmp_contexts', safe_json_encode($contexts));
log_event("SNMP contexts removed: '" . implode("', '", $delete_array) . "'", $device, 'device', $device['device_id']);
}
}
*/
// EOF

View File

@ -0,0 +1,66 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
*
*/
$valid['neighbours'] = array();
// SELECT * FROM `autodiscovery` WHERE `remote_device_id` IS NOT NULL AND `remote_device_id` NOT IN (SELECT `device_id` FROM `devices`)
// Include all discovery modules
$include_dir = "includes/discovery/neighbours";
include("includes/include-dir-mib.inc.php");
$table_rows = array();
$neighbours_db = dbFetchRows('SELECT * FROM `neighbours` WHERE `device_id` = ?', array($device['device_id']));
foreach ($neighbours_db as $neighbour)
{
$local_port_id = $neighbour['port_id'];
$remote_hostname = $neighbour['remote_hostname'];
$remote_address = $neighbour['remote_address'];
$remote_port = $neighbour['remote_port'];
$valid_host_key = $remote_hostname;
if (strlen($remote_address))
{
$valid_host_key .= '-' . $remote_address;
}
print_debug("$local_port_id -> $remote_hostname ($remote_address) -> $remote_port");
if (!$valid['neighbours'][$local_port_id][$valid_host_key][$remote_port])
{
// Do not remove deleted from db
//dbDelete('neighbours', '`neighbour_id` = ?', array($neighbour['neighbour_id']));
if ($neighbour['active'] == '1')
{
dbUpdate([ 'active' => 0 ], 'neighbours', '`neighbour_id` = ?', [ $neighbour['neighbour_id'] ]);
$GLOBALS['module_stats'][$module]['deleted']++;
}
} else {
$port = get_port_by_id_cache($local_port_id);
if (is_numeric($neighbour['remote_port_id']) && $neighbour['remote_port_id'])
{
$remote_port_array = get_port_by_id_cache($neighbour['remote_port_id']);
$remote_port = $remote_port_array['port_label'];
}
if (strlen($remote_address)) { $remote_hostname .= " ($remote_address)"; }
$table_rows[] = array(nicecase($neighbour['protocol']), $port['port_label'], $remote_hostname, $remote_port, truncate($neighbour['remote_platform'], 20), truncate($neighbour['remote_version'], 40));
}
}
echo(PHP_EOL);
$table_headers = array('%WProtocol%n', '%WifName%n', '%WRemote: hostname%n', '%Wport%n', '%Wplatform%n', '%Wversion%n');
print_cli_table($table_rows, $table_headers);
$GLOBALS['module_stats'][$module]['status'] = safe_count($valid[$module]);
if (OBS_DEBUG && $GLOBALS['module_stats'][$module]['status']) { print_vars($valid[$module]); }
unset($valid['neighbours']);
echo(PHP_EOL);
// EOF

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