-
Console Network Monitoring Program
I've searched quite a few different sites, but I haven't been able to find anything that will fit my needs. I'm looking for a console based network monitoring script. I want to be able to setup roughly 30 hosts to be shown in a console (tty9 preferably) that just does a simple ping to tell when they are up or down. Green means up, red means down. Something simple. Anybody know of a program / script (shell, perl...) that I can use to accomplish this?
Thanks,
Jason Bush
-
you already have a vision of what you want in your head, so finding something to fill that vision will be difficult, i would suggest, nagios/cacti and using snmp for this
but if your heart is so set, then write your own script, its not that hard
-
I really do have to stick with ping, and after giving up in my search, I've started to write my own script. Here is what I have so far:
nms (the main script):
Code:
#!/usr/bin/perl
use Net::Ping;
use Term::ANSIColor;
$data_file="nms.systems";
open(DAT, $data_file) || die("COULD NOT OPEN SYSTEMS FILE");
@raw_data=<DAT>;
close(DAT);
foreach $system (@raw_data)
{
chop($system);
($ipaddr,$identity,$row,$col)=split(/\|/,$system);
$p=Net::Ping->new("icmp");
if ($p->ping($ipaddr)) {
print color("green"),"System is up, column is $col, row is $row, identified as $identity.\n",color("reset");
} else {
print color("red"),"System is down, column is $col, row is $row, identified as $identity.\n",color("reset");
}
}
Then there is the nms.systems file that has the information for the systems:
Code:
127.0.0.1|localhost|3|56
127.0.0.1|localhost|6|8
127.0.0.1|localhost|6|20
127.0.0.1|localhost|6|32
127.0.0.1|localhost|6|44
127.0.0.1|localhost|6|56
127.0.0.1|localhost|6|68
127.0.0.1|localhost|9|8
127.0.0.1|localhost|9|20
127.0.0.1|localhost|9|32
127.0.0.1|localhost|9|44
127.0.0.1|localhost|9|56
128.0.1.1|localhost|9|68
I made the last one 128 so that it would represent a down system, so far so good. Now I've got to make the output pretty.
-
Can U send us a screen shot when it is done? PLus the full script
-
Yea, I'll post the source with a screen shot when done. I'm headed out shortly for Christmas break, but I'm working on this at work, for work, so it'll get done early next week sometime.
-
thanks for participating in the OSS community
-
Yeah, I discovered that sometimes with these relatively simple network monitoring things it's easier to write a script than find software that does it. Most network monitoring apps these days are way overkill for simple ping tests. I wrote one a while back to test the ping times of all of the systems on a given network segment to see if there are bottlenecks in our LAN party network. Hard to find software that will give you a simple readout of that information, but writing the script didn't take long at all.
-
Yea, I completely agree. I just figured this would have been a common request from people and it would have already been done. Once I get to work on Tuesday, I'll give the formatting of it a go. I'm learning how to do this as I go (I've some background in programming, but not much at all), and I was told to give the perl write function a look for formatting of the output. Anybody else have any tips before I tackle this?
-
I've got a working script, except for being able to run it on /dev/tty9 every minute, it is done. If you all know anything about perl, check out http://justlinux.com/forum/showthread.php?t=147940
-
I have it all working now, thanks for your help and suggestions. Below is my finished script.
nms.pl (main script)
Code:
#!/usr/bin/perl
use Net::Ping; # Module to check a remote host for reachability
use Curses; # Module to allow the use of system's curses
sub create_newwin {
$local_win = newwin(shift, shift, shift, shift);
box($local_win, 0, 0);
refresh($local_win);
return $local_win;
}
$data_file="/etc/nms.systems"; # File which holds network node data
open(DAT, $data_file) || die("COULD NOT OPEN SYSTEMS FILE: $!");
@raw_data=<DAT>; # Array for holding node data
close(DAT);
$screen="/dev/tty9";
open(SAVEOUT, ">&STDOUT") || die("COULD NOT DUP STDOUT: $!");
open(STDOUT, ">", $screen) || die("COULD NOT REOPEN STDOUT ON $screen: $!"); # Redirects standard output to $screen
initscr(); # Show header
start_color();
init_pair(1, COLOR_CYAN, COLOR_BLACK);
attron(COLOR_PAIR(1));
addstr(1, ($COLS -9) /2, "Networked");
addstr(2, ($COLS -14) / 2, "Systems Status");
attroff(COLOR_PAIR(1));
raw();
refresh();
foreach $system (@raw_data)
{
chop($system);
($ipaddr,$identity,$row,$col)=split(/\|/,$system);
$p=Net::Ping->new("icmp");
if ($p->ping($ipaddr,1)) {
$height=4;
$width=10;
$starty = $row -1;
$startx = $col -1;
start_color();
init_pair(2, COLOR_GREEN, COLOR_BLACK); # If system is up, show output as green
attron(COLOR_PAIR(2));
$my_win = create_newwin($height, $width, $starty, $startx);
addstr($row, $col, "$identity"); # Output information to specific location
addstr($row+1, $col, " UP");
attroff(COLOR_PAIR(2));
} else {
$height=4;
$width=10;
$starty = $row -1;
$startx = $col -1;
start_color();
init_pair(3, COLOR_RED, COLOR_BLACK); # If system is down, show output as red
attron(COLOR_PAIR(3));
$my_win = create_newwin($height, $width, $starty, $startx);
addstr($row, $col, "$identity"); # Output information to specific location
addstr($row+1, $col, " DOWN");
attroff(COLOR_PAIR(3));
}
refresh();
}
endwin();
close(SAVEOUT);
close(STDOUT);
sleep 30;
exec "/sbin/nms.pl";
nms.systems (systems to monitor)
Code:
127.0.0.1|gateway1|1|16
127.0.0.1|gateway2|1|56
127.0.0.1|system01|5|2
128.0.0.1|system02|5|16
127.0.0.1|system03|5|30
127.0.0.1|system11|5|42
127.0.0.1|system12|5|56
127.0.0.1|system13|5|70
127.0.0.1|system04|9|2
127.0.0.1|system05|9|16
127.0.0.1|system06|9|30
127.0.0.1|system14|9|42
127.0.0.1|system15|9|56
127.0.0.1|system16|9|70
127.0.0.1|system07|13|2
127.0.0.1|system08|13|16
127.0.0.1|system09|13|30
127.0.0.1|system17|13|42
127.0.0.1|system18|13|56
127.0.0.1|system19|13|70
127.0.0.1|system10|17|2
127.0.0.1|system20|17|42
127.0.0.1|system21|17|56
127.0.0.1|system22|17|70
127.0.0.1|system23|21|42
127.0.0.1|system24|21|56
The numbers at the end of the nms.systems file are the row number, and then column number. Maybe someone else can use this script. For it to work, you'll need to put the nms.pl file in /sbin and the nms.systems file in /etc... or modify the script to look elsewhere.
Also, it uses the perl-curses library and net ping library. In order to see what it's output, you'll need to look on terminal 9, which you can view by hitting, CTRL+ALT+F9.
Last edited by jrbush82; 12-30-2006 at 12:33 AM.
-
do you have a screenshot of the output?
-
Screenshot:
-
Nice!
I too wrote a server monitoring tool a few years ago, but he output is nothing as fancy as what you have created. It attempts to make a (SOCK_STREAM ) connection to a host, on a user specified port ( multiple ports per host ). If the port is closed it logs it and sends and email to a user specified address ( or multiple addresses ). If the closed port re-opens, it will make a log entry and send another message.
I wrote it originally because I wanted to know when the Ultima Online server I was running a macro on went down, and came back up ( so I could restart my macro ). However, I ended up tweaking it some more and using it at 2 of my past jobs. It does what I needed it to do, and it's written in C.
You can get it here: http://www.crankhouse.com/scheck.php
Thanks,
gooon12
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|