Commit version 24.12.13800
This commit is contained in:
@ -3,15 +3,16 @@
|
||||
# hddtemp sensor readings
|
||||
# needs hddtemp daemon listening on (at least) localhost
|
||||
# requires netcat to be installed and in the path
|
||||
# (c) 2012, Tom Laermans for Observium
|
||||
# (c) 2012-2023, Tom Laermans for Observium
|
||||
|
||||
hostname="localhost"
|
||||
port=7634
|
||||
nc=`which nc`
|
||||
PORT=7634
|
||||
|
||||
if [ $? -eq 0 ] && [ `$nc -zv $hostname $port 2>&1 | awk '{print $NF}'` = "open" ]
|
||||
# Test connection
|
||||
OUTPUT=$(nc localhost ${PORT})
|
||||
|
||||
# If no error when tonnecting to the port, show output
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo '<<<hddtemp>>>'
|
||||
$nc $hostname $port
|
||||
echo
|
||||
echo $OUTPUT
|
||||
fi
|
||||
|
@ -10,8 +10,8 @@ then
|
||||
if [ -x "$script" ]
|
||||
then
|
||||
echo "<<<munin-$script>>>"
|
||||
./$script
|
||||
./$script config
|
||||
munin-run $script
|
||||
munin-run $script config
|
||||
fi
|
||||
done
|
||||
cd ..
|
||||
|
@ -81,7 +81,7 @@ if (file_exists(__FILE__ . '.cnf' ) ) {
|
||||
# Make this a happy little script even when there are errors.
|
||||
$no_http_headers = true;
|
||||
ini_set('implicit_flush', false); # No output, ever.
|
||||
if ($debug ) {
|
||||
if ($debug) {
|
||||
ini_set('display_errors', true);
|
||||
ini_set('display_startup_errors', true);
|
||||
ini_set('error_reporting', 2147483647);
|
||||
@ -496,8 +496,8 @@ function ss_get_mysql_stats( $options ) {
|
||||
# Get SHOW INNODB STATUS and extract the desired metrics from it, then add
|
||||
# those to the array too.
|
||||
if ($chk_options['innodb']
|
||||
&& array_key_exists('have_innodb', $status)
|
||||
&& $status['have_innodb'] == 'YES'
|
||||
&& ((array_key_exists('have_innodb', $status) && $status['have_innodb'] === 'YES') ||
|
||||
(array_key_exists('Innodb_data_read', $status)))
|
||||
) {
|
||||
$result = run_query("SHOW /*!50000 ENGINE*/ INNODB STATUS", $conn);
|
||||
$istatus_text = $result[0]['Status'];
|
||||
@ -1117,8 +1117,7 @@ function make_bigint ($hi, $lo = null) {
|
||||
if (is_null($lo) ) {
|
||||
# Assume it is a hex string representation.
|
||||
return base_convert($hi, 16, 10);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$hi = $hi ? $hi : '0'; # Handle empty-string or whatnot
|
||||
$lo = $lo ? $lo : '0';
|
||||
return big_add(big_multiply($hi, 4294967296), $lo);
|
||||
@ -1303,4 +1302,4 @@ function debug($val) {
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
// EOF
|
||||
|
@ -81,11 +81,14 @@ $conn = DBI->connect ("DBI:$drvName:dbname=$dbName;host=$hostName;", $dbUser, $d
|
||||
# select version();
|
||||
$cmd="select version()";
|
||||
$all = sqlArray($cmd);
|
||||
$all =~ /\w+ (\d\.\d)/;
|
||||
$all =~ /\w+ (\d+\.\d)/;
|
||||
$version=$1;
|
||||
|
||||
# get the stats
|
||||
if ($version =~ /^[89]\.\d$/) {
|
||||
if ($version =~ /^15\.\d+$/) {
|
||||
$cmd="select datname, usename, client_addr, query as current_query from pg_stat_activity";
|
||||
}
|
||||
elsif ($version =~ /^[89]\.\d$/) {
|
||||
$cmd="select datname, usename, client_addr, current_query from pg_stat_activity";
|
||||
}
|
||||
|
||||
@ -131,7 +134,13 @@ for (; $all=$query->fetchrow_hashref() ;) {
|
||||
# (subtracting previous value from the current one would give you number of commits finished in N minutes).
|
||||
|
||||
# postgresql version 8.x have fewer stats (no tuples)
|
||||
if ($version =~ /^8\.[34]|9\.\d$/) {
|
||||
if ($version =~ /^15\.\d+$/) {
|
||||
$cmd="SELECT SUM(xact_commit) as xact_commit, SUM(xact_rollback) as xact_rollback, SUM(blks_read) as blks_read,
|
||||
SUM(blks_hit) as blks_hit, SUM(tup_returned) as tup_returned, SUM(tup_fetched) as tup_fetched,
|
||||
SUM(tup_inserted) as tup_inserted, SUM(tup_updated) as tup_updated, SUM(tup_deleted) as tup_deleted
|
||||
FROM pg_stat_database";
|
||||
}
|
||||
elsif ($version =~ /^8\.[34]|9\.\d$/) {
|
||||
$cmd="SELECT SUM(xact_commit) as xact_commit, SUM(xact_rollback) as xact_rollback, SUM(blks_read) as blks_read,
|
||||
SUM(blks_hit) as blks_hit, SUM(tup_returned) as tup_returned, SUM(tup_fetched) as tup_fetched,
|
||||
SUM(tup_inserted) as tup_inserted, SUM(tup_updated) as tup_updated, SUM(tup_deleted) as tup_deleted
|
||||
|
@ -4,6 +4,6 @@ recctrl=`which rec_control`
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo '<<<app-powerdns-recursor>>>'
|
||||
echo '<<<app-powerdns_recursor>>>'
|
||||
$recctrl get-all
|
||||
fi
|
||||
|
@ -6,7 +6,7 @@
|
||||
#
|
||||
# Simple os icons checker script
|
||||
#
|
||||
# @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
|
||||
# @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2023 Observium Limited
|
||||
# @author Mike Stupalov <mike@observium.org>
|
||||
#
|
||||
|
||||
|
100
scripts/distro
100
scripts/distro
@ -2,7 +2,7 @@
|
||||
#
|
||||
# Observium License Version 1.0
|
||||
#
|
||||
# Copyright (c) 2013-2019 Joe Holden, (c) 2015 Mike Stupalov
|
||||
# Copyright (C) 2013-2019 Joe Holden, (C) 2014-2024 Observium Limited
|
||||
#
|
||||
# The intent of this license is to establish the freedom to use, share and contribute to
|
||||
# the software regulated by this license.
|
||||
@ -46,7 +46,7 @@
|
||||
#
|
||||
# URL: [https://www.observium.org/files/distro]
|
||||
|
||||
DISTROSCRIPT="2.2.5"
|
||||
DISTROSCRIPT="2.3.2"
|
||||
|
||||
if [ -z ${DISTROFORMAT} ]; then
|
||||
DISTROFORMAT="pipe"
|
||||
@ -87,11 +87,21 @@ getdistro() {
|
||||
if [ -f /etc/armbian-release ]; then
|
||||
# Armbian uses incorrect os-release
|
||||
DISTRO="Armbian"
|
||||
elif [ -f /etc/orangepi-release ]; then
|
||||
# Orange Pi uses incorrect os-release
|
||||
DISTRO="Orange OS"
|
||||
elif [ -f /boot/dietpi/.version ]; then
|
||||
# This is clone of Raspbian, but distro/version incorrect
|
||||
DISTRO="DietPi"
|
||||
else
|
||||
# note, this source include also set variable name $VERSION, ie on debian "10 (buster)"
|
||||
. /etc/os-release
|
||||
#DISTRO=`echo ${NAME} | awk '{print $1}'`
|
||||
DISTRO="${NAME% *}"
|
||||
if [ "${DISTRO}" = "Linux" ]; then
|
||||
# ie: Linux Mint
|
||||
DISTRO="${NAME#Linux *}"
|
||||
fi
|
||||
fi
|
||||
elif [ -x /usr/bin/lsb_release ]; then
|
||||
DISTRO=`/usr/bin/lsb_release -si 2>/dev/null`
|
||||
@ -181,12 +191,19 @@ getdistro() {
|
||||
DISTRO=
|
||||
fi
|
||||
|
||||
# Additional Distro fixes
|
||||
if [ "${DISTRO}" = "Debian GNU/Linux" ]; then
|
||||
DISTRO="Debian"
|
||||
elif [ "${DISTRO}" = "Red" -o "${DISTRO}" = "RedHatEnterpriseServer" ]; then
|
||||
DISTRO="RedHat"
|
||||
elif [ "${DISTRO}" = "VMware Photon" ]; then
|
||||
DISTRO="Photon"
|
||||
elif [ "${DISTRO}" = "Arch" ]; then
|
||||
DISTRO="ArchLinux"
|
||||
DISTRO="Arch Linux"
|
||||
elif [ "${DISTRO}" = "Orange" ]; then
|
||||
DISTRO="Orange OS"
|
||||
elif [ "${DISTRO}" = "Amazon" ]; then
|
||||
DISTRO="Amazon Linux"
|
||||
fi
|
||||
|
||||
elif [ "${OS}" = "FreeBSD" ]; then
|
||||
@ -194,6 +211,8 @@ getdistro() {
|
||||
DISTRO="pfSense"
|
||||
elif [ -f /etc/platform -a -f /etc/prd.name ]; then
|
||||
DISTRO=`cat /etc/prd.name`
|
||||
elif [ -x /usr/local/sbin/opnsense-version ]; then
|
||||
DISTRO="OPNsense"
|
||||
elif [ -f /usr/local/bin/pbreg ]; then
|
||||
DISTRO="PC-BSD"
|
||||
elif [ -f /usr/sbin/hbsd-update -o -f /etc/hbsd-update.conf ]; then
|
||||
@ -261,6 +280,8 @@ getversion() {
|
||||
#elif [ "${DISTRO}" = "HardenedBSD" ]; then
|
||||
# tmp=`sysctl -n hardening.version 2>/dev/null`
|
||||
# VERSION=``
|
||||
elif [ "${DISTRO}" = "OPNsense" ]; then
|
||||
VERSION=`/usr/local/sbin/opnsense-version | awk '{ print $2 }'`
|
||||
elif [ -f /etc/prd.version ]; then
|
||||
VERSION=`cat /etc/prd.version`
|
||||
elif [ -f /bin/freebsd-version ]; then
|
||||
@ -282,6 +303,14 @@ getversion() {
|
||||
elif [ "${DISTRO}" = "Armbian" ]; then
|
||||
#. /etc/armbian-release
|
||||
VERSION=`awk -F '=' '/VERSION=/ { print $2 }' /etc/armbian-release`
|
||||
elif [ "${DISTRO}" = "Orange OS" ]; then
|
||||
#. /etc/orangepi-release
|
||||
VERSION=`awk -F '=' '/VERSION=/ { print $2 }' /etc/orangepi-release`
|
||||
elif [ "${DISTRO}" = "DietPi" ]; then
|
||||
. /boot/dietpi/.version
|
||||
VERSION="${G_DIETPI_VERSION_CORE}.${G_DIETPI_VERSION_SUB}.${G_DIETPI_VERSION_RC}"
|
||||
elif [ -f /etc/orangepi-os-version ]; then
|
||||
VERSION=`awk -F ' - ' '{ print $NF }' /etc/orangepi-os-version | sed 's/-linux.*//'`
|
||||
elif [ -f /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
VERSION="${VERSION_ID}"
|
||||
@ -348,7 +377,7 @@ detectvirt() {
|
||||
KVM*|[Go][Oo][Oo][Gg][Ll][Ee]*)
|
||||
type=kvm
|
||||
;;
|
||||
zvm|oracle|bochs|uml|parallels|kvm|qemu|qnx|acrn|powervm)
|
||||
zvm|oracle|amazon|bochs|uml|parallels|kvm|qemu|qnx|acrn|powervm)
|
||||
type="${1}"
|
||||
;;
|
||||
vm-other)
|
||||
@ -417,6 +446,14 @@ getvirt() {
|
||||
if [ "${OS}" = "Linux" ]; then
|
||||
if [ "${VIRT}" = "none" -a -f /usr/bin/systemd-detect-virt ]; then
|
||||
tmp=`/usr/bin/systemd-detect-virt -v`
|
||||
# systemd-detect-virt falsely detects "Microsoft" virtualisation
|
||||
# https://github.com/systemd/systemd/issues/21468
|
||||
if [ "${tmp}" = "microsoft" -a -f /sys/devices/virtual/dmi/id/product_name ]; then
|
||||
tmp2=`cat /sys/devices/virtual/dmi/id/product_name`
|
||||
if [ "${tmp2}" = "KVM" ]; then
|
||||
tmp="${tmp2}"
|
||||
fi
|
||||
fi
|
||||
VIRT=`detectvirt "${tmp}"`
|
||||
fi
|
||||
if [ "${VIRT}" = "none" -a -f /sys/devices/virtual/dmi/id/product_name ]; then
|
||||
@ -470,6 +507,61 @@ getvirt() {
|
||||
return 0
|
||||
}
|
||||
|
||||
help() {
|
||||
cat << EOF
|
||||
Usage: distro [-f format] [-o out] [-h] [-v]
|
||||
|
||||
Options:
|
||||
-f <format> Output format: pipe (default), twopipe, json, ini, export
|
||||
-o <out> Show specific parameter only: os, kernel, arch, distro,
|
||||
version, virt, cont
|
||||
-h Show help
|
||||
-v Show version
|
||||
|
||||
See the distro homepage at https://docs.observium.org/distro_script
|
||||
and source code at https://github.com/observium/distroscript
|
||||
EOF
|
||||
}
|
||||
|
||||
while getopts vho:f: flag
|
||||
do
|
||||
case "${flag}" in
|
||||
v) echo $DISTROSCRIPT; exit;;
|
||||
h) help; exit;;
|
||||
o)
|
||||
getos
|
||||
getdistro
|
||||
if [ "${OPTARG}" = "os" ]; then
|
||||
#getos
|
||||
echo $OS
|
||||
elif [ "${OPTARG}" = "kernel" ]; then
|
||||
getkernel
|
||||
echo $KERNEL
|
||||
elif [ "${OPTARG}" = "arch" ]; then
|
||||
getarch
|
||||
echo $ARCH
|
||||
elif [ "${OPTARG}" = "distro" ]; then
|
||||
#getdistro
|
||||
echo $DISTRO
|
||||
elif [ "${OPTARG}" = "version" ]; then
|
||||
getversion
|
||||
echo $VERSION
|
||||
elif [ "${OPTARG}" = "virt" ]; then
|
||||
getvirt
|
||||
echo $VIRT
|
||||
elif [ "${OPTARG}" = "cont" ]; then
|
||||
getcont
|
||||
echo $CONT
|
||||
fi
|
||||
exit
|
||||
;;
|
||||
f) if [ "${OPTARG}" = "pipe" -o "${OPTARG}" = "twopipe" -o "${OPTARG}" = "json" -o "${OPTARG}" = "export" -o "${OPTARG}" = "ini" ]; then
|
||||
DISTROFORMAT=${OPTARG}
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z ${DISTROEXEC+x} ]; then
|
||||
|
||||
getos
|
||||
|
@ -5,140 +5,110 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage scripts
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage scripts
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
chdir(dirname($argv[0]).'/..');
|
||||
chdir(dirname($argv[0]) . '/..');
|
||||
|
||||
$options = getopt("da");
|
||||
if (isset($options['d'])) { array_shift($argv); } // for compatibility
|
||||
if (isset($options['a'])) { array_shift($argv); } // for compatibility
|
||||
if (isset($options['d'])) {
|
||||
array_shift($argv);
|
||||
} // for compatibility
|
||||
if (isset($options['a'])) {
|
||||
array_shift($argv);
|
||||
} // for compatibility
|
||||
|
||||
include_once("includes/sql-config.inc.php");
|
||||
include_once("includes/observium.inc.php");
|
||||
|
||||
//$config['rancid_version'] = '3.7.1';
|
||||
//$config['rancid_version'] = '3.7.1'; // test
|
||||
|
||||
// Detect configured version
|
||||
if (isset($config['rancid_version'])) {
|
||||
// Rancid version set manually
|
||||
$rancid_config_version = ltrim($config['rancid_version'], 'vV');
|
||||
list($rancid_config_base) = explode('.', $rancid_config_version);
|
||||
// $rancid_message = "Used RANCID version configured manually in \$config['rancid_version']: $rancid_version";
|
||||
} else {
|
||||
// Dummy version for compare
|
||||
$rancid_config_version = 0;
|
||||
$rancid_config_base = 0;
|
||||
}
|
||||
|
||||
// Detect locally installed version
|
||||
// Rancid version configured manually
|
||||
$rancid_config_version = isset($config['rancid_version']) ? ltrim($config['rancid_version'], 'vV') : 0;
|
||||
// Detect locally installed rancid version
|
||||
if ($rancid_cmd = external_exec('which rancid-run')) {
|
||||
list(, $rancid_cmd_version) = explode(' ', external_exec($rancid_cmd . ' -V'));
|
||||
list($rancid_cmd_base) = explode('.', $rancid_cmd_version);
|
||||
$rancid_cmd_version = explode(' ', external_exec($rancid_cmd . ' -V'))[1];
|
||||
} else {
|
||||
// Dummy version for compare
|
||||
$rancid_cmd_version = 0;
|
||||
$rancid_cmd_base = 0;
|
||||
// Dummy version for compare
|
||||
$rancid_cmd_version = 0;
|
||||
}
|
||||
|
||||
if ($rancid_config_base > 0 && $rancid_cmd_base > 0 && $rancid_config_base != $rancid_cmd_base) {
|
||||
// If configured version base different from detected, than prefer configured (ie, for force v2 delimiter
|
||||
$rancid_version_base = $rancid_config_base;
|
||||
$rancid_version = $rancid_config_version;
|
||||
$rancid_message = "Used RANCID version configured manually in \$config['rancid_version']: $rancid_version";
|
||||
} elseif (version_compare($rancid_cmd_version, $rancid_config_version, '>')) {
|
||||
// RANCID locally detected, use maximum version
|
||||
$rancid_version_base = $rancid_cmd_version;
|
||||
$rancid_version = $rancid_cmd_version;
|
||||
$rancid_message = "Used RANCID version detected on system: $rancid_version";
|
||||
} elseif (version_compare($rancid_config_version, '0', '>')) {
|
||||
// RANCID not detected, but version configured
|
||||
$rancid_version_base = $rancid_config_base;
|
||||
$rancid_version = $rancid_config_version;
|
||||
$rancid_message = "Used RANCID version configured manually in \$config['rancid_version']: $rancid_version";
|
||||
} else {
|
||||
// Last compat version
|
||||
$rancid_version_base = '2';
|
||||
$rancid_version = '2';
|
||||
$rancid_message = "Used default RANCID version: $rancid_version";
|
||||
}
|
||||
$rancid_version = rtrim($rancid_version, '.0');
|
||||
$rancid_version = version_compare($rancid_cmd_version, $rancid_config_version, '>') ? $rancid_cmd_version : $rancid_config_version;
|
||||
$rancid_version = $rancid_version ? trim_number($rancid_version) : '3'; // set default version to 3+
|
||||
$rancid_version_major = explode('.', $rancid_version)[0];
|
||||
|
||||
// Set delimiter
|
||||
if ($rancid_version_base < 3) {
|
||||
$delimiter = ':';
|
||||
} else {
|
||||
$delimiter = ';';
|
||||
}
|
||||
|
||||
print_debug($rancid_message);
|
||||
$delimiter = $rancid_version_major < 3 ? ':' : ';';
|
||||
|
||||
$os_maps = [];
|
||||
|
||||
// Add user defined os maps first
|
||||
if (is_array($config['rancid']['os_map'])) {
|
||||
foreach ($config['rancid']['os_map'] as $os => $name) {
|
||||
$os_maps[$os][] = [ 'name' => $name ];
|
||||
}
|
||||
foreach ($config['rancid']['os_map'] as $os => $name) {
|
||||
$os_maps[$os][] = [ 'name' => $name ];
|
||||
}
|
||||
}
|
||||
|
||||
// OS maps from definitions
|
||||
foreach ($config['os'] as $os => $entry) {
|
||||
if (!isset($entry['rancid'])) { continue; }
|
||||
if (!isset($entry['rancid'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$os_maps[$os] = $entry['rancid'];
|
||||
$os_maps[$os] = $entry['rancid'];
|
||||
}
|
||||
|
||||
print_debug_vars($os_maps, 1);
|
||||
|
||||
?>
|
||||
# RANCID router.db autogenerated by <?php echo realpath($_SERVER['SCRIPT_FILENAME']) . PHP_EOL; ?>
|
||||
# <?php echo $rancid_message . PHP_EOL; ?>
|
||||
# RANCID version <?php echo $rancid_version . PHP_EOL; ?>
|
||||
# Do not edit this file directly!
|
||||
|
||||
<?php
|
||||
|
||||
$where = 'WHERE 1';
|
||||
$params = [];
|
||||
if (!isset($options['a'])) {
|
||||
$where .= ' AND `poller_id` = ?';
|
||||
$params[] = $config['poller_id'];
|
||||
}
|
||||
// Limit devices with rancid supported os
|
||||
$where .= generate_query_values_and(array_keys($os_maps), 'os');
|
||||
$sql = "SELECT `hostname`, `os`, `version`, `hardware`, `disabled`, `status` FROM `devices` " . $where . " ORDER BY `hostname`";
|
||||
foreach (dbFetchRows($sql, $params) as $device) {
|
||||
// rancid_device_blacklist or rancid_host_blacklist??
|
||||
if (is_array($config['rancid_device_blacklist']) &&
|
||||
in_array($device['hostname'], $config['rancid_host_blacklist'], TRUE)) { continue; }
|
||||
$where_array = [];
|
||||
if (!isset($options['a'])) {
|
||||
$where_array[] = generate_query_values($config['poller_id'], 'poller_id');
|
||||
}
|
||||
$where_array[] = generate_query_values(array_keys($os_maps), 'os');
|
||||
$sql = "SELECT `hostname`, `os`, `version`, `hardware`, `disabled`, `status` FROM `devices` " . generate_where_clause($where_array) . " ORDER BY `hostname`";
|
||||
foreach (dbFetchRows($sql) as $device) {
|
||||
// blacklisted hosts
|
||||
if (isset($config['rancid_host_blacklist']) &&
|
||||
(in_array($device['hostname'], (array)$config['rancid_host_blacklist'], TRUE) ||
|
||||
in_array($device['ip'], (array)$config['rancid_host_blacklist'], TRUE))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($device['disabled'] || !$device['status']) {
|
||||
$status = "down";
|
||||
} else {
|
||||
$status = "up";
|
||||
}
|
||||
//print_vars($device);
|
||||
// Up for not disabled and available devices
|
||||
$rancid_status = ($device['disabled'] || !$device['status']) ? "down" : "up";
|
||||
//print_vars($device);
|
||||
|
||||
// New defs
|
||||
foreach ($os_maps[$device['os']] as $rancid_map) {
|
||||
// Need check hardware for map
|
||||
if (isset($rancid_map['hardware']) &&
|
||||
!preg_match($rancid_map['hardware'], $device['hardware'])) { continue; }
|
||||
// New defs
|
||||
foreach ($os_maps[$device['os']] as $rancid_map) {
|
||||
// Need check hardware for map
|
||||
if (isset($rancid_map['hardware']) &&
|
||||
!preg_match($rancid_map['hardware'], $device['hardware'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Need check min os version
|
||||
if (isset($rancid_map['version_min']) &&
|
||||
version_compare($rancid_map['version_min'], $device['version'], '>')) { continue; }
|
||||
// Need check min os version
|
||||
if (isset($rancid_map['version_min']) &&
|
||||
version_compare($rancid_map['version_min'], $device['version'], '>')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Need check min rancid version
|
||||
if (isset($rancid_map['rancid_min']) &&
|
||||
version_compare(rtrim($rancid_map['rancid_min'], '.0'), $rancid_version, '>')) { continue; }
|
||||
// Need check min rancid version
|
||||
if (isset($rancid_map['rancid_min']) &&
|
||||
version_compare(trim_number($rancid_map['rancid_min']), $rancid_version, '>')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// All checks complete, write rancid entry and break loop
|
||||
echo($device['hostname'] . $delimiter . $rancid_map['name'] . $delimiter . $status . PHP_EOL);
|
||||
break;
|
||||
}
|
||||
// All checks complete, write rancid entry and break loop
|
||||
echo($device['hostname'] . $delimiter . $rancid_map['name'] . $delimiter . $rancid_status . PHP_EOL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -5,18 +5,20 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage scripts
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage scripts
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
chdir(dirname($argv[0]).'/..');
|
||||
chdir(dirname($argv[0]) . '/..');
|
||||
|
||||
$options = getopt("d");
|
||||
if (isset($options['d'])) { array_shift($argv); } // for compatibility
|
||||
if (isset($options['d'])) {
|
||||
array_shift($argv);
|
||||
} // for compatibility
|
||||
|
||||
include_once("includes/sql-config.inc.php");
|
||||
include_once("includes/observium.inc.php");
|
||||
|
||||
?>
|
||||
*** Targets ***
|
||||
@ -28,9 +30,8 @@ title = Network Latency Grapher
|
||||
remark = Welcome to Observium SmokePing
|
||||
<?php
|
||||
|
||||
if (is_array($config['smokeping']['slaves']))
|
||||
{
|
||||
echo('slaves = ' . implode(' ', $config['smokeping']['slaves']) . PHP_EOL);
|
||||
if (is_array($config['smokeping']['slaves'])) {
|
||||
echo('slaves = ' . implode(' ', $config['smokeping']['slaves']) . PHP_EOL);
|
||||
}
|
||||
|
||||
?>
|
||||
@ -40,10 +41,9 @@ menu = Observium
|
||||
|
||||
<?php
|
||||
|
||||
foreach (dbFetchRows("SELECT hostname FROM `devices` WHERE `ignore` = 0 AND `disabled` = 0 ORDER BY hostname") as $device)
|
||||
{
|
||||
echo("++ " . str_replace('.', $config['smokeping']['split_char'], $device['hostname']) . PHP_EOL);
|
||||
echo("host = " . $device['hostname'] . PHP_EOL . PHP_EOL);
|
||||
foreach (dbFetchRows("SELECT hostname FROM `devices` WHERE `ignore` = 0 AND `disabled` = 0 ORDER BY hostname") as $device) {
|
||||
echo("++ " . str_replace('.', $config['smokeping']['split_char'], $device['hostname']) . PHP_EOL);
|
||||
echo("host = " . $device['hostname'] . PHP_EOL . PHP_EOL);
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -1,171 +1,171 @@
|
||||
<?php
|
||||
|
||||
$language_data = array (
|
||||
$language_data = [
|
||||
|
||||
'LANG_NAME' => 'IOS',
|
||||
'COMMENT_SINGLE' => array(1 => '!'),
|
||||
'CASE_KEYWORDS' => GESHI_CAPS_LOWER,
|
||||
'OOLANG' => false,
|
||||
'NUMBERS' => GESHI_NUMBER_OCT_PREFIX | GESHI_NUMBER_HEX_PREFIX,
|
||||
'KEYWORDS' => array(
|
||||
1 => array(
|
||||
'no', 'shutdown'
|
||||
),
|
||||
# 2 => array(
|
||||
# 'router', 'interface', 'service', 'config-register', 'upgrade', 'version', 'hostname', 'boot-start-marker', 'boot', 'boot-end-marker', 'enable', 'aaa', 'clock', 'ip',
|
||||
# 'logging', 'access-list', 'route-map', 'snmp-server', 'mpls', 'speed', 'media-type', 'negotiation', 'timestamps', 'prefix-list', 'network', 'mask', 'unsuppress-map',
|
||||
# 'neighbor', 'remote-as', 'ebgp-multihop', 'update-source', 'description', 'peer-group', 'policy-map', 'class-map', 'class', 'match', 'access-group', 'bandwidth', 'username',
|
||||
# 'password', 'send-community', 'next-hop-self', 'route-reflector-client', 'ldp', 'discovery', 'advertise-labels', 'label', 'protocol', 'login', 'debug', 'log', 'duplex', 'router-id',
|
||||
# 'authentication', 'mode', 'maximum-paths', 'address-family', 'set', 'local-preference', 'community', 'trap-source', 'location', 'host', 'tacacs-server', 'session-id',
|
||||
# 'flow-export', 'destination', 'source', 'in', 'out', 'permit', 'deny', 'control-plane', 'line', 'con' ,'aux', 'vty', 'access-class', 'ntp', 'server', 'end', 'source-interface',
|
||||
# 'key', 'chain', 'key-string', 'redundancy', 'match-any', 'queue-limit', 'encapsulation', 'pvc', 'vbr-nrt', 'address', 'bundle-enable', 'atm', 'sonet', 'clns', 'route-cache',
|
||||
# 'default-information', 'redistribute', 'log-adjacency-changes', 'metric', 'spf-interval', 'prc-interval', 'lsp-refresh-interval', 'max-lsp-lifetime', 'set-overload-bit',
|
||||
# 'on-startup', 'wait-for-bgp', 'system', 'flash', 'timezone', 'subnet-zero', 'cef', 'flow-cache', 'timeout', 'active', 'domain', 'lookup', 'dhcp', 'use', 'vrf', 'hello', 'interval',
|
||||
# 'priority', 'ilmi-keepalive', 'buffered', 'debugging', 'fpd', 'secret', 'accounting', 'exec', 'group', 'local', 'recurring', 'source-route', 'call', 'rsvp-sync', 'scripting',
|
||||
# 'mtu', 'passive-interface', 'area' , 'distribute-list', 'metric-style', 'is-type', 'originate', 'activate', 'both', 'auto-summary', 'synchronization', 'aggregate-address', 'le', 'ge',
|
||||
# 'bgp-community', 'route', 'exit-address-family', 'standard', 'file', 'verify', 'domain-name', 'domain-lookup', 'route-target', 'export', 'import', 'map', 'rd', 'mfib', 'vtp', 'mls',
|
||||
# 'hardware-switching', 'replication-mode', 'ingress', 'flow', 'error', 'action', 'slb', 'purge', 'share-global', 'routing', 'traffic-eng', 'tunnels', 'propagate-ttl', 'switchport', 'vlan',
|
||||
# 'portfast', 'counters', 'max', 'age', 'ethernet', 'evc', 'uni', 'count', 'oam', 'lmi', 'gmt', 'netflow', 'pseudowire-class', 'spanning-tree', 'name', 'circuit-type'
|
||||
# ),
|
||||
# 3 => array(
|
||||
# 'isis', 'ospf', 'eigrp', 'rip', 'igrp', 'bgp', 'ipv4', 'unicast', 'multicast', 'ipv6', 'connected', 'static', 'subnets', 'tcl'
|
||||
# ),
|
||||
# 4 => array(
|
||||
# 'point-to-point', 'aal5snap', 'rj45', 'auto', 'full', 'half', 'precedence', 'percent', 'datetime', 'msec', 'locatime', 'summer-time', 'md5', 'wait-for-bgp', 'wide',
|
||||
# 'level-1', 'level-2', 'log-neighbor-changes', 'directed-request', 'password-encryption', 'common', 'origin-as', 'bgp-nexthop', 'random-detect', 'localtime', 'sso', 'stm-1',
|
||||
# 'dot1q', 'isl', 'new-model', 'always', 'summary-only', 'freeze', 'global', 'forwarded', 'access', 'trunk', 'edge', 'transparent'
|
||||
# ),
|
||||
),
|
||||
'LANG_NAME' => 'IOS',
|
||||
'COMMENT_SINGLE' => [1 => '!'],
|
||||
'CASE_KEYWORDS' => GESHI_CAPS_LOWER,
|
||||
'OOLANG' => FALSE,
|
||||
'NUMBERS' => GESHI_NUMBER_OCT_PREFIX | GESHI_NUMBER_HEX_PREFIX,
|
||||
'KEYWORDS' => [
|
||||
1 => [
|
||||
'no', 'shutdown'
|
||||
],
|
||||
# 2 => array(
|
||||
# 'router', 'interface', 'service', 'config-register', 'upgrade', 'version', 'hostname', 'boot-start-marker', 'boot', 'boot-end-marker', 'enable', 'aaa', 'clock', 'ip',
|
||||
# 'logging', 'access-list', 'route-map', 'snmp-server', 'mpls', 'speed', 'media-type', 'negotiation', 'timestamps', 'prefix-list', 'network', 'mask', 'unsuppress-map',
|
||||
# 'neighbor', 'remote-as', 'ebgp-multihop', 'update-source', 'description', 'peer-group', 'policy-map', 'class-map', 'class', 'match', 'access-group', 'bandwidth', 'username',
|
||||
# 'password', 'send-community', 'next-hop-self', 'route-reflector-client', 'ldp', 'discovery', 'advertise-labels', 'label', 'protocol', 'login', 'debug', 'log', 'duplex', 'router-id',
|
||||
# 'authentication', 'mode', 'maximum-paths', 'address-family', 'set', 'local-preference', 'community', 'trap-source', 'location', 'host', 'tacacs-server', 'session-id',
|
||||
# 'flow-export', 'destination', 'source', 'in', 'out', 'permit', 'deny', 'control-plane', 'line', 'con' ,'aux', 'vty', 'access-class', 'ntp', 'server', 'end', 'source-interface',
|
||||
# 'key', 'chain', 'key-string', 'redundancy', 'match-any', 'queue-limit', 'encapsulation', 'pvc', 'vbr-nrt', 'address', 'bundle-enable', 'atm', 'sonet', 'clns', 'route-cache',
|
||||
# 'default-information', 'redistribute', 'log-adjacency-changes', 'metric', 'spf-interval', 'prc-interval', 'lsp-refresh-interval', 'max-lsp-lifetime', 'set-overload-bit',
|
||||
# 'on-startup', 'wait-for-bgp', 'system', 'flash', 'timezone', 'subnet-zero', 'cef', 'flow-cache', 'timeout', 'active', 'domain', 'lookup', 'dhcp', 'use', 'vrf', 'hello', 'interval',
|
||||
# 'priority', 'ilmi-keepalive', 'buffered', 'debugging', 'fpd', 'secret', 'accounting', 'exec', 'group', 'local', 'recurring', 'source-route', 'call', 'rsvp-sync', 'scripting',
|
||||
# 'mtu', 'passive-interface', 'area' , 'distribute-list', 'metric-style', 'is-type', 'originate', 'activate', 'both', 'auto-summary', 'synchronization', 'aggregate-address', 'le', 'ge',
|
||||
# 'bgp-community', 'route', 'exit-address-family', 'standard', 'file', 'verify', 'domain-name', 'domain-lookup', 'route-target', 'export', 'import', 'map', 'rd', 'mfib', 'vtp', 'mls',
|
||||
# 'hardware-switching', 'replication-mode', 'ingress', 'flow', 'error', 'action', 'slb', 'purge', 'share-global', 'routing', 'traffic-eng', 'tunnels', 'propagate-ttl', 'switchport', 'vlan',
|
||||
# 'portfast', 'counters', 'max', 'age', 'ethernet', 'evc', 'uni', 'count', 'oam', 'lmi', 'gmt', 'netflow', 'pseudowire-class', 'spanning-tree', 'name', 'circuit-type'
|
||||
# ),
|
||||
# 3 => array(
|
||||
# 'isis', 'ospf', 'eigrp', 'rip', 'igrp', 'bgp', 'ipv4', 'unicast', 'multicast', 'ipv6', 'connected', 'static', 'subnets', 'tcl'
|
||||
# ),
|
||||
# 4 => array(
|
||||
# 'point-to-point', 'aal5snap', 'rj45', 'auto', 'full', 'half', 'precedence', 'percent', 'datetime', 'msec', 'locatime', 'summer-time', 'md5', 'wait-for-bgp', 'wide',
|
||||
# 'level-1', 'level-2', 'log-neighbor-changes', 'directed-request', 'password-encryption', 'common', 'origin-as', 'bgp-nexthop', 'random-detect', 'localtime', 'sso', 'stm-1',
|
||||
# 'dot1q', 'isl', 'new-model', 'always', 'summary-only', 'freeze', 'global', 'forwarded', 'access', 'trunk', 'edge', 'transparent'
|
||||
# ),
|
||||
],
|
||||
|
||||
'REGEXPS' => array (
|
||||
1 => array(
|
||||
GESHI_SEARCH => '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})',
|
||||
GESHI_REPLACE => '\\1',
|
||||
GESHI_BEFORE => '',
|
||||
),
|
||||
2 => array(
|
||||
GESHI_SEARCH => '(255\.\d{1,3}\.\d{1,3}\.\d{1,3})',
|
||||
GESHI_REPLACE => '\\1',
|
||||
GESHI_BEFORE => '',
|
||||
),
|
||||
3 => array(
|
||||
GESHI_SEARCH => '(source|interface|update-source|router-id) ([A-Za-z0-9\/\:\-\.]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
),
|
||||
4 => array(
|
||||
GESHI_SEARCH => '(neighbor) ([\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}]+|[a-zA-Z0-9\-\_]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
),
|
||||
5 => array(
|
||||
GESHI_SEARCH => '(distribute-map|access-group|policy-map|class-map\ match-any|ip\ access-list\ extended|match\ community|community-list\ standard|community-list\ expanded|ip\ access-list\ standard|router\ bgp|remote-as|key\ chain|service-policy\ input|service-policy\ output|class|login\ authentication|authentication\ key-chain|username|import\ map|export\ map|domain-name|hostname|route-map|access-class|ip\ vrf\ forwarding|ip\ vrf|vtp\ domain|name|pseudowire-class|pw-class|prefix-list|vrf) ([A-Za-z0-9\-\_\.]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
),
|
||||
6 => array(
|
||||
GESHI_SEARCH => '(password|key-string|key) ([0-9]) (.+)',
|
||||
GESHI_REPLACE => '\\2 \\3',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
),
|
||||
7 => array(
|
||||
GESHI_SEARCH => '(enable) ([a-z]+) ([0-9]) (.+)',
|
||||
GESHI_REPLACE => '\\3 \\4',
|
||||
GESHI_BEFORE => '\\1 \\2 ',
|
||||
),
|
||||
8 => array(
|
||||
GESHI_SEARCH => '(description|location|contact|remark) (.+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
),
|
||||
9 => array(
|
||||
GESHI_SEARCH => '([0-9\.\_\*]+\:[0-9\.\_\*]+)',
|
||||
GESHI_REPLACE => '\\1',
|
||||
),
|
||||
10 => array(
|
||||
GESHI_SEARCH => '(boot) ([a-z]+) (.+)',
|
||||
GESHI_REPLACE => '\\3',
|
||||
GESHI_BEFORE => '\\1 \\2 '
|
||||
),
|
||||
11 => array(
|
||||
GESHI_SEARCH => '(net) ([0-9a-z\.]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 '
|
||||
),
|
||||
12 => array(
|
||||
GESHI_SEARCH => '(access-list|RO|RW) ([0-9]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 '
|
||||
),
|
||||
13 => array(
|
||||
GESHI_SEARCH => '(vlan) ([0-9]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 '
|
||||
),
|
||||
14 => array(
|
||||
GESHI_SEARCH => '(encapsulation|speed|duplex|mtu|metric|media-type|negotiation|transport\ input|bgp-community|set\ as-path\ prepend|maximum-prefix|version|local-preference|continue|redistribute|cluster-id|vtp\ mode|label\ protocol|spanning-tree\ mode) (.+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 '
|
||||
),
|
||||
'REGEXPS' => [
|
||||
1 => [
|
||||
GESHI_SEARCH => '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})',
|
||||
GESHI_REPLACE => '\\1',
|
||||
GESHI_BEFORE => '',
|
||||
],
|
||||
2 => [
|
||||
GESHI_SEARCH => '(255\.\d{1,3}\.\d{1,3}\.\d{1,3})',
|
||||
GESHI_REPLACE => '\\1',
|
||||
GESHI_BEFORE => '',
|
||||
],
|
||||
3 => [
|
||||
GESHI_SEARCH => '(source|interface|update-source|router-id) ([A-Za-z0-9\/\:\-\.]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
],
|
||||
4 => [
|
||||
GESHI_SEARCH => '(neighbor) ([\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}]+|[a-zA-Z0-9\-\_]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
],
|
||||
5 => [
|
||||
GESHI_SEARCH => '(distribute-map|access-group|policy-map|class-map\ match-any|ip\ access-list\ extended|match\ community|community-list\ standard|community-list\ expanded|ip\ access-list\ standard|router\ bgp|remote-as|key\ chain|service-policy\ input|service-policy\ output|class|login\ authentication|authentication\ key-chain|username|import\ map|export\ map|domain-name|hostname|route-map|access-class|ip\ vrf\ forwarding|ip\ vrf|vtp\ domain|name|pseudowire-class|pw-class|prefix-list|vrf) ([A-Za-z0-9\-\_\.]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
],
|
||||
6 => [
|
||||
GESHI_SEARCH => '(password|key-string|key) ([0-9]) (.+)',
|
||||
GESHI_REPLACE => '\\2 \\3',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
],
|
||||
7 => [
|
||||
GESHI_SEARCH => '(enable) ([a-z]+) ([0-9]) (.+)',
|
||||
GESHI_REPLACE => '\\3 \\4',
|
||||
GESHI_BEFORE => '\\1 \\2 ',
|
||||
],
|
||||
8 => [
|
||||
GESHI_SEARCH => '(description|location|contact|remark) (.+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 ',
|
||||
],
|
||||
9 => [
|
||||
GESHI_SEARCH => '([0-9\.\_\*]+\:[0-9\.\_\*]+)',
|
||||
GESHI_REPLACE => '\\1',
|
||||
],
|
||||
10 => [
|
||||
GESHI_SEARCH => '(boot) ([a-z]+) (.+)',
|
||||
GESHI_REPLACE => '\\3',
|
||||
GESHI_BEFORE => '\\1 \\2 '
|
||||
],
|
||||
11 => [
|
||||
GESHI_SEARCH => '(net) ([0-9a-z\.]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 '
|
||||
],
|
||||
12 => [
|
||||
GESHI_SEARCH => '(access-list|RO|RW) ([0-9]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 '
|
||||
],
|
||||
13 => [
|
||||
GESHI_SEARCH => '(vlan) ([0-9]+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 '
|
||||
],
|
||||
14 => [
|
||||
GESHI_SEARCH => '(encapsulation|speed|duplex|mtu|metric|media-type|negotiation|transport\ input|bgp-community|set\ as-path\ prepend|maximum-prefix|version|local-preference|continue|redistribute|cluster-id|vtp\ mode|label\ protocol|spanning-tree\ mode) (.+)',
|
||||
GESHI_REPLACE => '\\2',
|
||||
GESHI_BEFORE => '\\1 '
|
||||
],
|
||||
|
||||
),
|
||||
],
|
||||
|
||||
'STYLES' => array(
|
||||
'REGEXPS' => array(
|
||||
0 => 'color: #ff0000;',
|
||||
1 => 'color: #0000cc;', # x.x.x.x
|
||||
2 => 'color: #000099; font-style: italic', # 255.x.x.x
|
||||
3 => 'color: #000000; font-weight: bold; font-style: italic;', # interface xxx
|
||||
4 => 'color: #ff0000;', # neighbor x.x.x.x
|
||||
5 => 'color: #000099;', # variable names
|
||||
6 => 'color: #cc0000;',
|
||||
7 => 'color: #cc0000;', # passwords
|
||||
8 => 'color: #555555;', # description
|
||||
9 => 'color: #990099;', # communities
|
||||
10 => 'color: #cc0000; font-style: italic;', # no/shut
|
||||
11 => 'color: #000099;', # net numbers
|
||||
12 => 'color: #000099;', # acls
|
||||
13 => 'color: #000099;', # acls
|
||||
14 => 'color: #990099;', # warnings
|
||||
),
|
||||
'KEYWORDS' => array(
|
||||
1 => 'color: #cc0000; font-weight: bold;', # no/shut
|
||||
2 => 'color: #000000;', # commands
|
||||
3 => 'color: #000000; font-weight: bold;', # proto/service
|
||||
4 => 'color: #000000;', # options
|
||||
5 => 'color: #ff0000;'
|
||||
),
|
||||
'COMMENTS' => array(
|
||||
1 => 'color: #808080; font-style: italic;'
|
||||
),
|
||||
'ESCAPE_CHAR' => array(
|
||||
0 => 'color: #000099; font-weight: bold;'
|
||||
),
|
||||
'BRACKETS' => array(
|
||||
0 => 'color: #66cc66;'
|
||||
),
|
||||
'STRINGS' => array(
|
||||
0 => 'color: #ff0000;'
|
||||
),
|
||||
'NUMBERS' => array(
|
||||
0 => 'color: #cc0000;'
|
||||
),
|
||||
'METHODS' => array(
|
||||
0 => 'color: #006600;'
|
||||
),
|
||||
'SYMBOLS' => array(
|
||||
0 => 'color: #66cc66;'
|
||||
),
|
||||
'SCRIPT' => array(
|
||||
0 => '',
|
||||
1 => '',
|
||||
2 => '',
|
||||
3 => ''
|
||||
)
|
||||
'STYLES' => [
|
||||
'REGEXPS' => [
|
||||
0 => 'color: #ff0000;',
|
||||
1 => 'color: #0000cc;', # x.x.x.x
|
||||
2 => 'color: #000099; font-style: italic', # 255.x.x.x
|
||||
3 => 'color: #000000; font-weight: bold; font-style: italic;', # interface xxx
|
||||
4 => 'color: #ff0000;', # neighbor x.x.x.x
|
||||
5 => 'color: #000099;', # variable names
|
||||
6 => 'color: #cc0000;',
|
||||
7 => 'color: #cc0000;', # passwords
|
||||
8 => 'color: #555555;', # description
|
||||
9 => 'color: #990099;', # communities
|
||||
10 => 'color: #cc0000; font-style: italic;', # no/shut
|
||||
11 => 'color: #000099;', # net numbers
|
||||
12 => 'color: #000099;', # acls
|
||||
13 => 'color: #000099;', # acls
|
||||
14 => 'color: #990099;', # warnings
|
||||
],
|
||||
'KEYWORDS' => [
|
||||
1 => 'color: #cc0000; font-weight: bold;', # no/shut
|
||||
2 => 'color: #000000;', # commands
|
||||
3 => 'color: #000000; font-weight: bold;', # proto/service
|
||||
4 => 'color: #000000;', # options
|
||||
5 => 'color: #ff0000;'
|
||||
],
|
||||
'COMMENTS' => [
|
||||
1 => 'color: #808080; font-style: italic;'
|
||||
],
|
||||
'ESCAPE_CHAR' => [
|
||||
0 => 'color: #000099; font-weight: bold;'
|
||||
],
|
||||
'BRACKETS' => [
|
||||
0 => 'color: #66cc66;'
|
||||
],
|
||||
'STRINGS' => [
|
||||
0 => 'color: #ff0000;'
|
||||
],
|
||||
'NUMBERS' => [
|
||||
0 => 'color: #cc0000;'
|
||||
],
|
||||
'METHODS' => [
|
||||
0 => 'color: #006600;'
|
||||
],
|
||||
'SYMBOLS' => [
|
||||
0 => 'color: #66cc66;'
|
||||
],
|
||||
'SCRIPT' => [
|
||||
0 => '',
|
||||
1 => '',
|
||||
2 => '',
|
||||
3 => ''
|
||||
]
|
||||
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
);
|
||||
];
|
||||
|
||||
?>
|
||||
|
188
scripts/ifAlias
Normal file → Executable file
188
scripts/ifAlias
Normal file → Executable file
@ -1,65 +1,129 @@
|
||||
#!/usr/bin/perl -w
|
||||
#!/bin/bash
|
||||
# -------------------------------------------------------------------------
|
||||
# Observium
|
||||
#
|
||||
# This file is part of Observium.
|
||||
#
|
||||
# @package observium
|
||||
# @subpackage scripts
|
||||
# @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2023 Observium Limited
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
## From Sascha Schaal
|
||||
# Add to snmpd.conf something like:
|
||||
# pass .1.3.6.1.2.1.31.1.1.1.18 /usr/local/bin/ifAlias
|
||||
BASE=".1.3.6.1.2.1.31.1.1.1.18" # IF-MIB::ifAlias
|
||||
REQ="$1" # -g get, -n getnext, -s set
|
||||
OID="$2" # Requested OID
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $REQ = $ARGV[0];
|
||||
my $ROID = $ARGV[1];
|
||||
my $Base = ".1.3.6.1.2.1.31.1.1.1.18";
|
||||
my @iface_list = `ip l | grep mtu`;
|
||||
my $index = 0;
|
||||
my %Table;
|
||||
my $p_oid;
|
||||
my $p_type = "STRING";
|
||||
my $p_desc;
|
||||
|
||||
if ($ROID eq $Base){
|
||||
$index = 0;
|
||||
}
|
||||
else{
|
||||
my @split = split("$Base.",$ROID);
|
||||
$index = $split[1];
|
||||
}
|
||||
foreach my $row (@iface_list){
|
||||
my @split = split(": ", $row);
|
||||
my $desc = `grep "^# $split[1]:" /etc/network/interfaces|sed s/^\\#\\ $split[1]:\\ //`;
|
||||
my ($key, $value) = ("$Base.$split[0]",$desc);
|
||||
$Table{$key} = $value;
|
||||
}
|
||||
if ($REQ eq "-g"){
|
||||
if ($index == 0){
|
||||
exit 0;
|
||||
}
|
||||
else{
|
||||
if( exists($Table{$ROID} ) ) {
|
||||
$p_oid = $ROID;
|
||||
$p_desc = $Table{$ROID};
|
||||
}
|
||||
else{
|
||||
print "noSuchName\n";
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
elsif ($REQ eq "-n"){
|
||||
for ($index, $index <= keys %Table,$index++){
|
||||
if( exists($Table{"$Base.$index"} ) ) {
|
||||
$p_oid = "$Base.$index";
|
||||
$p_desc = $Table{"$Base.$index"};
|
||||
}
|
||||
else{
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
exit 0;
|
||||
}
|
||||
if [ "$REQ" = "-s" ]; then
|
||||
#echo $* >> /tmp/passtest.log
|
||||
exit 0
|
||||
fi
|
||||
|
||||
print "$p_oid\n";
|
||||
print "$p_type\n";
|
||||
print "$p_desc";
|
||||
exit 0;
|
||||
#1 lo
|
||||
#2 eth0
|
||||
#3 eth1
|
||||
LINKS="$(ip link | awk -F ": " '/^[0-9]+:/ {print $1 " " $2}')"
|
||||
#echo "$LINKS"
|
||||
|
||||
_starts_with() {
|
||||
local _str="$1"
|
||||
local _sub="$2"
|
||||
echo "$_str" | grep "^$_sub" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
ifindex() {
|
||||
local IF="${OID#"${BASE}".}"
|
||||
local line
|
||||
|
||||
if [ "$REQ" = "-g" ]; then
|
||||
# GET request
|
||||
case $IF in ''|*[!0-9]*) return 1;; esac; # not int number
|
||||
echo "$IF"
|
||||
return 0
|
||||
else
|
||||
# GETNEXT request
|
||||
if [ "$IF" = "$BASE" ] || [ "$IF" = "" ]; then
|
||||
# first interface index
|
||||
echo "${LINKS%% *}"
|
||||
return 0
|
||||
else
|
||||
local next=false
|
||||
echo "$LINKS" | while read line; do
|
||||
if $next; then echo "${line%% *}"; return 0; fi
|
||||
if _starts_with "$line" "$IF "; then next=true; fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
ifname() {
|
||||
local IF="$1"
|
||||
local line
|
||||
|
||||
echo "$LINKS" | while read line; do
|
||||
if _starts_with "$line" "$IF "; then echo "${line##* }"; fi
|
||||
done
|
||||
}
|
||||
|
||||
ifalias_sys() {
|
||||
#local IFNAME="$1"
|
||||
local sys_file="/sys/class/net/${1}/ifalias"
|
||||
|
||||
# 15: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
|
||||
# link/none
|
||||
# alias Wireguard VPN
|
||||
if [ -f "$sys_file" ]; then
|
||||
cat "$sys_file"
|
||||
fi
|
||||
}
|
||||
|
||||
ifalias_frr() {
|
||||
local IFNAME="$1"
|
||||
|
||||
# FRR
|
||||
if [ -x "/bin/vtysh" ]; then
|
||||
# prefer vtysh
|
||||
vtysh -c "show interface description" 2>&1 /dev/null | grep -si -m1 "^$IFNAME " | awk '{for (i=4; i<NF; i++) printf $i " "; print $NF}'
|
||||
elif [ -f "/etc/frr/frr.conf" ]; then
|
||||
awk "/^interface ${IFNAME}/,/^exit/" /etc/frr/frr.conf | awk "/^ description /" | sed "s/^\\ description\\ //"
|
||||
fi
|
||||
}
|
||||
|
||||
ifalias_conf() {
|
||||
local IFNAME="$1"
|
||||
|
||||
if [ -f "/etc/network/interfaces.d/$IFNAME" ]; then
|
||||
CFG="/etc/network/interfaces.d/$IFNAME"
|
||||
elif [ -f "/etc/network/interfaces" ]; then
|
||||
CFG="/etc/network/interfaces"
|
||||
elif [ -f "/etc/sysconfig/network-scripts/ifcfg-$IFNAME" ]; then
|
||||
CFG="/etc/sysconfig/network-scripts/ifcfg-$IFNAME"
|
||||
elif [ -f "/etc/conf.d/net-conf-$IFNAME" ]; then
|
||||
CFG="/etc/conf.d/net-conf-$IFNAME"
|
||||
elif [ -f "/etc/conf.d/net" ]; then
|
||||
CFG="/etc/conf.d/net"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
grep -si -m1 "^# $IFNAME:" $CFG | sed "s/^# $IFNAME: //i"
|
||||
}
|
||||
|
||||
IFINDEX="$(ifindex)"
|
||||
[ "$IFINDEX" ] || exit 1 # incorrect ifindex
|
||||
|
||||
IFNAME="$(ifname "$IFINDEX")"
|
||||
IFALIAS="$(ifalias_frr "$IFNAME")"
|
||||
# get ifalias from config files
|
||||
[ "$IFALIAS" ] || IFALIAS="$(ifalias_conf "$IFNAME")"
|
||||
# if not found in config, try common link alias
|
||||
# sudo ip link set <interface> alias "<ifalias>"
|
||||
[ "$IFALIAS" ] || IFALIAS="$(ifalias_sys "$IFNAME")"
|
||||
|
||||
echo "${BASE}.${IFINDEX}"
|
||||
echo "string"
|
||||
echo "$IFALIAS"
|
||||
|
||||
exit 0
|
173
scripts/ifAlias.py
Executable file
173
scripts/ifAlias.py
Executable file
@ -0,0 +1,173 @@
|
||||
#!/usr/bin/python -u
|
||||
# -------------------------------------------------------------------------
|
||||
# Observium
|
||||
#
|
||||
# This file is part of Observium.
|
||||
#
|
||||
# @package observium
|
||||
# @subpackage scripts
|
||||
# @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2023 Observium Limited
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
# Add to snmpd.conf something like:
|
||||
# pass_persist .1.3.6.1.2.1.31.1.1.1.18 /usr/local/bin/ifAlias.py
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
try:
|
||||
import snmp_passpersist as snmp
|
||||
except ImportError:
|
||||
print("ERROR: missing python module: snmp_passpersist")
|
||||
print("Install: sudo pip install snmp_passpersist")
|
||||
sys.exit(2)
|
||||
|
||||
# General stuff
|
||||
UPDATE = 120 # refresh every 120 sec
|
||||
MAX_RETRY = 10 # Number of successive retry in case of error
|
||||
OID_BASE = ".1.3.6.1.2.1.31.1.1.1.18" # IF-MIB::ifAlias
|
||||
|
||||
# Globals vars
|
||||
pp = None
|
||||
cache = {'frr': True} # exist FRR or not
|
||||
|
||||
|
||||
def get_links():
|
||||
"""Get dict of system interfaces"""
|
||||
links = {}
|
||||
out = subprocess.run(['ip', 'link'], stdout=subprocess.PIPE)
|
||||
for line in out.stdout.decode('utf-8').splitlines():
|
||||
match = re.match(r'^(\d+):\s+(\w\S*?): ', line)
|
||||
if match:
|
||||
links[int(match.group(1))] = match.group(2)
|
||||
# print(links)
|
||||
return links
|
||||
|
||||
|
||||
def ifalias_sys(ifname):
|
||||
"""Get ifalias from sys alias"""
|
||||
sys_file = '/sys/class/net/' + ifname + '/ifalias'
|
||||
if os.path.isfile(sys_file):
|
||||
sys_net = open(sys_file, "r")
|
||||
ifalias = sys_net.read()
|
||||
sys_net.close()
|
||||
|
||||
return ifalias
|
||||
|
||||
return ''
|
||||
|
||||
|
||||
def ifalias_frr(ifname):
|
||||
"""Get ifalias from FRR config files or vtysh"""
|
||||
global cache
|
||||
|
||||
if not cache['frr']:
|
||||
return ''
|
||||
|
||||
if os.path.isfile('/bin/vtysh') and os.access('/bin/vtysh', os.X_OK):
|
||||
# prefer vtysh
|
||||
vty_pattern = r'^%s\s+\w+\s+\w+\s*(\S.*)?$' % re.escape(ifname)
|
||||
out = subprocess.run(['vtysh', '-c', 'show interface description'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
||||
for line in out.stdout.decode('utf-8').splitlines():
|
||||
match = re.match(vty_pattern, line, re.IGNORECASE)
|
||||
if match:
|
||||
return str(match.group(1))
|
||||
elif os.path.isfile('/etc/frr/frr.conf'):
|
||||
out = subprocess.run(['awk', '/^interface ' + ifname + '/,/^exit/', '/etc/frr/frr.conf'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
||||
for line in out.stdout.decode('utf-8').splitlines():
|
||||
match = re.match(r'^ description +(\S.*)?', line)
|
||||
if match:
|
||||
return str(match.group(1))
|
||||
|
||||
cache['frr'] = False # set not exist FRR
|
||||
return ''
|
||||
|
||||
|
||||
def ifalias_conf(ifname):
|
||||
"""Get ifalias from interface config files"""
|
||||
global cache
|
||||
|
||||
if os.path.isfile('/etc/network/interfaces.d/' + ifname):
|
||||
cfg = '/etc/network/interfaces.d/' + ifname
|
||||
elif os.path.isfile('/etc/network/interfaces'):
|
||||
cfg = '/etc/network/interfaces'
|
||||
elif os.path.isfile('/etc/sysconfig/network-scripts/ifcfg-' + ifname):
|
||||
cfg = '/etc/sysconfig/network-scripts/ifcfg-' + ifname
|
||||
elif os.path.isfile('/etc/conf.d/net-conf-' + ifname):
|
||||
cfg = '/etc/conf.d/net-conf-' + ifname
|
||||
elif os.path.isfile('/etc/conf.d/net'):
|
||||
cfg = '/etc/conf.d/net'
|
||||
else:
|
||||
return ''
|
||||
|
||||
conf_pattern = r'^\s*\#\s+%s:\s+(.+)' % re.escape(ifname)
|
||||
conf = open(cfg, "r")
|
||||
for line in conf.readlines():
|
||||
match = re.match(conf_pattern, line, re.IGNORECASE)
|
||||
if match:
|
||||
ifalias = match.group(1)
|
||||
conf.close()
|
||||
return ifalias
|
||||
|
||||
conf.close()
|
||||
return ''
|
||||
|
||||
|
||||
def update_ifalias():
|
||||
"""Update snmp ifAlias"""
|
||||
global pp
|
||||
|
||||
for ifindex, ifname in get_links().items():
|
||||
ifalias = ifalias_frr(ifname)
|
||||
if not ifalias:
|
||||
ifalias = ifalias_conf(ifname)
|
||||
if not ifalias:
|
||||
ifalias = ifalias_sys(ifname)
|
||||
|
||||
# print(ifindex, ifname, ifalias)
|
||||
pp.add_str(str(ifindex), ifalias)
|
||||
|
||||
|
||||
# update_ifalias()
|
||||
# sys.exit(0)
|
||||
|
||||
|
||||
def main():
|
||||
"""Feed the IF-MIB::ifAlias Oid and start listening for snmp passpersist"""
|
||||
global pp
|
||||
|
||||
retry_timestamp = int(time.time())
|
||||
retry_counter = MAX_RETRY
|
||||
while retry_counter > 0:
|
||||
try:
|
||||
# Load helpers
|
||||
pp = snmp.PassPersist(OID_BASE)
|
||||
|
||||
pp.start(update_ifalias, UPDATE) # Shouldn't return (except if updater thread has died)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("Exiting on user request.")
|
||||
sys.exit(0)
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
# Errors frequency detection
|
||||
now = int(time.time())
|
||||
if (now - 3600) > retry_timestamp: # If the previous error is older than 1H
|
||||
retry_counter = MAX_RETRY # Reset the counter
|
||||
else:
|
||||
retry_counter -= 1 # Else countdown
|
||||
retry_timestamp = now
|
||||
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# EOF
|
@ -1,5 +1,11 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
# WARNING. Use better variant of persist ifAlias script from this dir.
|
||||
# - python, need install:
|
||||
# sudo pip install snmp_passpersist
|
||||
# - add to snmpd.conf
|
||||
# pass_persist .1.3.6.1.2.1.31.1.1.1.18 /usr/local/bin/ifAlias.py
|
||||
|
||||
# SNMP::Extension::PassPersist is required.
|
||||
# This is in the package libsnmp-extension-passpersist-perl on Debian and Ubuntu
|
||||
# Usage : Copy the script to /usr/bin/ifAlias_persist and add to /etc/snmp/snmpd.conf
|
||||
@ -22,14 +28,24 @@ $extsnmp->run;
|
||||
sub update_tree {
|
||||
my ($self) = @_;
|
||||
|
||||
|
||||
if (-f "/etc/frr/frr.conf") {
|
||||
my $mode = "frr";
|
||||
} else {
|
||||
my $mode = "debian";
|
||||
}
|
||||
my $Base = ".1.3.6.1.2.1.31.1.1.1.18";
|
||||
my @iface_list = `ip l | grep mtu`;
|
||||
my $type = "string";
|
||||
|
||||
foreach my $row (@iface_list){
|
||||
foreach my $row (@iface_list) {
|
||||
my @split = split(": ", $row);
|
||||
my $desc = `grep "^# $split[1]:" /etc/network/interfaces|sed s/^\\#\\ $split[1]:\\ //`;
|
||||
if ($mode == "frr") {
|
||||
# see: https://jira.observium.org/browse/OBS-4036
|
||||
# my $desc = `grep -A 1 "^interface $split[1]" /etc/frr/frr.conf | tail -1 |sed "s/^\\ description\\ //"`;
|
||||
my $desc = `awk "/^interface $split[1]/,/^exit/" /etc/frr/frr.conf | awk "/^ description /" | sed "s/^\\ description\\ //"`;
|
||||
} else {
|
||||
my $desc = `grep "^# $split[1]:" /etc/network/interfaces | sed s/^\\#\\ $split[1]:\\ //`;
|
||||
}
|
||||
chomp($desc);
|
||||
my ($key, $value) = ("$Base.$split[0]",$desc);
|
||||
$self->add_oid_entry($key,$type,$value);
|
||||
@ -37,6 +53,3 @@ sub update_tree {
|
||||
# $extsnmp->dump_oid_tree();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,42 +5,40 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage scripts
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage scripts
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
chdir(dirname($argv[0]).'/..');
|
||||
chdir(dirname($argv[0]) . '/..');
|
||||
|
||||
$options = getopt("dh:");
|
||||
|
||||
include_once("includes/sql-config.inc.php");
|
||||
include_once("includes/observium.inc.php");
|
||||
|
||||
if (empty($options['h']))
|
||||
{
|
||||
print "Usage: scripts/rename-port-rrdfile.php -h <device_id|hostname>\n\n";
|
||||
exit(1);
|
||||
if (empty($options['h'])) {
|
||||
print "Usage: scripts/rename-port-rrdfile.php -h <device_id|hostname>\n\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (is_numeric($options['h']))
|
||||
{
|
||||
$where = "`device_id` = ?";
|
||||
if (is_numeric($options['h'])) {
|
||||
$where = "`device_id` = ?";
|
||||
} else {
|
||||
$where = "`hostname` = ?";
|
||||
$where = "`hostname` = ?";
|
||||
}
|
||||
|
||||
$device = dbFetchRow("SELECT * FROM devices WHERE " . $where, array($options['h']));
|
||||
$device = dbFetchRow("SELECT * FROM devices WHERE " . $where, [$options['h']]);
|
||||
|
||||
$ports = dbFetchRows("SELECT * FROM ports WHERE `device_id` = ?", array($device['device_id']));
|
||||
$ports = dbFetchRows("SELECT * FROM ports WHERE `device_id` = ?", [$device['device_id']]);
|
||||
|
||||
foreach ($ports as $port) {
|
||||
$old_rrdfile = trim($config['rrd_dir'])."/".trim($device['hostname'])."/port-".$port['ifIndex'].".rrd";
|
||||
$new_rrdfile = get_port_rrdfilename($device, $port);
|
||||
$old_rrdfile = trim($config['rrd_dir']) . "/" . trim($device['hostname']) . "/port-" . $port['ifIndex'] . ".rrd";
|
||||
$new_rrdfile = get_port_rrdfilename($device, $port);
|
||||
|
||||
printf("%s -> %s\n", $old_rrdfile, $new_rrdfile);
|
||||
printf("%s -> %s\n", $old_rrdfile, $new_rrdfile);
|
||||
|
||||
rename($old_rrdfile, $new_rrdfile);
|
||||
rename($old_rrdfile, $new_rrdfile);
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
131
scripts/snmpdump.php
Executable file
131
scripts/snmpdump.php
Executable file
@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
chdir(dirname($argv[0]));
|
||||
|
||||
// Get options before definitions!
|
||||
$options = getopt("h:f:o:cdqV", [], $opt_index);
|
||||
|
||||
include("../includes/observium.inc.php");
|
||||
|
||||
$cli = TRUE;
|
||||
|
||||
// get_versions();
|
||||
|
||||
if (isset($options['V'])) {
|
||||
// Print a current version and exit
|
||||
print_message(OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION);
|
||||
if (is_array($options['V'])) {
|
||||
print_versions();
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$snmpdump_start = utime();
|
||||
|
||||
if (isset($options['h'])) {
|
||||
if (is_intnum($options['h'])) {
|
||||
$device = device_by_id_cache($options['h']);
|
||||
//print_vars($device);
|
||||
} elseif (is_valid_hostname($options['h'])) {
|
||||
$device = device_by_name($options['h']);
|
||||
|
||||
if (!$device && $add = array_slice($argv, $opt_index)) {
|
||||
if (get_ip_version($options['h']) || is_domain_resolves($options['h'])) {
|
||||
array_unshift($add, $options['h']);
|
||||
|
||||
if ($snmp = get_device_snmp_argv($add, $snmp_options)) {
|
||||
//print_vars($snmp);
|
||||
if ($snmp['snmp_version'] === 'v3') {
|
||||
$snmp_options = array_merge(array_shift($snmp['snmp_v3_auth']), (array)$snmp_options);
|
||||
$device = build_initial_device_array($options['h'], NULL, $snmp['snmp_version'], $snmp['snmp_port'], $snmp['snmp_transport'], (array)$snmp_options);
|
||||
} else {
|
||||
$device = build_initial_device_array($options['h'], array_shift($snmp['snmp_community']), $snmp['snmp_version'], $snmp['snmp_port'], $snmp['snmp_transport'], (array)$snmp_options);
|
||||
}
|
||||
//print_vars($device);
|
||||
}
|
||||
//print_vars($opt_index);
|
||||
// Use same way for parse snmp auth as in add_device
|
||||
// SNMPv1/2c: add_device.php <hostname> [community] [v1|v2c] [port] [udp|udp6|tcp|tcp6] [context]
|
||||
// SNMPv3 : Defaults : add_device.php <hostname> any v3 [user] [port] [udp|udp6|tcp|tcp6] [context]
|
||||
// No Auth, No Priv : add_device.php <hostname> nanp v3 [user] [port] [udp|udp6|tcp|tcp6] [context]
|
||||
// Auth, No Priv : add_device.php <hostname> anp v3 <user> <password> [md5|sha|sha-224|sha-256|sha-384|sha-512] [port] [udp|udp6|tcp|tcp6] [context]
|
||||
// Auth, Priv : add_device.php <hostname> ap v3 <user> <password> <enckey> [md5|sha|sha-224|sha-256|sha-384|sha-512] [des|aes|aes-192|aes-192-c|aes-256|aes-256-c] [port] [udp|udp6|tcp|tcp6] [context]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$device) {
|
||||
print_error("Unknown device '{$options['h']}'.");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
// Unknown device (need pass own snmp auth)
|
||||
$device = [];
|
||||
}
|
||||
|
||||
if (!$device) {
|
||||
print_message("%n
|
||||
USAGE:
|
||||
$scriptname [-cqdV] -h device [-f filename]
|
||||
|
||||
EXAMPLE:
|
||||
./scripts/snmpdump.php -c -h <device> Show snmpwalk commands for make snmpdump specific device (exist in db)
|
||||
./scripts/snmpdump.php -h <device> Make snmpdump for specific device (exist in db) to file <hostname>.snmpwalk
|
||||
|
||||
./scripts/snmpdump.php -h <hostname> <community> Make snmpdump for specific hostname with v2 community to file <hostname>.snmpwalk
|
||||
Can use snmp v1/2c/3 auth params same as for ./add_device.php
|
||||
|
||||
OPTIONS:
|
||||
-h <device id> | <device hostname> Device hostname or id (required).
|
||||
-f Filename for store snmpdump (default: <hostname>.snmpwalk).
|
||||
For write to stdout use -f stdout
|
||||
-c Show snmpwalk commands for self run.
|
||||
-o Start Numeric Oid (default: .)
|
||||
-q Quiet output.
|
||||
-V Show observium version and exit.
|
||||
-VV Show observium and used programs versions and exit.
|
||||
|
||||
DEBUGGING OPTIONS:
|
||||
-d Enable debugging output.
|
||||
-dd More verbose debugging output.
|
||||
|
||||
%rInvalid arguments!%n", 'color', FALSE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$oid = $options['o'] ?? NULL;
|
||||
|
||||
if (cli_is_piped()) {
|
||||
$options['f'] = 'stdout';
|
||||
} elseif (isset($options['c'])) {
|
||||
// show snmpwalk commands
|
||||
snmp_dump($device, 'cmd', $oid);
|
||||
exit;
|
||||
} elseif (!isset($options['f'])) {
|
||||
$options['f'] = $device['hostname'] . '.snmpwalk';
|
||||
if (!is_writable(dirname($options['f']))) {
|
||||
$options['f'] = $config['temp_dir'] . '/' . $options['f'];
|
||||
}
|
||||
}
|
||||
|
||||
if (strtolower($options['f']) !== 'stdout') {
|
||||
if ($filename = snmp_dump($device, $options['f'], $oid)) {
|
||||
print_success("SNMP dump completed to file:\n $filename");
|
||||
}
|
||||
} else {
|
||||
// Just snmpwalk to stdout
|
||||
snmp_dump($device, NULL, $oid);
|
||||
}
|
||||
|
||||
// EOF
|
@ -9,7 +9,7 @@
|
||||
@package observium
|
||||
@subpackage definitions
|
||||
@author Mike Stupalov <mike@observium.org>
|
||||
@copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2018 Observium Limited
|
||||
@copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2023 Observium Limited
|
||||
|
||||
"""
|
||||
|
||||
@ -156,7 +156,7 @@ head = """<?php
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage definitions
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2018 Observium Limited
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2023 Observium Limited
|
||||
*
|
||||
*/
|
||||
|
||||
|
13
scripts/systemd/observium_agent.service
Normal file
13
scripts/systemd/observium_agent.service
Normal file
@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=Observium Agent Service
|
||||
After=network.target observium_agent.socket
|
||||
Requires=observium_agent.socket
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
# Note the - to make systemd ignore the exit code
|
||||
ExecStart=-/usr/bin/observium_agent
|
||||
# This is the part that makes it work like inetd
|
||||
StandardOutput=socket
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
10
scripts/systemd/observium_agent.socket
Normal file
10
scripts/systemd/observium_agent.socket
Normal file
@ -0,0 +1,10 @@
|
||||
[Install]
|
||||
WantedBy = sockets.target
|
||||
[Unit]
|
||||
Description=Observium Agent Socket
|
||||
PartOf=observium_agent.service
|
||||
[Socket]
|
||||
ListenStream=36602
|
||||
Accept=yes
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
201
scripts/wmic
Executable file
201
scripts/wmic
Executable file
@ -0,0 +1,201 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 2015 David Lundgren
|
||||
#
|
||||
# Python WMI Client
|
||||
#
|
||||
# Can be used in place of wmic when using check_wmi_plus.pl with Nagios.
|
||||
#
|
||||
# @author David Lundgren (@drlundgren)
|
||||
#
|
||||
# https://github.com/ProjectPatatoe/py-wmi-client/
|
||||
#
|
||||
# need additional packages:
|
||||
# sudo pip3 install natsort
|
||||
# sudo pip3 install impacket
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
import configparser
|
||||
|
||||
from natsort import natsorted, ns
|
||||
from impacket.dcerpc.v5.dtypes import NULL
|
||||
from impacket.dcerpc.v5.dcom import wmi
|
||||
from impacket.dcerpc.v5.dcomrt import DCOMConnection
|
||||
|
||||
APP_VERSION = '0.1.0'
|
||||
|
||||
|
||||
class WmiClient(object):
|
||||
"""WMI Client"""
|
||||
|
||||
def __init__(self, auth, host):
|
||||
"""
|
||||
|
||||
:param auth:
|
||||
:param host:
|
||||
"""
|
||||
self.auth = auth
|
||||
self.host = host
|
||||
|
||||
def get_language(self, lang):
|
||||
"""
|
||||
Retrieve the language passed in from int to string
|
||||
|
||||
:param lang: string
|
||||
:return:
|
||||
"""
|
||||
if lang == 552:
|
||||
return 'en-US'
|
||||
return '??-??'
|
||||
|
||||
def format_value(self, value, cimtype, type):
|
||||
"""
|
||||
Formats the value based on the cimtype and type
|
||||
|
||||
:param value:
|
||||
:param cimtype: string
|
||||
:param type: int
|
||||
:return:
|
||||
"""
|
||||
if cimtype == 'string':
|
||||
if value == 0:
|
||||
return '(null)'
|
||||
else:
|
||||
return str(value).strip()
|
||||
elif cimtype == 'boolean': # boolean
|
||||
if value == 'True':
|
||||
return 'True'
|
||||
else:
|
||||
return 'False'
|
||||
elif value is None:
|
||||
if cimtype == 'uint32' or cimtype == 'uint64':
|
||||
return '0'
|
||||
else:
|
||||
return ('%s' % value).strip()
|
||||
|
||||
def print_results(self, queryObject, delimiter):
|
||||
"""
|
||||
Prints the results in the classObject as wmic.c would
|
||||
|
||||
:param queryObject: IEnumWbemClassObject
|
||||
:param delimiter: string
|
||||
:return:
|
||||
"""
|
||||
|
||||
while True:
|
||||
try:
|
||||
classObject = queryObject.Next(0xffffffff, 1)[0]
|
||||
print('CLASS: %s' % classObject.getClassName())
|
||||
record = classObject.getProperties()
|
||||
keys = []
|
||||
for name in record:
|
||||
keys.append(name.strip())
|
||||
keys = natsorted(keys, alg=ns.IGNORECASE)
|
||||
print(delimiter.join(keys))
|
||||
tmp = []
|
||||
for key in keys:
|
||||
if key == 'MUILanguages':
|
||||
vals = []
|
||||
for v in record[key]['value']:
|
||||
vals.append(self.get_language(v))
|
||||
record[key]['value'] = vals
|
||||
|
||||
if isinstance(record[key]['value'], list):
|
||||
values = []
|
||||
for v in record[key]['value']:
|
||||
values.append(
|
||||
self.format_value(v, record[key]['qualifiers']['CIMTYPE'], record[key]['type']))
|
||||
tmp.append('(%s)' % ','.join(values))
|
||||
else:
|
||||
tmp.append('%s' % self.format_value(record[key]['value'], record[key]['qualifiers']['CIMTYPE'],
|
||||
record[key]['type']))
|
||||
print(delimiter.join(tmp))
|
||||
except Exception as e:
|
||||
if e.get_error_code() != wmi.WBEMSTATUS.WBEM_S_FALSE:
|
||||
raise
|
||||
else:
|
||||
break
|
||||
|
||||
def query_and_print(self, wql, **kwargs):
|
||||
"""
|
||||
Querys and prints the results
|
||||
|
||||
:param wql:
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
namespace = '//./root/cimv2'
|
||||
delimiter = '|'
|
||||
conn = None
|
||||
classObject = None
|
||||
wmiService = None
|
||||
wmiLogin = None
|
||||
|
||||
if 'namespace' in kwargs:
|
||||
namespace = kwargs['namespace']
|
||||
if 'delimiter' in kwargs:
|
||||
delimiter = kwargs['delimiter']
|
||||
|
||||
try:
|
||||
conn = DCOMConnection(self.host, self.auth['username'], self.auth['password'], self.auth['domain'], '', '',
|
||||
None, oxidResolver=True, doKerberos=False)
|
||||
wmiInterface = conn.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login, wmi.IID_IWbemLevel1Login)
|
||||
wmiLogin = wmi.IWbemLevel1Login(wmiInterface)
|
||||
wmiService = wmiLogin.NTLMLogin(namespace, NULL, NULL)
|
||||
wmiLogin.RemRelease()
|
||||
|
||||
queryObject = wmiService.ExecQuery(wql.strip('\n'),
|
||||
wmi.WBEM_FLAG_RETURN_IMMEDIATELY | wmi.WBEM_FLAG_ENSURE_LOCATABLE)
|
||||
self.print_results(queryObject, delimiter)
|
||||
queryObject.RemRelease()
|
||||
|
||||
wmiService.RemRelease()
|
||||
conn.disconnect()
|
||||
except Exception as e:
|
||||
if classObject is not None:
|
||||
classObject.RemRelease()
|
||||
if wmiLogin is not None:
|
||||
wmiLogin.RemRelease()
|
||||
if wmiService is not None:
|
||||
wmiService.RemRelease()
|
||||
if conn is not None:
|
||||
conn.disconnect()
|
||||
raise Exception("Could not connect to %s: %s" % (self.host, str(e)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description="WMI client")
|
||||
parser.add_argument('-U', '--user', dest='user', help="[DOMAIN\]USERNAME[%%PASSWORD]")
|
||||
parser.add_argument('-A', '--authentication-file', dest='authfile', help="Authentication file")
|
||||
parser.add_argument('--delimiter', default='|', help="delimiter, default: |")
|
||||
parser.add_argument('--namespace', default='//./root/cimv2', help='namespace name (default //./root/cimv2)')
|
||||
parser.add_argument('host', metavar="//host")
|
||||
parser.add_argument('wql', metavar="query")
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
auth = {
|
||||
'username': '',
|
||||
'password': '',
|
||||
'domain': ''
|
||||
}
|
||||
if options.authfile is not None:
|
||||
authfile = '[root]\n' + open(options.authfile, 'r').read()
|
||||
config = configparser.ConfigParser()
|
||||
config.read_string(authfile)
|
||||
auth['domain'] = config.get('root', 'domain', fallback='WORKGROUP')
|
||||
auth['username'] = config.get('root', 'username')
|
||||
auth['password'] = config.get('root', 'password')
|
||||
elif options.user is not None:
|
||||
auth['domain'], auth['username'], auth['password'] = re.compile(
|
||||
'(?:(?:([^/\\\\%]*)[/\\\\])?([^%]*))(?:%(.*))?').match(options.user).groups('')
|
||||
else:
|
||||
print("Missing user information")
|
||||
sys.exit(1)
|
||||
|
||||
if auth['domain'] == '':
|
||||
auth['domain'] = 'WORKGROUP'
|
||||
|
||||
WmiClient(auth, options.host[2:]).query_and_print(options.wql, namespace=options.namespace,
|
||||
delimiter=options.delimiter)
|
Reference in New Issue
Block a user