Commit cca2113d8cf91053f881024491fef621c1ca2a61
1 parent
5458527c
added cgi-bin/nagiosstatus.sh
Showing
2 changed files
with
70 additions
and
4 deletions
README.md
1 | nagios-plugins | 1 | nagios-plugins |
2 | ============== | 2 | ============== |
3 | This repository contains my collection of modified and custom written check | 3 | This repository contains my collection of modified and custom written check |
4 | -plugins for [Nagios](http://www.nagios.org). | 4 | +plugins and scripts for [Nagios](http://www.nagios.org). |
5 | 5 | ||
6 | -Most of these are modified versions of standard plugins or very custom so | ||
7 | -distributing them through [NagiosExchange](https://exchange.nagios.org/) is | 6 | +Most of these are very custom solutions or modified versions of standard plugins |
7 | +so distributing them through [NagiosExchange](https://exchange.nagios.org/) is | ||
8 | not really appropriate. I am publishing them separately so that others may | 8 | not really appropriate. I am publishing them separately so that others may |
9 | benefit from these as well. Use them freely and please let me know is you | 9 | benefit from these as well. Use them freely and please let me know is you |
10 | encounter any issues or require changes. | 10 | encounter any issues or require changes. |
@@ -18,7 +18,7 @@ License, see [below](#license) | @@ -18,7 +18,7 @@ License, see [below](#license) | ||
18 | 18 | ||
19 | plugins/check_memory | 19 | plugins/check_memory |
20 | -------------------- | 20 | -------------------- |
21 | -nagios check script to monitor the memory on Linux systems. Due to changes in | 21 | +Nagios check script to monitor the memory on Linux systems. Due to changes in |
22 | the output of procps v3.3 (the changelog refers to it as modernizing it), it's | 22 | the output of procps v3.3 (the changelog refers to it as modernizing it), it's |
23 | output changed and breaks the the check_memory script as shipped with many linux | 23 | output changed and breaks the the check_memory script as shipped with many linux |
24 | distributions. This version supports both the old and the new format so that | 24 | distributions. This version supports both the old and the new format so that |
@@ -26,6 +26,20 @@ is indifferent of which version of procps (to date) is used. No other changes | @@ -26,6 +26,20 @@ is indifferent of which version of procps (to date) is used. No other changes | ||
26 | were made to the script. | 26 | were made to the script. |
27 | 27 | ||
28 | 28 | ||
29 | +cgi-bin/nagiosstatus.sh | ||
30 | +----------------------- | ||
31 | +Very simplistic CGI-BIN script that checkes whether nagios is still running and | ||
32 | +still updating its status. It wil always return an HTTP Status 200 (OK) and a | ||
33 | +simple text page with one of the following texts: | ||
34 | + - STOPPED - in case the nagios process is not running | ||
35 | + - STALLED - in case the nagios status file has not been updated for 5 minutes | ||
36 | + - OK - when Nagios is running and updated its status file < 5 minutes ago | ||
37 | + | ||
38 | +I wrote this script to be used with an external monitoring system, I use it with | ||
39 | +the free subscription from [Pingdom](http://www.pingdom.com) to get alerts when | ||
40 | +my Nagios monitoring system is no longer reachable. | ||
41 | + | ||
42 | + | ||
29 | <a name="license">License</a> | 43 | <a name="license">License</a> |
30 | ----------------------------- | 44 | ----------------------------- |
31 | These scripts, documentation & configration examples are free software: you can | 45 | These scripts, documentation & configration examples are free software: you can |
cgi-bin/nagiosstatus.sh
0 → 100755
1 | +#!/bin/bash | ||
2 | +# | ||
3 | +# nagiosstatus.sh - simple CGI-BIN script checking the Nagios process status | ||
4 | +# | ||
5 | +# Version 1.0, latest version, documentation and bugtracker available at: | ||
6 | +# https://gitlab.lindenaar.net/scripts/nagios-plugins | ||
7 | +# | ||
8 | +# Copyright (c) 2015 Frederik Lindenaar | ||
9 | +# | ||
10 | +# This script is free software: you can redistribute and/or modify it under the | ||
11 | +# terms of version 3 of the GNU General Public License as published by the Free | ||
12 | +# Software Foundation, or (at your option) any later version of the license. | ||
13 | +# | ||
14 | +# This script is distributed in the hope that it will be useful but WITHOUT ANY | ||
15 | +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
16 | +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
17 | +# | ||
18 | +# You should have received a copy of the GNU General Public License along with | ||
19 | +# this program. If not, visit <http://www.gnu.org/licenses/> to download it. | ||
20 | + | ||
21 | +# Default settings for Debian Linux, adjust for your system if necessary | ||
22 | +PROGRAM=nagios3 | ||
23 | +PIDFILE=/var/run/nagios3/nagios3.pid | ||
24 | +STATFILE=/var/cache/nagios3/status.dat | ||
25 | +MAXAGE="5 minutes" | ||
26 | + | ||
27 | +# First output the HTTP header | ||
28 | +DATE=`date -R` | ||
29 | +cat << EOH | ||
30 | +Status: 200 OK | ||
31 | +Content-Type: text/plain | ||
32 | +Date: $DATE | ||
33 | +Expires: $DATE | ||
34 | +Last-Modified: $DATE | ||
35 | +Cache-Control: no-cache | ||
36 | +Connection: close | ||
37 | + | ||
38 | +EOH | ||
39 | + | ||
40 | +# Check whether the process is running | ||
41 | +if [ -f "$PIDFILE" -a "$PROGRAM" = `ps --no-header -o comm -p \`cat $PIDFILE\`` ]; then | ||
42 | + # It's running, check whether the Statfile exists and is recent | ||
43 | + if [ -n "$STATFILE" -a -n "$MAXAGE" -a -f "$STATFILE" -a \ | ||
44 | + `stat -c %Y $STATFILE` -lt `date +%s -d "$MAXAGE ago"` ]; then | ||
45 | + echo STALLED | ||
46 | + else | ||
47 | + echo OK | ||
48 | + fi | ||
49 | +else | ||
50 | + echo STOPPED | ||
51 | +fi | ||
52 | + |