| 1 |
PREREQUISITES: |
| 2 |
- Linux operating system ( I am using RedHat 6.2 ); |
| 3 |
- MRTG version ( I used 2.8.8 version ); |
| 4 |
- SHELL scripting language; |
| 5 |
- AWK scripting language; |
| 6 |
- FPING utility ( I used 2.2b1 ); |
| 7 |
- CRON daemon installed; |
| 8 |
- TCP/IP Network connection {:-) |
| 9 |
|
| 10 |
net-hosts |
| 11 |
|
| 12 |
I use this script to monitor internet connection state |
| 13 |
on a chosen route (from traceroute). Usage is very simple: |
| 14 |
|
| 15 |
- Put in your crontab file a line which have to be run |
| 16 |
every five (5) minute or any other time interval you want |
| 17 |
(but you have to edit, according with this new value, |
| 18 |
'make-mrtg.cfg.awk' file). I am using Linux RedHat 6.2 |
| 19 |
and in my /etc/cron.d I put a file named 'net-hosts' with |
| 20 |
the following structure: |
| 21 |
|
| 22 |
################################## |
| 23 |
# /etc/cron.d/net-hosts -rw-r--r-- |
| 24 |
# |
| 25 |
|
| 26 |
*/05 * * * * root /usr/local/mrtg/contrib/net-hosts/net-hosts |
| 27 |
|
| 28 |
# |
| 29 |
# EOF |
| 30 |
################################## |
| 31 |
|
| 32 |
- Restart your cron daemon... and wait |
| 33 |
|
| 34 |
To install, first edit the variables from both 'make-mrtg.cfg.awk' |
| 35 |
and 'net-hosts files' as needed. I found it easier to have these defined |
| 36 |
rather than hardcoded due to differences between code interpretations. |
| 37 |
|
| 38 |
You don't have to insert any other target in your own mrtg.cfg |
| 39 |
file that you already have, because this script is launced by |
| 40 |
the cron daemon. |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
internet |
| 45 |
|
| 46 |
This is the file which keep the IPs, FQDNs, dates and states |
| 47 |
for hosts you want to monitor. The format of this file is: |
| 48 |
|
| 49 |
<IP_1>:<FQDN_1>:<LAST-MODIFIED_1>:<STATE_1> |
| 50 |
<IP_2>:<FQDN_2>:<LAST-MODIFIED_2>:<STATE_2> |
| 51 |
<IP_3>:<FQDN_3>:<LAST-MODIFIED_3>:<STATE_3> |
| 52 |
. |
| 53 |
. |
| 54 |
. |
| 55 |
|
| 56 |
where: |
| 57 |
- IP_xxx is IP address (IPv4) for host xxx |
| 58 |
- FQDN_xxx is Fully Qualified Domain Name of host xxx |
| 59 |
- LAST-MODIFIED_1 is the date when the state of host xxx was last modified |
| 60 |
- STATE_1 is the current state of host xxx (1 = UP; 0 = DOWN) |
| 61 |
|
| 62 |
First time you create this file you just need IPs and FQDNs, |
| 63 |
blank dates and 1 (or 0) for the state of every hosts, like this: |
| 64 |
|
| 65 |
aaa.aaa.aaa.aaa:your.router.name::1 |
| 66 |
bbb.bbb.bbb.bbb:yourISP.router.name::1 |
| 67 |
. |
| 68 |
. |
| 69 |
. |
| 70 |
zzz.zzz.zzz.zzz:that.host.name::1 |
| 71 |
|
| 72 |
HINT: You could have an ordered list using traceroute and |
| 73 |
awk (or any other shell-script). |
| 74 |
|
| 75 |
The file 'internet' shipped with this package it is |
| 76 |
a demo. |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
make-mrtg.cfg.awk |
| 82 |
|
| 83 |
This is the core of the entire task. Here I make 'mrtg-awk.cfg' |
| 84 |
file using the content of 'internet' file and the state read |
| 85 |
from fping utility (Fast Ping - it was not written by me...). |
| 86 |
After doing this, internaly is lauched 'mrtg' executable |
| 87 |
for net-hosts's mrtg.cfg file (named 'mrtg-awk.cfg'). |
| 88 |
Of course, it is created a file, 'internet.html', used |
| 89 |
like an index file for the all targets in 'mrtg-awk.cfg', |
| 90 |
but you could use 'indexmaker' script provided with MRTG |
| 91 |
for doing this (see an example in 'net-hosts'). |
| 92 |
|
| 93 |
Be aware ! You have to place icons (MRTG) and image files |
| 94 |
(grnball.gif, redball.gif, cubprev.gif) in the same |
| 95 |
location. You also have to place 'net-hosts.css' into declared |
| 96 |
location inside that AWK script file. |
| 97 |
|
| 98 |
|
| 99 |
---------- |
| 100 |
|
| 101 |
Direct questions or suggestions to me. |
| 102 |
|
| 103 |
Have fun! |
| 104 |
|
| 105 |
-Adrian Turcu <[email protected]> |
| 106 |
|
| 107 |
|
| 108 |
|