Project: Arduino Server/Service Monitor

lit_blueWhat I’ve completed:

I’ve successfully written a bash script that runs once every minute. The script detects whether or not my server is online by issuing a simple ping request. Based on results of the ping request(s), the arduino will display a green LED when the server is online or a red LED if the server is offline. **UPDATE** I now have the project reporting when a new email comes into my gmail account.

What’s Left:

I’d like to take this circuit off the arduino and put it in a nice display. Any suggestions are appreciated.

What I’ve Learned:

  1. Values can be passed to the arduino through a serial connection by echoing to /dev/ttyUSB0 (this could be different based on your configuration
  2. /dev/ttyUSB0 needs to have write permissions
  3. How to handle data sent to the arduino in a useful manner

The Code:

Upload the following to your arduino:

/*Set the appropriate pins for your LEDs*/
int GreenPin = 13;
int RedPin = 8;
int val = 0;
 
void setup() {
 
/*Set the Serial Speed and the Pins for Outputmode*/
  Serial.begin(9600);
  pinMode(GreenPin, OUTPUT);
  pinMode(RedPin, OUTPUT);
}
 
/*Function to set the lights when the server is offline*/
int Server_Down() {
      digitalWrite(GreenPin,LOW);
      digitalWrite(RedPin,HIGH);
  }
 
/*Function to set the lights when the server is online*/
int Server_Up() {
    digitalWrite(GreenPin,HIGH);
    digitalWrite(RedPin,LOW);
}
 
void loop () {
/*Read in the value passed to the arduino*/
  val = Serial.read();
 
/*If '0' is passed to the arduino from the script, execute the Server_Down function*/
  if (val == '0') {
     Server_Down();
  }
 
/*If '1' is passed to the arduino from the script, execute the Server_Up function*/
  if (val == '1') {
     Server_Up();
  }
}

Heres the bash script, set the script to executable (chmod +x [filename]):

#!/bin/bash
 
#Find the hosts state
Host_Status=`ping -c 4 burnsforce.com | grep bytes | wc -l`
 
#The following is for debugging, take it out for effecient code
echo $Host_Status
 
# A value of 5 means the host is up, turn on the green light, otherwise turn on the red light
if [ "${Host_Status}" == "5" ]; then
 
             #Sends a value of '1' to the arduino, telling it the server is up
             echo 1 > /dev/ttyUSB0
 
        else
 
             #Sends a value of '0' to the arduino, telling it the server is down
             echo 0 > /dev/ttyUSB0
        fi

Setup Crontab:

You’ll want to set the script on a crontab to actually monitor the server (Mine is setup to run once every minute). Open up Crontab with the following command:

[root@host]# crontab -e

Add the following line to the crontab:

* * * * * bash /root/ping.sh > /root/results.txt  #sets a log file for troubleshooting

Pictures Of The Project:

arduinagiosarduino_nagios_online_2arduino_nagios_offlinearduino_nagios_offline_2

Final Project Photos:

Click Here for the guide on making the lava lamp housing. Unfortunately, the true beauty of this project doesn’t come out in the below photos. In reality, the colors are much more vibrant. Let me know what you think! proj_1proj_2proj_3proj_0lit_bluelit_redlit_green

  1. No comments yet.

  1. March 8th, 2009
You must be logged in to post a comment.