menuimage

Description

Usage

Example

Options

Conf_file

Conf_file_Example

Further_information

License

Changelog

Download

My_Other_Sites

My_Programs

Comments

tiny-device-monitor v3.3 [23 Nov 2016] by Dominic

Description

tiny-device-monitor.sh is a lightweight network monitoring program - see https://en.wikipedia.org/wiki/Network_monitoring, and runs under Linux or (with Cygwin) Windows. It's called 'tiny' because it's little, but sometimes the best things come in small packages!

Based on the conf file you create (one line per device - example below), it checks a list of machines and/or webpages for a response i.e. that they are live. For a webpage, it uses wget to check that the response includes some specified key_text; otherwise, it uses ping or, if a port number is specified, nmap.

It can be used for testing internet or intranet websites, local or remote servers / computers, and peripherals such as printers, switches, wireless access points etc.

It can be run with -cq as a cron job at regular intervals, say every 5 minutes, and it will generate some text as a warning if they go offline - cron can then send this to you as an email.

Usage

tiny-device-monitor.sh [options] [conf_file]

Example

./tiny-device-monitor.sh -q

Options

-c report only a change in status i.e. from failure to success or vice-versa
-f force mode - test all sites, including subtests that would normally be excluded
-h see this help text and exit
-l see changelog and exit
-s with -c option, report a failure only if it is repeated a consecutive time
-v verbose text output
-q quiet - text output only for a failure or status change

Conf_file

conf_file (default is tiny-device-monitor.conf in same directory as the running instance of tiny-device-monitor.sh) contains text lines with 2-4 fields like this (where square brackets indicate optional text):

[+/-]address[:[U]port] reportname [key_text] [wget_options]

- if address begins with 'http', or is 'ditto', then it is a website test: wget is used to retrieve the page which is then tested for key_text (see below)
- if address is 'ditto' (without the single quotes) then the page downloaded for the most recent http test in this session is re-used as the source for this test - so you can perform multiple tests on the same web page without having to download it repeatedly
- if a port number is specified (format address:[U]portnumber), nmap is used (precede port number with U for UDP, otherwise TCP) - any key_text and wget_options will be ignored
- if none of the above apply, ping is used - any key_text and wget_options will be ignored
- if address is preceded by a plus or minus sign then it is a 'subtest', which is carried out only if the preceding non-subtest succeeded (+) or failed (-). Note that -f command-line option forces all subtests to be carried out regardless.

- reportname is the device's 'friendly' name i.e. that will appear in reports; any spaces in it must be escaped with \

- key_text is only required and used for webpages (i.e. with wget) and the retrieved data is tested to check that the key_text is present; the test is case-sensitive, and spaces in key_text (or in reportname) must be escaped with \, not with quotes ("). Any characters that would need to be escaped anyway will need to be double escaped with \\. Tests are performed using sed -n, prefixing '/' and suffixing '/p', so searching is sed regex-compatible. You can perform more sophisticated (e.g. multiline) tests by starting key_text with /, and expecting output only if the test is successful, e.g. to search for the word 'Registered' in the line after 'sip.voicetrading.com', use this key_text: /sip\\.voicetrading\\.com/{N;/Registered/p}

- wget_options are additional options if any for wget e.g: --http-user=myusername --http-password=mypassword

- a blank line, or any text after (and including) a hash (#), is ignored
- exit code 99 indicates one or more destination failures

Conf_file Example

# seek key_test 'Forbidden' on my webserver (lan-facing)
http://127.0.0.1/ internal Forbidden
# seek key_text 'My Greatest Web Site' on my webserver (wan-facing)
# (note the escaping of spaces!)
http://my.wan.ip my\ wan\ ip My\ Greatest\ Web\ Site
# if wan-facing test fails, ping-test my router lan-facing
-192.168.1.2 my_router_lan_side
# check my local network printer
192.168.1.109:9100 My\ Printer

Further information

When checking a webpage, tiny-device-monitor.sh checks both the page output and any output from wget - including error text - for the presence of the key_text. The downside of this is that you must guard against using a keyword that might appear unexpectedly anywhere in wget's output, but the upside is that that you can also check for specific error words. In particular, for password-protected sites, you can look for keywords returned by the site upon unauthorized access. This can be quicker than passing through the authorization username and password and means you do not have to put this sensitive data in the conf_file. For example:

http://my.cctv.website.com MyCCTV 401\ Authorisation\ Required

instead of

http://my.cctv.website.com MyCCTV i-Catcher --user=fred --password=bloggs

A permanent results log is maintained at /var/log/tiny-device-monitor.sh.log - the directory can be modified by setting $LOG.
Temporary files during the run are stored at (and, unless the run is aborted, deleted from) /tmp - this can be modified by setting $TMPDIR.
Files recording the most recent results are stored at /var/tmp/*-new.log and /var/tmp/*-old.log for use by the -c option test.
Note that other users on the same system may be able to read these files.

License

Copyright © 2017 Dominic Raferd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Changelog

3.3 [23 Nov 2016]: remove ssh option that was added at 3.2
3.2 [15 Nov 2016]: nmap skips ping scan, prevents some false positives, add ssh option
3.1 [30 Sep 2016]: some log messages were going to a wrongly-named log file
3.0 [22 Sep 2016]: remove debug message that appeared in non-debug mode
2.9 [16 Jul 2016]: change names and locations of temporary/log files
2.8 [18 Nov 2015]: add 'ditto' option to allow multiple checks on a webpage, use sed -n for pattern matching and allow complex and/or multiline testing, use uniquely-named temporary files
2.7 [02 Sep 2015]: allow http redirects but require certificate checks
2.6 [14 Aug 2015]: port-based test (nmap) bugfixed
2.5 [13 Aug 2015]: subtest (+/-) options bugfixed
2.4 [14 Jul 2015]: -s option bugfixed
2.3 [01 Jul 2015]: add -s option
2.2 [18 May 2015]: tidy up a couple of temporary files after successful conclusion
2.1 [14 May 2015]: report nmap 'open|filtered' UDP ports 'Failed', not 'Found'
2.0 [16 Jul 2014]: remove '--open' switch from nmap so it works with older versions of nmap, add UDP port test option
1.9 [18 Mar 2014]: renamed from 'websites-live-checker' to 'tiny-device-monitor' which better reflects its purpose, help text updated
1.8 [27 Nov 2013]: make change-in-status testing a command-line option, add force subtesting option, add subtest conditional on success (+ or -) - note changes required to any prior conf files, help updated
1.7 [02 Sep 2013]: small improvement to output text
1.6 [15 May 2013]: improved output text
1.5 [14 May 2013]: small change to help and output text
1.4 [24 May 2012]: small improvement to output text
1.3 [14 May 2012]: small improvement to conditional testing
1.2 [01 May 2012]: add '+' conditional test
1.1 [08 Mar 2012]: improved help text
1.0 [21 Sep 2011]: now compatible with cygwin & for non-privileged user

Download tiny-device-monitor.sh

My Other Sites

My Programs

Here is a selection of some (other) programs I have written, most of which run from the command line (CLI), are freely available and can be obtained by clicking on the links. Dependencies are shown and while in most cases written for a conventional Linux server, they should run even on a Raspberry Pi, and many can run under Windows using Cygwin. Email me if you have problems or questions, or if you think I could help with a programming requirement.

Backup Utilities

Debian/Ubuntu kernel and LVM Utilities

Dellmont / Three / Giffgaff / Vodafone - VoIP and Mobile Phone Account Utilities

Miscellaneous Programs

Comments

No comments yet
*Name:
Email:
Hide my email
*Text:
 
Powered by Scriptsmill Comments Script