mirror of
https://github.com/librenms/librenms-agent.git
synced 2024-05-09 09:54:52 +00:00
SNMP extend scripts from the main repo
This commit is contained in:
89
snmp/apache-stats
Executable file
89
snmp/apache-stats
Executable file
@@ -0,0 +1,89 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
# Original python script Copyright (C) 2009 Glen Pitt-Pladdy
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
use LWP::Simple;
|
||||||
|
|
||||||
|
$CACHETIME = 30;
|
||||||
|
$CACHEFILE = '/tmp/snmp-cache-apache';
|
||||||
|
|
||||||
|
# check for cache file newer CACHETIME seconds ago
|
||||||
|
if ( -f $CACHEFILE && time - (stat( $CACHEFILE ))[9] < $CACHETIME) {
|
||||||
|
# use cached data
|
||||||
|
#print "Using cached data from file $CACHEFILE.\n";
|
||||||
|
open (INFILE, "<$CACHEFILE" )
|
||||||
|
or die "File open failure: $CACHEFILE\n";
|
||||||
|
@data = <INFILE>;
|
||||||
|
close INFILE;
|
||||||
|
} else {
|
||||||
|
# grab the status URL (fresh data)
|
||||||
|
@data = split /(\n)/, LWP::Simple::get( 'http://localhost/server-status?auto' )
|
||||||
|
or die "Data fetch failure.\n";
|
||||||
|
|
||||||
|
# write file
|
||||||
|
$tmpfile = "$CACHEFILE.TMP.$PID";
|
||||||
|
open (OUTFILE, ">$tmpfile")
|
||||||
|
or die "File open failure: $tmpfile\n";
|
||||||
|
print OUTFILE @data;
|
||||||
|
close OUTFILE;
|
||||||
|
rename ( $tmpfile, $CACHEFILE );
|
||||||
|
}
|
||||||
|
|
||||||
|
# dice up the data
|
||||||
|
@scoreboardkey = ( '_', 'S', 'R', 'W', 'K', 'D', 'C', 'L', 'G', 'I', '.' );
|
||||||
|
%params = {};
|
||||||
|
foreach $line (@data) {
|
||||||
|
chomp $line;
|
||||||
|
@fields = split( /: /, $line);
|
||||||
|
if ($fields[0] eq 'Scoreboard') {
|
||||||
|
# count up the scoreboard into states
|
||||||
|
%states = {};
|
||||||
|
foreach $state (@scoreboardkey) {
|
||||||
|
$states{$state} = 0;
|
||||||
|
}
|
||||||
|
foreach $state ( split(//, $fields[1]) ) {
|
||||||
|
$states{$state}++;
|
||||||
|
}
|
||||||
|
} elsif ($fields[0] eq 'Total kBytes') {
|
||||||
|
# turn into base (byte) value
|
||||||
|
$params{$fields[0]} = int($fields[1])*1024;
|
||||||
|
} else {
|
||||||
|
# just store everything else
|
||||||
|
$params{$fields[0]} = $fields[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# output the data in order (this is because some platforms don't have them all)
|
||||||
|
@dataorder = (
|
||||||
|
'Total Accesses',
|
||||||
|
'Total kBytes',
|
||||||
|
'CPULoad',
|
||||||
|
'Uptime',
|
||||||
|
'ReqPerSec',
|
||||||
|
'BytesPerSec',
|
||||||
|
'BytesPerReq',
|
||||||
|
'BusyServers',
|
||||||
|
'IdleServers'
|
||||||
|
);
|
||||||
|
foreach $param (@dataorder) {
|
||||||
|
if (exists $params{$param}) {
|
||||||
|
print $params{$param}."\n";
|
||||||
|
} else {
|
||||||
|
# not all Apache's have all stats
|
||||||
|
print "U\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# print the scoreboard
|
||||||
|
foreach $state (@scoreboardkey) {
|
||||||
|
print $states{$state}."\n";
|
||||||
|
}
|
||||||
87
snmp/apache-stats.py
Executable file
87
snmp/apache-stats.py
Executable file
@@ -0,0 +1,87 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Copyright (C) 2009 Glen Pitt-Pladdy
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
CACHETIME = 30
|
||||||
|
CACHEFILE = '/tmp/apache-snmp'
|
||||||
|
|
||||||
|
# check for cache file newer CACHETIME seconds ago
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
if os.path.isfile ( CACHEFILE ) \
|
||||||
|
and ( time.time() - os.stat ( CACHEFILE )[8] ) < CACHETIME:
|
||||||
|
# use cached data
|
||||||
|
f = open ( CACHEFILE, 'r' )
|
||||||
|
data = f.read()
|
||||||
|
f.close()
|
||||||
|
else:
|
||||||
|
# grab the status URL (fresh data)
|
||||||
|
# need debian package python-urlgrabber
|
||||||
|
from urlgrabber import urlread
|
||||||
|
data = urlread ( 'http://localhost/server-status?auto',
|
||||||
|
user_agent = 'SNMP Apache Stats' )
|
||||||
|
# write file
|
||||||
|
f = open ( CACHEFILE+'.TMP.'+`os.getpid()`, 'w' )
|
||||||
|
f.write ( data )
|
||||||
|
f.close()
|
||||||
|
os.rename ( CACHEFILE+'.TMP.'+`os.getpid()`, CACHEFILE )
|
||||||
|
|
||||||
|
|
||||||
|
# dice up the data
|
||||||
|
scoreboardkey = [ '_', 'S', 'R', 'W', 'K', 'D', 'C', 'L', 'G', 'I', '.' ]
|
||||||
|
params = {}
|
||||||
|
for line in data.splitlines():
|
||||||
|
fields = line.split( ': ' )
|
||||||
|
if fields[0] == 'Scoreboard':
|
||||||
|
# count up the scoreboard into states
|
||||||
|
states = {}
|
||||||
|
for state in scoreboardkey:
|
||||||
|
states[state] = 0
|
||||||
|
for state in fields[1]:
|
||||||
|
states[state] += 1
|
||||||
|
elif fields[0] == 'Total kBytes':
|
||||||
|
# turn into base (byte) value
|
||||||
|
params[fields[0]] = int(fields[1])*1024
|
||||||
|
else:
|
||||||
|
# just store everything else
|
||||||
|
params[fields[0]] = fields[1]
|
||||||
|
|
||||||
|
# output the data in order (this is because some platforms don't have them all)
|
||||||
|
dataorder = [
|
||||||
|
'Total Accesses',
|
||||||
|
'Total kBytes',
|
||||||
|
'CPULoad',
|
||||||
|
'Uptime',
|
||||||
|
'ReqPerSec',
|
||||||
|
'BytesPerSec',
|
||||||
|
'BytesPerReq',
|
||||||
|
'BusyWorkers',
|
||||||
|
'IdleWorkers'
|
||||||
|
]
|
||||||
|
for param in dataorder:
|
||||||
|
try:
|
||||||
|
print params[param]
|
||||||
|
# print param
|
||||||
|
except: # not all Apache's have all stats
|
||||||
|
print 'U'
|
||||||
|
|
||||||
|
# print the scoreboard
|
||||||
|
for state in scoreboardkey:
|
||||||
|
print states[state]
|
||||||
|
# print state
|
||||||
76
snmp/mailscanner.php
Executable file
76
snmp/mailscanner.php
Executable file
@@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
// A small script to grab the MailScanner statistics from a MailScanner server
|
||||||
|
// Needed commands: php, MailScanner, WatchMailLog, perl
|
||||||
|
///
|
||||||
|
// Install:
|
||||||
|
// Add the WatchMailLog Daemon to the rc.local so its start on server boot
|
||||||
|
// Run the WatchMailLog Daemon to start grabbing statistics from log files
|
||||||
|
// Add the following to your snmpd.conf file:
|
||||||
|
// extend mailwatch /opt/librenms/scripts/mailwatch.php
|
||||||
|
///
|
||||||
|
// Version 1.0 By:
|
||||||
|
// All In One - Dennis de Houx <info@all-in-one.be>
|
||||||
|
///
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
// START SETTINGS ///
|
||||||
|
|
||||||
|
$mailstats = "/opt/librenms/scripts/watchmaillog/watchmaillog_counters";
|
||||||
|
|
||||||
|
// END SETTINGS ///
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
// DO NOT EDIT BENETH THIS LINE
|
||||||
|
///
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function doSNMPv2($vars) {
|
||||||
|
$stats = array();
|
||||||
|
if (file_exists($vars)) {
|
||||||
|
$data = file($vars);
|
||||||
|
foreach ($data as $item=>$value) {
|
||||||
|
if (!empty($value)) {
|
||||||
|
$temp = explode(':', trim($value));
|
||||||
|
if (isset($temp[1])) {
|
||||||
|
$stats[$temp[0]] = $temp[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$var = array();
|
||||||
|
$var['mess_recv'] = (isset($stats['mess_recv']) ? $stats['mess_recv'] : "U");
|
||||||
|
$var['mess_rejected'] = (isset($stats['mess_rejected']) ? $stats['mess_rejected'] : "U");
|
||||||
|
$var['mess_relay'] = (isset($stats['mess_relay']) ? $stats['mess_relay'] : "U");
|
||||||
|
$var['mess_sent'] = (isset($stats['mess_sent']) ? $stats['mess_sent'] : "U");
|
||||||
|
$var['mess_waiting'] = (isset($stats['mess_waiting']) ? $stats['mess_waiting'] : "U");
|
||||||
|
$var['spam'] = (isset($stats['spam']) ? $stats['spam'] : "U");
|
||||||
|
$var['virus'] = (isset($stats['virus']) ? $stats['virus'] : "U");
|
||||||
|
foreach ($var as $item=>$count) {
|
||||||
|
echo $count."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearStats($mailstats) {
|
||||||
|
if (file_exists($mailstats)) {
|
||||||
|
$fp = fopen($mailstats, 'w');
|
||||||
|
fwrite($fp, "mess_recv:0\n");
|
||||||
|
fwrite($fp, "mess_rejected:0\n");
|
||||||
|
fwrite($fp, "mess_relay:0\n");
|
||||||
|
fwrite($fp, "mess_sent:0\n");
|
||||||
|
fwrite($fp, "mess_waiting:0\n");
|
||||||
|
fwrite($fp, "spam:0\n");
|
||||||
|
fwrite($fp, "virus:0\n");
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doSNMPv2($mailstats);
|
||||||
|
//clearStats($mailstats);
|
||||||
|
|
||||||
|
?>
|
||||||
131
snmp/mysql-stats
Executable file
131
snmp/mysql-stats
Executable file
@@ -0,0 +1,131 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
import warnings
|
||||||
|
import re
|
||||||
|
warnings.filterwarnings(action="ignore", message='the sets module is deprecated')
|
||||||
|
import sets
|
||||||
|
import MySQLdb
|
||||||
|
import base64
|
||||||
|
conn = MySQLdb.connect(host='',
|
||||||
|
user='',
|
||||||
|
passwd='',
|
||||||
|
db='')
|
||||||
|
|
||||||
|
cursor = conn.cursor ()
|
||||||
|
|
||||||
|
|
||||||
|
cursor.execute ("SHOW GLOBAL STATUS")
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
datavariables = {
|
||||||
|
'Command Counters': ['Com_delete','Com_insert','Com_insert_select','Com_load','Com_replace','Com_replace_select', 'Com_select', 'Com_update', 'Com_update_multi'],
|
||||||
|
'Connections': ['max_connections', 'Max_used_connections', 'Aborted_clients', 'Aborted_connects','Threads_connected','Connections'],
|
||||||
|
'Files and Tables': ['table_open_cache','Open_files','Open_tables','Opened_tables'],
|
||||||
|
'InnoDB Buffer Pool': ['ib_bpool_size','ib_bpool_dbpages', 'ib_bpool_free','ib_bpool_modpages'],
|
||||||
|
'InnoDB Buffer Pool Activity': ['ib_bpool_read','ib_bpool_created', 'ib_bpool_written'],
|
||||||
|
'InnoDB Insert Buffer': ['ib_ibuf_inserts','ib_ibuf_merged_rec', 'ib_ibuf_merges'],
|
||||||
|
'InnoDB IO': ['ib_io_read','ib_io_write','ib_io_log', 'ib_io_fsync'],
|
||||||
|
'InnoDB IO Pending': ['ib_iop_log','ib_iop_sync', 'ib_iop_flush_log', 'ib_iop_flush_bpool', 'ib_iop_ibuf_aio','ib_iop_aioread','ib_iop_aiowrite'],
|
||||||
|
'InnoDB Log': ['innodb_log_buffer_size','ib_log_flush','ib_log_written'],
|
||||||
|
'InnoDB Row Operations': ['Innodb_rows_deleted','Innodb_rows_inserted','Innodb_rows_read','Innodb_rows_updated'],
|
||||||
|
'InnoDB Semaphores': ['ib_spin_rounds','ib_spin_waits','ib_os_waits'],
|
||||||
|
'InnoDB Transactions': ['ib_tnx'],
|
||||||
|
'MyISAM Indexes': ['Key_read_requests','Key_reads','Key_write_requests','Key_writes'],
|
||||||
|
'Network Traffic': ['Bytes_received','Bytes_sent'],
|
||||||
|
'Query Cache': ['Qcache_queries_in_cache','Qcache_hits','Qcache_inserts','Qcache_not_cached','Qcache_lowmem_prunes'],
|
||||||
|
'Query Cache Memory': ['query_cache_size','Qcache_free_memory'],
|
||||||
|
'Select Types': ['Select_full_join','Select_full_range_join','Select_range','Select_range_check','Select_scan'],
|
||||||
|
'Slow Queries': ['Slow_queries'],
|
||||||
|
'Sorts': ['Sort_rows','Sort_range','Sort_merge_passes','Sort_scan'],
|
||||||
|
'Table Locks': ['Table_locks_immediate','Table_locks_waited'],
|
||||||
|
'Temporary Objects': ['Created_tmp_disk_tables','Created_tmp_tables','Created_tmp_files']
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
for row in rows:
|
||||||
|
data[row[0]] = row[1]
|
||||||
|
|
||||||
|
cursor = ""
|
||||||
|
cursor = conn.cursor ()
|
||||||
|
cursor.execute ("SHOW VARIABLES")
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
data[row[0]] = row[1]
|
||||||
|
|
||||||
|
cursor = ""
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SHOW ENGINE INNODB STATUS")
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
for line in row[2].split("\n"):
|
||||||
|
ib_bpool_size = re.match(r"Buffer\spool\ssize\s+(\d+)", line)
|
||||||
|
ib_bpool_free = re.match(r"Free\sbuffers\s+(\d+)", line)
|
||||||
|
ib_bpool_dbpages = re.match(r"Database\spages\s+(\d+)", line)
|
||||||
|
ib_bpool_modpages = re.match(r"Modified\sdb\spages\s+(\d+)", line)
|
||||||
|
ib_b_reg = re.match(r"Pages\sread\s(\d+),\screated\s(\d+),\swritten (\d+)", line)
|
||||||
|
ib_insert_buffer = re.match(r"(\d+)\sinserts,\s(\d+)\smerged\srecs,\s(\d+)", line)
|
||||||
|
ib_io = re.match(r"(\d+)\sOS\sfile\sreads,\s(\d+)\sOS\sfile\swrites,\s(\d+)\sOS\sfsyncs", line)
|
||||||
|
ib_io_log = re.match(r"(\d+)\slog\si\/o's\sdone.*", line)
|
||||||
|
ib_io_p1 = re.match(r"Pending\snormal\saio\sreads:\s(\d+),\saio\swrites:\s(\d+),", line)
|
||||||
|
ib_io_p2 = re.match(r"\s?ibuf\saio\sreads:\s(\d+),\slog\si\/o's:\s(\d+),\ssync\si\/o's:\s(\d+)", line)
|
||||||
|
ib_io_p3 = re.match(r"\s?Pending\sflushes\s\(fsync\)\slog:\s(\d+);\sbuffer\spool:\s(\d+)\s?", line)
|
||||||
|
ib_log_p1 = re.match(r"\s?Log\ssequence\snumber\s([[a-fA-F\d]+)(?: (\d+))?", line)
|
||||||
|
ib_log_p2 = re.match(r"\s?Log\sflushed\sup\sto\s+([[a-fA-F\d]+)(?: (\d+))?", line)
|
||||||
|
ib_semaphore = re.match(r"\s?Mutex\sspin\swaits\s(\d+),\srounds\s(\d+),\sOS waits\s(\d+)", line)
|
||||||
|
ib_tnx = re.match(r"\s?Trx\sid\scounter\s([[a-fA-F\d]+)(?: (\d+))?", line)
|
||||||
|
|
||||||
|
if ib_bpool_size:
|
||||||
|
data['ib_bpool_size'] = ib_bpool_size.group(1)
|
||||||
|
elif ib_bpool_free:
|
||||||
|
data['ib_bpool_free'] = ib_bpool_free.group(1)
|
||||||
|
elif ib_bpool_dbpages:
|
||||||
|
data['ib_bpool_dbpages'] = ib_bpool_dbpages.group(1)
|
||||||
|
elif ib_bpool_modpages:
|
||||||
|
data['ib_bpool_modpages'] = ib_bpool_modpages.group(1)
|
||||||
|
elif ib_insert_buffer:
|
||||||
|
data['ib_ibuf_inserts'] = ib_insert_buffer.group(1)
|
||||||
|
data['ib_ibuf_merged_rec'] = ib_insert_buffer.group(2)
|
||||||
|
data['ib_ibuf_merges'] = ib_insert_buffer.group(3)
|
||||||
|
elif ib_io:
|
||||||
|
data['ib_io_read'] = ib_io.group(1)
|
||||||
|
data['ib_io_write'] = ib_io.group(2)
|
||||||
|
data['ib_io_fsync'] = ib_io.group(3)
|
||||||
|
elif ib_io_log:
|
||||||
|
data['ib_io_log'] = ib_io_log.group(1)
|
||||||
|
elif ib_io_p1:
|
||||||
|
data['ib_iop_aioread'] = ib_io_p1.group(1)
|
||||||
|
data['ib_iop_aiowrite'] = ib_io_p1.group(2)
|
||||||
|
elif ib_io_p2:
|
||||||
|
data['ib_iop_ibuf_aio'] = ib_io_p2.group(1)
|
||||||
|
data['ib_iop_log'] = ib_io_p2.group(2)
|
||||||
|
data['ib_iop_sync'] = ib_io_p2.group(3)
|
||||||
|
elif ib_io_p3:
|
||||||
|
data['ib_iop_flush_log'] = ib_io_p3.group(1)
|
||||||
|
data['ib_iop_flush_bpool'] = ib_io_p3.group(2)
|
||||||
|
elif ib_log_p1:
|
||||||
|
data['ib_log_written'] = ib_log_p1.group(1)
|
||||||
|
if ib_log_p1.group(2):
|
||||||
|
data['ib_log_written'] = int(data['ib_log_written']) + int(ib_log_p1.group(2))
|
||||||
|
elif ib_log_p2:
|
||||||
|
data['ib_log_flush'] = ib_log_p2.group(1)
|
||||||
|
if ib_log_p2.group(2):
|
||||||
|
data['ib_log_flush'] = int(data['ib_log_flush']) + int(ib_log_p2.group(2))
|
||||||
|
elif ib_semaphore:
|
||||||
|
data['ib_spin_waits'] = ib_semaphore.group(1)
|
||||||
|
data['ib_spin_rounds'] = ib_semaphore.group(2)
|
||||||
|
data['ib_os_waits'] = ib_semaphore.group(3)
|
||||||
|
elif ib_tnx:
|
||||||
|
data['ib_tnx'] = ib_tnx.group(1)
|
||||||
|
if ib_tnx.group(2):
|
||||||
|
data['ib_tnx'] = int(data['ib_tnx']) + int(ib_tnx.group(2))
|
||||||
|
elif ib_b_reg:
|
||||||
|
data['ib_bpool_read'] = ib_b_reg.group(1)
|
||||||
|
data['ib_bpool_created'] = ib_b_reg.group(2)
|
||||||
|
data['ib_bpool_written'] = ib_b_reg.group(3)
|
||||||
|
|
||||||
|
|
||||||
|
for category in datavariables:
|
||||||
|
for variable in datavariables[category]:
|
||||||
|
if variable in data:
|
||||||
|
print data[variable]
|
||||||
1247
snmp/mysql_stats.php
Executable file
1247
snmp/mysql_stats.php
Executable file
File diff suppressed because it is too large
Load Diff
0
snmp/nfs-stats.sh
Normal file → Executable file
0
snmp/nfs-stats.sh
Normal file → Executable file
37
snmp/nginx-stats
Executable file
37
snmp/nginx-stats
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
import urllib2
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
data = urllib2.urlopen('http://127.0.0.1/nginx-status').read()
|
||||||
|
|
||||||
|
params = {}
|
||||||
|
|
||||||
|
for line in data.split("\n"):
|
||||||
|
smallstat = re.match(r"\s?Reading:\s(.*)\sWriting:\s(.*)\sWaiting:\s(.*)$", line)
|
||||||
|
req = re.match(r"\s+(\d+)\s+(\d+)\s+(\d+)", line)
|
||||||
|
if smallstat:
|
||||||
|
params["Reading"] = smallstat.group(1)
|
||||||
|
params["Writing"] = smallstat.group(2)
|
||||||
|
params["Waiting"] = smallstat.group(3)
|
||||||
|
elif req:
|
||||||
|
params["Requests"] = req.group(3)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
dataorder = [
|
||||||
|
"Active",
|
||||||
|
"Reading",
|
||||||
|
"Writing",
|
||||||
|
"Waiting",
|
||||||
|
"Requests"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
for param in dataorder:
|
||||||
|
if param == "Active":
|
||||||
|
Active = int(params["Reading"]) + int(params["Writing"]) + int(params["Waiting"])
|
||||||
|
print Active
|
||||||
|
else:
|
||||||
|
print params[param]
|
||||||
13
snmp/postfix-queues
Executable file
13
snmp/postfix-queues
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#Written by Valec 2006. Steal and share.
|
||||||
|
#Get postfix queue lengths
|
||||||
|
|
||||||
|
#extend mailq /opt/observer/scripts/getmailq.sh
|
||||||
|
|
||||||
|
QUEUES="incoming active deferred hold"
|
||||||
|
|
||||||
|
for i in $QUEUES; do
|
||||||
|
COUNT=`qshape $i | grep TOTAL | awk '{print $2}'`
|
||||||
|
printf "$COUNT\n"
|
||||||
|
done
|
||||||
76
snmp/powerdns.php
Executable file
76
snmp/powerdns.php
Executable file
@@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// A small script to grab the DNS statistics from a PowerDNS server
|
||||||
|
// Needed commands: php, pdns_control
|
||||||
|
//
|
||||||
|
// Install:
|
||||||
|
// Add the following to your snmpd.conf file:
|
||||||
|
// extend powerdns /opt/librenms/scripts/powerdns.php
|
||||||
|
//
|
||||||
|
// Version 1.0 By:
|
||||||
|
// All In One - Dennis de Houx <info@all-in-one.be>
|
||||||
|
|
||||||
|
// START SETTINGS ///
|
||||||
|
$pdnscontrol = '/usr/bin/pdns_control';
|
||||||
|
// END SETTINGS ///
|
||||||
|
|
||||||
|
// DO NOT EDIT UNDER THIS LINE
|
||||||
|
//
|
||||||
|
$cmd = shell_exec($pdnscontrol.' show \*');
|
||||||
|
$vars = array();
|
||||||
|
$vars = explode(',', $cmd);
|
||||||
|
|
||||||
|
|
||||||
|
function doSNMP($vars) {
|
||||||
|
foreach ($vars as $item => $value) {
|
||||||
|
$value = trim($value);
|
||||||
|
if (!empty($value)) {
|
||||||
|
echo $value."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}//end doSNMP()
|
||||||
|
|
||||||
|
function doSNMPv2($vars) {
|
||||||
|
$pdns = array();
|
||||||
|
foreach ($vars as $item => $value) {
|
||||||
|
if (!empty($value)) {
|
||||||
|
$temp = explode('=', $value);
|
||||||
|
if (isset($temp[1])) {
|
||||||
|
$pdns[$temp[0]] = $temp[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$var = array();
|
||||||
|
$var['corrupt-packets'] = (isset($pdns['corrupt-packets']) ? $pdns['corrupt-packets'] : 'U');
|
||||||
|
$var['deferred-cache-inserts'] = (isset($pdns['deferred-cache-inserts']) ? $pdns['deferred-cache-inserts'] : 'U');
|
||||||
|
$var['deferred-cache-lookup'] = (isset($pdns['deferred-cache-lookup']) ? $pdns['deferred-cache-lookup'] : 'U');
|
||||||
|
$var['latency'] = (isset($pdns['latency']) ? $pdns['latency'] : 'U');
|
||||||
|
$var['packetcache-hit'] = (isset($pdns['packetcache-hit']) ? $pdns['packetcache-hit'] : 'U');
|
||||||
|
$var['packetcache-miss'] = (isset($pdns['packetcache-miss']) ? $pdns['packetcache-miss'] : 'U');
|
||||||
|
$var['packetcache-size'] = (isset($pdns['packetcache-size']) ? $pdns['packetcache-size'] : 'U');
|
||||||
|
$var['qsize-q'] = (isset($pdns['qsize-q']) ? $pdns['qsize-q'] : 'U');
|
||||||
|
$var['query-cache-hit'] = (isset($pdns['query-cache-hit']) ? $pdns['query-cache-hit'] : 'U');
|
||||||
|
$var['query-cache-miss'] = (isset($pdns['query-cache-miss']) ? $pdns['query-cache-miss'] : 'U');
|
||||||
|
$var['recursing-answers'] = (isset($pdns['recursing-answers']) ? $pdns['recursing-answers'] : 'U');
|
||||||
|
$var['recursing-questions'] = (isset($pdns['recursing-questions']) ? $pdns['recursing-questions'] : 'U');
|
||||||
|
$var['servfail-packets'] = (isset($pdns['servfail-packets']) ? $pdns['servfail-packets'] : 'U');
|
||||||
|
$var['tcp-answers'] = (isset($pdns['tcp-answers']) ? $pdns['tcp-answers'] : 'U');
|
||||||
|
$var['tcp-queries'] = (isset($pdns['tcp-queries']) ? $pdns['tcp-queries'] : 'U');
|
||||||
|
$var['timedout-packets'] = (isset($pdns['timedout-packets']) ? $pdns['timedout-packets'] : 'U');
|
||||||
|
$var['udp-answers'] = (isset($pdns['udp-answers']) ? $pdns['udp-answers'] : 'U');
|
||||||
|
$var['udp-queries'] = (isset($pdns['udp-queries']) ? $pdns['udp-queries'] : 'U');
|
||||||
|
$var['udp4-answers'] = (isset($pdns['udp4-answers']) ? $pdns['udp4-answers'] : 'U');
|
||||||
|
$var['udp4-queries'] = (isset($pdns['udp4-queries']) ? $pdns['udp4-queries'] : 'U');
|
||||||
|
$var['udp6-answers'] = (isset($pdns['udp6-answers']) ? $pdns['udp6-answers'] : 'U');
|
||||||
|
$var['udp6-queries'] = (isset($pdns['udp6-queries']) ? $pdns['udp6-queries'] : 'U');
|
||||||
|
foreach ($var as $item => $count) {
|
||||||
|
echo $count."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}//end doSNMPv2()
|
||||||
|
|
||||||
|
|
||||||
|
doSNMPv2($vars);
|
||||||
0
snmp/raspberry.sh
Normal file → Executable file
0
snmp/raspberry.sh
Normal file → Executable file
3
snmp/shoutcast.default.conf
Normal file
3
snmp/shoutcast.default.conf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
server1:8050
|
||||||
|
server2:8000
|
||||||
|
server2:8010
|
||||||
122
snmp/shoutcast.php
Executable file
122
snmp/shoutcast.php
Executable file
@@ -0,0 +1,122 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
// A small script to grab the realtime statistics from a ShoutCast server
|
||||||
|
// Needed commands: php
|
||||||
|
///
|
||||||
|
// Install:
|
||||||
|
// Edit the shoutcast.conf file
|
||||||
|
// Add a crontab (every 5 min) for:
|
||||||
|
// /opt/librenms/scripts/shoutcast.php makeCache
|
||||||
|
// Add the following to your snmpd.conf file:
|
||||||
|
// extend shoutcast /opt/librenms/scripts/shoutcast.php
|
||||||
|
///
|
||||||
|
// Version 1.1 By:
|
||||||
|
// All In One - Dennis de Houx <info@all-in-one.be>
|
||||||
|
///
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
// START SETTINGS ///
|
||||||
|
|
||||||
|
$config = "/opt/librenms/scripts/shoutcast.conf";
|
||||||
|
$cache = "/opt/librenms/scripts/shoutcast.cache";
|
||||||
|
|
||||||
|
// END SETTINGS ///
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
// DO NOT EDIT BENETH THIS LINE
|
||||||
|
///
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/* Do NOT run this script through a web browser */
|
||||||
|
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
|
||||||
|
die('<span style="color: #880000; text-weight: bold; font-size: 1.3em;">This script is only meant to run at the command line.</span>');
|
||||||
|
}
|
||||||
|
|
||||||
|
$cmd = (isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : "");
|
||||||
|
|
||||||
|
function get_data($host, $port) {
|
||||||
|
$fp = @fsockopen($host, $port, $errno, $errstr, 5);
|
||||||
|
if(!$fp) { $connect = 0; }
|
||||||
|
if (!isset($connect)) {
|
||||||
|
fputs($fp, "GET /7.html HTTP/1.0\r\n"
|
||||||
|
. "User-Agent: All In One - SHOUTcast Stats Parser"
|
||||||
|
. " (Mozilla Compatible)\r\n\r\n");
|
||||||
|
while (!feof($fp)) {
|
||||||
|
$rawdata = fgets($fp, 1024);
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
preg_match('/body>(.*)<\/body/', $rawdata, $matches);
|
||||||
|
$res = explode(',', $matches[1], 7);
|
||||||
|
$res[7] = $host;
|
||||||
|
$res[8] = $port;
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_list($config) {
|
||||||
|
if (file_exists($config)) {
|
||||||
|
$servers = file($config);
|
||||||
|
$data = array();
|
||||||
|
foreach ($servers as $item=>$server) {
|
||||||
|
list($host, $port) = explode(":", $server, 2);
|
||||||
|
array_push($data, get_data(trim($host), trim($port)));
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function doSNMPv2($vars) {
|
||||||
|
$res = array();
|
||||||
|
foreach ($vars as $items=>$server) {
|
||||||
|
$var = array();
|
||||||
|
$var['bitrate'] = (isset($server['5']) ? (($server['5'] / 8) * 1000) : "0");
|
||||||
|
//$var['bitrate'] = (isset($server['5']) ? ($server['5'] * 1024) : "0");
|
||||||
|
$var['traf_in'] = (isset($server['1']) ? ($var['bitrate'] * $server['1']) : "0");
|
||||||
|
$var['traf_out'] = (isset($server['0']) ? ($var['bitrate'] * $server['0']) : "0");
|
||||||
|
$var['current'] = (isset($server['0']) ? $server['0'] : "0");
|
||||||
|
$var['status'] = (isset($server['1']) ? $server['1'] : "0");
|
||||||
|
$var['peak'] = (isset($server['2']) ? $server['2'] : "0");
|
||||||
|
$var['max'] = (isset($server['3']) ? $server['3'] : "0");
|
||||||
|
$var['unique'] = (isset($server['4']) ? $server['4'] : "0");
|
||||||
|
$host = (isset($server['7']) ? $server['7'] : "unknown");
|
||||||
|
$port = (isset($server['8']) ? $server['8'] : "unknown");
|
||||||
|
$tmp = $host.":".$port;
|
||||||
|
foreach ($var as $item=>$value) {
|
||||||
|
$tmp .= ";".$value;
|
||||||
|
}
|
||||||
|
array_push($res, $tmp);
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeCacheFile($data, $cache) {
|
||||||
|
$fp = fopen($cache, 'w');
|
||||||
|
foreach ($data as $item=>$value) {
|
||||||
|
fwrite($fp, $value."\n");
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function readCacheFile($cache) {
|
||||||
|
if (file_exists($cache)) {
|
||||||
|
$data = file($cache);
|
||||||
|
foreach ($data as $item=>$value) {
|
||||||
|
echo trim($value)."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cmd == "makeCache") {
|
||||||
|
$servers = get_list($config);
|
||||||
|
$data = doSNMPv2($servers);
|
||||||
|
makeCacheFile($data, $cache);
|
||||||
|
} else {
|
||||||
|
readCacheFile($cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user