Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Script to send an email if your server is down
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Script to send an email if your server is down

netomxnetomx Moderator, Veteran
edited November 2011 in Tutorials

Hello, I made a script that emails me if my backup server is off, and then email me if it gets back on. It is pretty simple BUT this is an ALPHA RELEASE !

REQUIREMENTS:
Linux
PHP with PEAR (and PEAR needs mail, net_smtp)
A SMTP server
Backup VPS (like 10 a year ones)

Main script (put it on the server you DONT WANT TO check if it is down): http://paste2.org/p/1770117
The mandaemail.php script: http://paste2.org/p/1770124

Then, just make chmod a+x on the main script and add it to your cron to run the script every minute.

EDIT:
Poject's here, with Wiki!
http://code.google.com/p/vps-email-status/

Thanked by 4Go59954 LES Spirit camarg

Comments

  • Go59954Go59954 Member
    edited November 2011

    Why there's a password of ours required to be included inside the "mandaemail.php script"?!

    Can't the email be sent without it?!

  • Excuse me if that's silly, but when I saw a password in the settings I felt that's fishy :p If I can know which parameters in both php scripts needs modification that would be really good.

  • I cannot access any of the above mentioned paste2.org links :(

  • @Go59954 said: Why there's a password of ours required to be included inside the "mandaemail.php script"?!

    Can't the email be sent without it?!

    The password is for authenticating to your SMTP server. This eliminates the need for you to have an MTA such as sendmail installed on your monitoring server.

  • netomxnetomx Moderator, Veteran
    edited November 2011

    Damn... when I saw the first post, I thought: damn, I didnt erase my password! But then I noticed I got it wrong haha.

    Asim, do you want the files in a zip ???

    EDIT: If you want, I can reorganize the code and make a config.php file to include just the things you need to modify, is that ok?

  • netomxnetomx Moderator, Veteran
    edited November 2011

    There you go:

    http://code.google.com/p/vps-email-status/

    With a wiki :)

    EDIT:

    Interesting, maybe I can make this script send an email every X hours sending general information, like CPU, Memory, HDD, Speedtests and pings to a server, like Google... I'm gonna tell you this night if I will make that. Any suggestions?

    Thanked by 2Go59954 Asim
  • Go59954Go59954 Member
    edited November 2011

    Thank you =) And yeah it would be great and would help someone if you ever added more stuff :)

    My suggestion I think would be better if (but, maybe much more work for you) if it's with a database (or a flat file), where these tests are done every short time like 30 sec or 1 min interval, and an average is then produced and sent by email whether as raw data (e.g. RAM average: 250 mb), or analyzed by some sort like a graph made with letters is produced (e.g. using * or # symbols). Then after sending the email every hour+ saving the same report in another database / file (in case emails are not sent for some reason, and where archive is better be accessible through a webpage), after that, the short interval data at the first database/file is overwritten with data records of next hour. Or not overwritten if file size doesn't matter. Just my 2cents ;)

  • SpiritSpirit Member
    edited November 2011

    @netomx said: Any suggestions?

    More servers! Possibility to include monitoring of more than one vps.

    @Go59954 said: My suggestion I think would better (but, maybe much more work for you) if it's with a database.. or analyzed by some sort like a graph...

    No, no... as less as possible complications, dependencies, services... It's plenty advanced monitoring tools out there already. We don't need another one which would require databases, webserver, whatever...

    Simple script which would send notification... and maybe some additional infos with as less as possible requirements... sounds perfect.

  • Go59954Go59954 Member
    edited November 2011

    @Spirit Don't worry it's still simple (I'm guessing) since no bandwidth or log file analysis is involved, but more services, maybe :) even though the suggestion is to include a simple (not too accurate) letters graph, like Bmon's graph: http://linuxers.org/sites/default/files/content/misc/bmon7.png , even though that's a realtime graph, while the required one is just a static one based on 1 hour data.

  • Go59954Go59954 Member
    edited November 2011

    and maybe some additional infos with as less as possible requirements... sounds perfect.

    My thought is, that RAM+CPU+HDD..etc "read" is instant, so will it be that useful to know that read of 1 second in every hour? So I thought of saving them every short interval in a file and get the average every hour. But I found it not that helpful for knowing if there was, for instant, a spike in CPU within the hour, at least with short spikes. So I suggest also the graph thing based on same data.

    An average though is needed in my opinion, unlike the graph thing.

  • netomxnetomx Moderator, Veteran

    Yeah, something like this http://backup.neto.mx ?? But like with an hour basis? I was thinking about that, too.

    And Spirit, multiple servers sounds like a very good idea! Let me try to finish today :)

    And about the graphs, sounds very good too, as a plugin, but I may make it later on, I think multiple servers and information mails may be a better improvement.

  • netomxnetomx Moderator, Veteran

    UPDATE: I have fixed critical bugs: it wasn't even running!

    Added: Reports (very simple, just to test them) to email every hour (tweakable).

    Any ideas to include in the reports?

    Several servers are coming!

  • netomxnetomx Moderator, Veteran

    UPDATE: v0.3
    Fixed: ping problems
    Added: Multiple servers !

  • netomxnetomx Moderator, Veteran

    UPDATE:

    v0.4

    Fixed: HDD Space

    Added: Number of ping retries before sending email of server down

    Please report suggestions, errors, etc!

  • netomxnetomx Moderator, Veteran

    Update, check the changes, it should work fine now!

Sign In or Register to comment.