commit 3ca191dd2f8f7363352ae12d56be6ed031f2b4a0 Author: root Date: Thu May 3 20:27:22 2018 +0200 init diff --git a/check_clients.py b/check_clients.py new file mode 100755 index 0000000..c515ee7 --- /dev/null +++ b/check_clients.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 +import json +from urllib.request import urlopen +from pprint import pprint +import sys + +JSON_URL = "https://netinfo.freifunk-stuttgart.de/json/alfred-json-159.json" + +if len(sys.argv) != 2: + print("UNKNOWN: Invalid arguments "+sys.argv[0]+" ") + exit(3) +node_mac = sys.argv[1] + +response = urlopen(JSON_URL) +data = json.loads(response.read().decode("utf-8")) + +node = {} +try: + node = data[node_mac] +except KeyError as e: + print("CRITICAL: Node not found: "+str(e)) + exit(2) + +performance_data = "" + +for key,value in node['clients'].items(): + performance_data += "|"+str(key)+"="+str(value)+"\n" + +print("OK - %d Clients"%node['clients']['total']+performance_data) +exit(0) diff --git a/check_cups_printer b/check_cups_printer new file mode 100755 index 0000000..bf08da3 --- /dev/null +++ b/check_cups_printer @@ -0,0 +1,78 @@ +#!/bin/bash +# +# Copyright (c) 2009, Mark Shirley +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +# +# -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +# -Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +# -The name of the contributor may not be used to endorse or promote products derived from this software without specific prior written permission. + +#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +# +# +# + +# This will attempt to locate existing lpstat command. Modify if neccessary. +LPSTAT=`which lpstat` + +while [ $# -gt 0 ] +do + case $1 in + -h) + HOST=$2 + shift 2 + ;; + -p) + PRINTER=$2 + shift 2 + ;; + *) + echo "The arguments to use are" + echo "-h: The host of the CUPS server" + echo "-p: The CUPS printer name" + shift 1 + ;; + esac +done + +error_file=$(mktemp) +RESULT=$($LPSTAT -h $HOST -p $PRINTER 2>$error_file) +ERRORS=$(< $error_file) +rm $error_file + + +# Due to lpstat returning a "printing" regardless of the printer rejecting or unable to connect i moved those up higher in the case +case $RESULT in + *Rejecting*) + OUTPUT="Critical - $PRINTER is rejecting jobs" + EXIT=2 + ;; + *Unable*) + OUTPUT="Critical - CUPS Unable to connect to $PRINTER" + EXIT=2 + ;; + *idle*) + OUTPUT="OK - $PRINTER is idle" + EXIT=0 + ;; + *printing*) + OUTPUT="OK - $PRINTER is printing" + EXIT=0 + ;; + *disabled*) + OUTPUT="CRITICAL - $PRINTER is stopped" + EXIT=2 + ;; + *) + OUTPUT="CRITICAL - Unknown error occured while checking $PRINTER" + EXIT=2 + ;; +esac + +echo $OUTPUT +echo $ERRORS +exit $EXIT diff --git a/check_dnsmasq_leases.sh b/check_dnsmasq_leases.sh new file mode 100755 index 0000000..38a4173 --- /dev/null +++ b/check_dnsmasq_leases.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +leases=$(cat /var/lib/misc/dnsmasq.leases | wc -l) +VALUE="|Leases=$leases" +OUTPUT="OK: $leases active leases" +EXIT_CODE=0 + +echo "$OUTPUT" "$VALUE" +exit $EXIT_CODE diff --git a/check_entropy b/check_entropy new file mode 100755 index 0000000..90151e6 --- /dev/null +++ b/check_entropy @@ -0,0 +1,93 @@ +#!/usr/bin/perl +# +# check_entropy - Monitor systems entropy +# Copyright (C) 2016 Josef 'veloc1ty' Stautner (hello@veloc1ty.de) +# +# 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 3 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, see . + +use strict; +use Getopt::Long; + +our $ARG_WARNING_VALUE = 400; +our $ARG_CRITICAL_VALUE = 200; + +sub isInt { + my $possibleInt = shift; + + return 1 if ( $possibleInt =~ /\d+/ ); + return 0; +} + +sub exitUnknown { + printf("UNKNOWN - %s\n", shift); + exit(3); +} + +sub exitCritical { + printf("CRITICAL - %s\n", shift); + exit(2); +} + +sub exitWarning { + printf("WARNING - %s\n", shift); + exit(1); +} + +sub parseArguments { + GetOptions ( + 'warning=i' => \$ARG_WARNING_VALUE, + 'critical=i' => \$ARG_CRITICAL_VALUE + ); + + exitUnknown('--warning isn\'t a number') if ( ! isInt($ARG_WARNING_VALUE)); + exitUnknown('--critical isn\'t a number') if ( ! isInt($ARG_CRITICAL_VALUE)); + + if ( $ARG_WARNING_VALUE < $ARG_CRITICAL_VALUE ) { + exitUnknown('--warning has to be greater that --critical') + } +} + +sub getEntropy { + my $possibleEntropy = `cat /proc/sys/kernel/random/entropy_avail`; + chomp($possibleEntropy); + + if ( ! isInt($possibleEntropy) ) { + exitCritical('Was not able to fetch available entropy'); + } + + return $possibleEntropy; +} + +sub main { + parseArguments(); + + my $availableEntropy = getEntropy(); + my $availableEntropyString = + sprintf('Available: %d|available_entropy=%d;%d;%d', + $availableEntropy, $availableEntropy, $ARG_WARNING_VALUE, + $ARG_CRITICAL_VALUE); + + + if ( $availableEntropy < $ARG_CRITICAL_VALUE ) { + exitCritical(sprintf('Not enogh entropy! %s', $availableEntropyString)); + } + elsif ( $availableEntropy < $ARG_WARNING_VALUE ) { + exitWarning(sprintf('Slightly few entropy! %s', $availableEntropyString)); + } + else { + printf("OK - Entropy is just fine! %s\n", $availableEntropyString); + } +} + +main(); diff --git a/check_heating.sh b/check_heating.sh new file mode 100755 index 0000000..0b04b6c --- /dev/null +++ b/check_heating.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +IMAGE_URL="http://webcam.intern.yannikenss.de/image.jpg" +TRESHOLD=0.009 + +while getopts ":i:c:" opt; do + case $opt in + i) + IMAGE_URL="$OPTARG" + ;; + c) + TRESHOLD="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" + ;; + esac +done + +OUTPUT="UNKNOWN: Script failed" +EXIT_CODE=3 + +error_file=$(mktemp) + +for i in {1..3} +do + value=$(convert <(curl -s "$IMAGE_URL" 2>> $error_file ) -colorspace Gray -format "%[fx:image.mean]" info: 2>> $error_file) + is_dark=$(echo "$value < $TRESHOLD" | bc -l 2>> $error_file) + + if [ $is_dark -eq 0 ] + then + OUTPUT="OK: Image bright" + EXIT_CODE=0 + else + OUTPUT="CRITICAL: Image dark" + EXIT_CODE=2 + VALUE="|Brightness=$value" + + echo "$OUTPUT" "$VALUE" + cat $error_file + rm $error_file + exit $EXIT_CODE + fi + sleep 0.5 +done +VALUE="|Brightness=$value" + +echo "$OUTPUT" "$VALUE" +cat $error_file +rm $error_file +exit $EXIT_CODE diff --git a/check_openvpn b/check_openvpn new file mode 100755 index 0000000..61c3a99 --- /dev/null +++ b/check_openvpn @@ -0,0 +1,184 @@ +#!/usr/bin/env python + +# Check if an OpenVPN server runs on a given UDP or TCP port. +# +# Copyright 2013 Roland Wolters +# Copyright 2016 Alarig Le Lay +# +# Version 20160803 +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import os +import sys +import time +import hmac +import hashlib +import struct +import socket +import argparse +import binascii + +HMAC_CLIENT_KEY_START = 192 +BUFFER_SIZE = 1024 + +def ok(msg): + print 'OK: %s' % msg + return 0 + +def critical(msg): + print 'CRIT: %s' % msg + return 2 + +def buildpacket(tcp, key, digestmod): + packet = 1 + ts = int(time.time()) + session = os.urandom(8) + + if key: + # hmac + h = hmac.new(key, digestmod=digestmod) + h.update(struct.pack('>I', packet)) # packet id + h.update(struct.pack('>I', ts)) # net time + h.update('\x38') # type + h.update(session) # session id + h.update(struct.pack('>B', 0)) # message packet id array length + h.update(struct.pack('>I', 0)) # message packet id + + # packet + result = '' + result += '\x38' # type + result += session # session id + if key: result += h.digest() # hmac + result += struct.pack('>I', packet) # packet id + result += struct.pack('>I', ts) # net time + result += struct.pack('>B', 0) # message packet id array length + result += struct.pack('>I', 0) # message packet id + if tcp: result = struct.pack('>H', len(result)) + result + return result + +def checkserver(host, port, tcp, timeout, key, digest): + packet = buildpacket(tcp, key, digest) + check = checkserver_tcp if tcp else checkserver_udp + return check(host, port, timeout, packet) + +def checkserver_udp(host, port, timeout, packet): + # thanks to glucas for the idea + try: + af, socktype, proto, canonname, sa = socket.getaddrinfo(host, port, \ + socket.AF_UNSPEC, socket.SOCK_DGRAM)[0] + s = socket.socket(af, socktype, proto) + s.settimeout(timeout) + except socket.error: + return critical('Unable to create UDP socket') + + try: + s.sendto(packet, (host, port)) + data, _ = s.recvfrom(BUFFER_SIZE) + reply = binascii.hexlify(data) + return ok('OpenVPN UDP server response (hex): %s' % reply) + except: + return critical('OpenVPN UDP server not responding') + finally: + s.close() + +def checkserver_tcp(host, port, timeout, packet): + try: + af, socktype, proto, canonname, sa = socket.getaddrinfo(host, port, \ + socket.AF_UNSPEC, socket.SOCK_STREAM)[0] + s = socket.socket(af, socktype, proto) + s.settimeout(timeout) + except socket.error: + return critical('Unable to create TCP socket') + + try: + s.connect((host, port)) + s.send(packet) + data = s.recv(BUFFER_SIZE) + if len(data) <= 0: raise RuntimeError + reply = binascii.hexlify(data) + return ok('OpenVPN TCP server response (hex): %s' % reply) + except: + return critical('OpenVPN TCP server not responding') + finally: + s.close() + +def readkey(path): + key = None + try: + with open(path, 'r') as myfile: key = myfile.read() + except: + return None + index_start = key.find('-\n'); + index_end = key.find('\n-', index_start); + if index_start < 0 or index_end < 0 or index_end <= index_start: + return None + index_start += 2 + key = key[index_start:index_end].replace('\n', '').replace('\r', '') + return key + +def optionsparser(argv=None): + parser = argparse.ArgumentParser() + parser.add_argument('-p', '--port', help='set port number (default is %(default)d)', type=int, dest='port', default=1194) + parser.add_argument('-t', '--tcp', help='use tcp instead of udp', action='store_true') + parser.add_argument('--timeout', help='set timeout (default is %(default)d)', type=int, default=5) + parser.add_argument('--digest', help='set HMAC digest (default is %(default)s)', type=str, default='sha1') + parser.add_argument('--digest-size', help='set HMAC digest size', type=int) + parser.add_argument('--digest-key', help='set HMAC key', type=str, default=None) + parser.add_argument('--tls-auth', help='set tls-auth file', type=str, default=None) + parser.add_argument('host', help='the OpenVPN host name or IP', type=str) + return parser.parse_args(argv) + +def main(argv=None): + args = optionsparser(argv) + + if args.digest_size and args.digest_size < 0: + critical('digest size must be positive') + if args.tls_auth and args.digest_key: + critical('--tls-auth cannot go with --digest-key') + + key = args.digest_key + digest = args.digest + digest_size = args.digest_size + + digest = digest.lower() + if digest not in hashlib.algorithms: + return critical('digest not available') + try: + digest = getattr(hashlib, digest) + if not digest_size: digest_size = digest().digest_size + except: + return critical('digest creation failed') + + if args.tls_auth: + key = readkey(args.tls_auth) + if key == None: return critical('cannot read tls auth file') + index_start = HMAC_CLIENT_KEY_START * 2 + index_end = (HMAC_CLIENT_KEY_START + digest_size) * 2 + key = key[index_start:index_end] + + if key: key = binascii.unhexlify(key) + + return checkserver(args.host, args.port, args.tcp, args.timeout, key, digest) + +if __name__ == '__main__': + code = main() + sys.exit(code) + diff --git a/check_postfix_queue b/check_postfix_queue new file mode 100755 index 0000000..45344b2 --- /dev/null +++ b/check_postfix_queue @@ -0,0 +1,140 @@ +#!/bin/bash +################################################################### +# check_postfix_mailqueue is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Bjoern Bongermino +# +################################################################### +# 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. +# +#################################################################### + +# Uncomment to enable debugging +# set -x + +PROGNAME=`basename $0` +VERSION="Version 1.0" +AUTHOR="Bjoern Bongermino (http://www.bongermino.de)" + +STATE_OK=0 +STATE_WARNING=1 +STATE_CRITICAL=2 +STATE_UNKNOWN=3 + +warning=0 +critical=0 + +print_version() { + echo "$PROGNAME $VERSION $AUTHOR" +} + +print_help() { + print_version $PROGNAME $VERSION + echo "" + echo "$PROGNAME - Checks postfix mailqueue statistic" + echo "" + echo "$PROGNAME is a Nagios plugin which generates statistics" + echo "for the postfix mailqueue and checks for corrupt messages." + echo "The following values will be checked:" + echo "maildrop: Localy posted mail" + echo "incoming: Processed local mail and received from network" + echo "active: Mails being delivered (should be small)" + echo "deferred: Stuck mails (that will be retried later)" + echo "corrupt: Messages found to not be in correct format (shold be 0)" + echo "hold: Recent addition, messages put on hold indefinitly - delete of free" + echo "" + echo "Usage: $PROGNAME -w WARN-Level -c CRIT-Level" + echo "" + echo "Options:" + echo " -w)" + echo " Warning level for deferred mails" + echo " -c)" + echo " Critical level for deferred mail" + echo " -h)" + echo " This help" + echo " -v)" + echo " Version" + exit $STATE_OK +} + +# Check for parameters +while test -n "$1"; do + case "$1" in + -h) + print_help + exit $STATE_OK;; + -v) + print_version + exit $STATE_OK;; + -w) + warning=$2 + shift + ;; + -c) + critical=$2 + shift + ;; + *) + check_postfix_mailqueue + ;; + esac + shift +done + +check_postfix_mailqueue() { +# Can be set via environment, but default is fetched by postconf (if available, +# else /var/spool/postfix) +if which postconf > /dev/null ; then + SPOOLDIR=${spooldir:-`postconf -h queue_directory`} +else + SPOOLDIR=${spooldir:-/var/spool/postfix} +fi + +cd $SPOOLDIR >/dev/null 2>/dev/null || { + echo -n "Cannot cd to $SPOOLDIR" + exit $STATE_CRITICAL +} + +# Get values +deferred=`(test -d deferred && find deferred -type f ) | wc -l` +active=`(test -d active && find active -type f ) | wc -l` +maildrop=`(test -d maildrop && find maildrop -type f ) | wc -l` +incoming=`(test -d incoming && find incoming -type f ) | wc -l` +corrupt=`(test -d corrupt && find corrupt -type f ) | wc -l` +hold=`( test -d hold && find hold -type f ) | wc -l` +} + +check_postfix_mailqueue +values="Deferred mails=$deferred Active deliveries=$active Locally posted mails=$maildrop Incoming mails=$incoming Corrupt mails=$corrupt Mails on hold=$hold" +perfdata="deferred=$deferred;; active=$active;; maildrop=$maildrop;; incoming=$incoming;; corrupt=$corrupt;; hold=$hold;;" + +if [ $corrupt -gt 0 ]; then + echo -n "Postfix Mailqueue CRITICAL - $corrupt corrupt messages found! | $perfdata" + exit $STATE_CRITICAL +fi + +if [ $warning -gt 0 ] && [ $critical -gt 0 ]; then + if [ $deferred -gt $critical ]; then + echo -n "Postfix Mailqueue CRITICAL - $values | $perfdata" + exit $STATE_CRITICAL + elif [ $deferred -gt $warning ]; then + echo -n "Postfix Mailqueue WARNING - $values | $perfdata" + exit $STATE_WARNING + else + echo -n "Postfix Mailqueue OK - $values | $perfdata" + exit $STATE_OK + fi +else + echo -n "Postfix Mailqueue OK - $values | $perfdata" + exit $STATE_OK +fi diff --git a/check_proxy.sh b/check_proxy.sh new file mode 100755 index 0000000..f9b0153 --- /dev/null +++ b/check_proxy.sh @@ -0,0 +1,115 @@ +#!/bin/bash +# +# Check the status of a proxy server by downloading a sample URL directly and through the proxy and then comparing the two files +# +# -- Written 2008/03/13 TA + + +# establish the default settings +# +# this can be overridden on the command line, but as long as the Nagios instance is up, this URL should work +SAMPLE_URL=http://blog.fefe.de/ + +# This is always overriden with a single host URL and is only provided as an example +HTTP_PROXY=http://squid2.uhi.ac.uk:8080/ + +# This needs to be high enough to weather network glitches, but not so high that we end up with multiple instances waiting to finish +TIMEOUT=30 + +# The default error code is unknown in case I haven't thought of something +ERROR_CODE=3 + +# comment this out to see the output from wget on the command line (and in the cron output) +LOG="-o /dev/null" + +# parse the command line options +# +if [ -z "$1" ]; then + echo "Usage: $0 PROXY_URL [TEST_URL] [TIMEOUT]"; + echo " PROXY_URL: The full URL (including port number and protocol) of the proxy server to be tested"; + echo " TEST_URL: The URL to attempt to load"; + echo " TIMEOUT: The time (in seconds) to wait before giving up on loading the test URL"; + echo; + exit $ERROR_CODE; +else + HTTP_PROXY=$1 +fi + +if [ ! -z "$2" ]; then + SAMPLE_URL=$2 +fi + +if [ ! -z "$3" ]; then + TIMEOUT=$3 +fi + + +# required binaries +# +WGET=/usr/bin/wget +DIFF=/usr/bin/diff +DATE=/bin/date +BC=/usr/bin/bc + +# The base timestamp used to uniquely tag the filenames as a matching set +TIMESTAMP=`$DATE +%s%N` + +# the filenames we will create +# +PROXIED_FILE="$(mktemp)" +UNPROXIED_FILE="$(mktemp)" + + +# Remove the temporary files if they already exist +# +if [ -e $UNPROXIED_FILE ]; then rm $PROXIED_FILE; fi +if [ -e $PROXIED_FILE ]; then rm $PROXIED_FILE; fi + +# Get the content directly +TIMESTAMP2=`$DATE +%s%N` +$WGET -t 1 --timeout=$TIMEOUT $SAMPLE_URL -O $UNPROXIED_FILE $LOG + +# Get the content through the proxy +TIMESTAMP3=`$DATE +%s%N` +http_proxy=$HTTP_PROXY $WGET -t 1 --timeout=$TIMEOUT -O $PROXIED_FILE $SAMPLE_URL $LOG +TIMESTAMP4=`$DATE +%s%N` + +# Compare the two files +DIFF_OUTPUT=`$DIFF $PROXIED_FILE $UNPROXIED_FILE`; + +if [ ! -s "$UNPROXIED_FILE" ]; then + echo "WARNING: The test URL does not appear to be available or is unreachable..."; + ERROR_CODE=1; +else + if [ -s "$UNPROXIED_FILE" -a ! -s "$PROXIED_FILE" ]; then + echo "CRITICAL: Could not load the content through the specified proxy server..." + ERROR_CODE=2; + else + if [ ! -z "$DIFF_OUTPUT" ]; then + echo "WARNING: The content downloaded through the proxy does not match the live content..."; + ERROR_CODE=1; + else + DIRECT_TIME=`echo "scale=2; ($TIMESTAMP3-$TIMESTAMP2)/1000000" | $BC`; + PROXIED_TIME=`echo "scale=2; ($TIMESTAMP4-$TIMESTAMP3)/1000000" | $BC`; + ELAPSED_TIME=`echo "scale=2; ($TIMESTAMP4-$TIMESTAMP2)/1000000000" | $BC`; + echo "OK: Proxy server accessible and serving up the same content as a direct link. Run completed in $ELAPSED_TIME seconds"; + echo "|'Proxy time'=${PROXIED_TIME}ms" + echo "|'Direct time'=${DIRECT_TIME}ms" + + ERROR_CODE=0; + fi + fi +fi + + + +if [ -e $UNPROXIED_FILE ]; then rm $PROXIED_FILE; fi +if [ -e $PROXIED_FILE ]; then rm $PROXIED_FILE; fi + +exit $ERROR_CODE; + +# Predefined exit codes for Nagios/NetSaint +# UNKNOWN = 3 +# OK = 0 +# WARNING = 1 +# CRITICAL = 2 diff --git a/check_wifi_stations.sh b/check_wifi_stations.sh new file mode 100755 index 0000000..389a8af --- /dev/null +++ b/check_wifi_stations.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +WWW_PATH="/cgi-bin/stations" + +while getopts ":p:h:" opt; do + case $opt in + p) + WWW_PATH="$OPTARG" + ;; + h) + HOST="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" + ;; + esac +done + +OUTPUT="UNKNOWN: Script failed" +EXIT_CODE=3 + +stations=$(curl -s http://$HOST$WWW_PATH | wc -l) +VALUE="|Stations=$stations" +OUTPUT="OK: $stations Stations" +EXIT_CODE=0 + +echo "$OUTPUT" "$VALUE" +exit $EXIT_CODE diff --git a/pollstatus.py b/pollstatus.py new file mode 100755 index 0000000..1e4e373 --- /dev/null +++ b/pollstatus.py @@ -0,0 +1,37 @@ +#!/usr/bin/python3 +import socket +import sys +from getopt import getopt + +options, args = getopt(sys.argv[1:], "h:p:") + +HOST = "localhost" +PORT = 9999 + +for o,a in options: + if o == "-h": + HOST = a + elif o == "-p": + PORT = int(a) + else: + print("unrecognized argument") + exit(2) +try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((HOST, PORT)) + s.sendall(b"status\n") + answer = s.recv(50).decode("ascii") + s.close() + if answer.strip() == "Running": + print("OK: received 'Running'") + exit(0) + elif answer.strip() == "Not running": + print("ERROR: received 'Not Running'") + exit(2) + else: + print("ERROR: received '"+answer.strip()+"'") + exit(2) +except OSError as err: + print("ERROR: Network Error") + print(err) + exit(2)