I was busy writing different scripts for image installation when I had the idea to create a script would query the network and make a web page for viewing. This script is a ping monitor, it currently doesn’t use any other protocols. I wrote this to allow me to see systems that were up without having to VPN into the network to see what Nagios was saying. I had never wrote anything in Perl before and wanted to give it a try. Today with Google and other online resources there is no reason that almost everyone can write a script, program, or some kind of code with no experience in that language. It is also dependant on whether you understand the basics of programs and how they should flow. So once you look at my script you will see some of my inexperience with Perl in the way some of the code is system calls verses a all Perl syntax.
Anyhow back to my script. The script was written on a Linux system and I have had it running for a good 3 months on a VM just pinging away. It can currently only do one sub-net but if I don’t get bored with it I may expand it. It is started with a shell script but doesn’t have to be. I did this so I could add a start/stop entry into the log file that it creates. So if you don’t care for it you can start it without the shell script.
The script has a few text based menus that I put in to allow a person to select certain things like what subnet, where to write the index.html file, and how many machines to put in a row on the web page. I have alway done these little menus to help people use the script without really understanding what it is doing.
Once the script has started you have to leave the terminal open or send it to the background with Linux commands. I have thought of a ways to make it go to the background once it starts but have not been motivated enough to change it. The script will will do a full scan of the network every 5 to 10 minutes depending on what you enter for check times. Meaning that is will ping everything at the time you specify but will do a full network rescan 5 or 10 minutes to catch systems that have just come online and to keep systems that have went offline on the webpage. So lets go through the flow of the script.
You will have to untar the file and keep the folders that are in there. I am planing to have the script itself do the folder creation just have not gotten to it yet. So with the files in place the script will run out of the folder you untar’d it to. You will start the script in a bash terminal using ./start.sh or perl ./PATH/NetMon.pl. Now I will run you through the menus. The first one on the left is the menus you end the sub-net. You will simple enter the first 3 octets. The next menus will be the location if the web page. It defaults to the web folder inside the installation directory but can be changed. This is so you can send it to a share or a web servers directory for others to look at. Last will be the number of icons in a row on the web page. This was put into place to help with systems with different resolution and to keep symmetry in the look. Once these configs are done the script will begin pinging the sub-net.
The web page is created by the script by simply writing text to a file. The file is then has a symlink to the index.html at the location put into the location menu. The web page will refresh every 15 seconds to allow for timely information update even if the script only checks systems every 10 minutes.
As you can tell I made this page. I just copied syntax to create more icons for the pic. The most systems I have monitored with this was around 70. Just because I don’t have a ton of systems on my network. So I understand that it doesn’t have features of programs like nagios, but this is a script that can run in a terminal. Plus the most network bandwidth I have seen this use is 35 Kbps and that was when it was scanning.
I am currently adding the ability to scan more than one sub-net and I want it to be able to notify someone if you are not watching the screen. I have also considered changing the initial discovery to use ARP but the Perl plugin for that feature isn’t being developed anymore and I have nothing but problems with it. I also want the script to move to the back ground once it hit a certain point in the script. But you can run it with the nohup command and you can close the terminal and it stays running.
Finally I have been working on the script creating the directories that it needs once you run it the first time. Then it will just check anytime it is restarted. This is just something that I play with theses days to see how well I can get this to work. It may not be useful for large networks but it is something simple that can be run as a process on a Linux machine that can publish the web page to a web server to monitor systems from anywhere. I will add the files for download so anyone can download if they want.