Page 1 of 2

Twitter server monitor

Posted: Thu Jul 16, 2009 8:32 am
by uipe
Before coming to Amahi I spent some time testing out WHS and one thing I came to appreciate, even with its limitations, was an addon that would send system errors to twiiter, so I decided to create a script in python that would be able to send me information about the server, has I don't run any critical applications on my server I just want to know how things are from time to time.
In twitter terms I have an account just for the server that only allows private followers ;)

This is how the message looks like :
Image

For all but upload and download I used common system calls, so you can easily change the code for your own applications the only really specific case is the up/down, as I only have an Ethernet port active, I can't use its statistics (they would get mixed up with lan usage) so I had to fetch the data from my router statistics page that uses the Tomato firmware, If you are able to use it for other routers pls post here ;)
Any suggestions and tips are really welcome!

TIPS: As the passwords are not safe I recommend that you make sure that only root can read it (chmod 711 for example as root).
Don't spam it, I for example only run it during the day and only in 4 hours interval (my crontab entrie 1 11,15,19,23 * * * /usr/local/bin/twitCron.py)

ATTENTION: this was written with the propose of getting to know python for shell scripting, this was in fact the second program I have ever written in python, I have a large experience in other languages but had never tried it, so do not yell if the code isn't the better you have ever seen...

Re: Twitter server monitor

Posted: Thu Jul 16, 2009 9:02 am
by rampage537
Very nice, I will have to give this a try sometime soon.

Re: Twitter server monitor

Posted: Thu Jul 16, 2009 12:11 pm
by cpg
This is very cool!!

We should turn this into an app!

Re: Twitter server monitor

Posted: Fri Jul 17, 2009 5:51 am
by cpg
hey there!

we implemented a notification api for amahi.org inspired by your twittercron code!

the notification is by email (to your amahi.org account email) now. later we can do twitter, not too hard.

here is one simple example of how to use it, in ruby:

Code: Select all

bash$ cd /var/hda/platform/html /var/hda/platform/html bash$ ./script/console Loading development environment (Rails 2.1.1) >> AmahiApi::api_key = Setting.get("api-key") => "this-is-my-hda's-api-key" >> te = AmahiApi::TimelineEvent.new(:kind => "network", :message => "This is my first ever Amahi notification event") and te.save => true >> bash$
i got the email below!
very coool!

now, an app to do a little plugin/app to monitor various things and send the events over the api should be fairly easy to do.
we could turn your twitCron code into a server and build a little web UI to control what things are notified.

Code: Select all

Date: Fri, 17 Jul 2009 03:02:00 -0700 From: Amahi <no-reply@amahi.org> To: [my-email] Subject: [Amahi Direct Message] network event Hi, you have a new network event from your Amahi HDA: This is my first ever Amahi notification event -- Turn off these emails at: http://www.amahi.org/user/notifications Please do not reply to this message; it was sent from an unmonitored email address.
--
edit

you will need a small patch to the amahi_api.rb code. this is part of the latest platform test rpm that you can have if you want.
otherwise , you can add these two lines before the last end closing the class in the /var/hda/platform/html/lib/amahi_api.rb

Code: Select all

class TimelineEvent < Base end

Re: Twitter server monitor

Posted: Fri Jul 17, 2009 5:54 am
by cpg
here are some ideas on what events to notify:
  • running low on available disk space
  • logins to the network and logouts (DHCP/DDNS events)
  • high temperature in disk drives
  • high temperature in the CPU
  • high CPU load?
  • server powerdown/powerup (in case of power failures, maybe UPS events?)
  • bandwidth usage
  • VPN logins/logouts
  • ...
others? :)

Re: Twitter server monitor

Posted: Fri Jul 17, 2009 6:09 am
by rampage537
services stopped, started or restarted
terminal logins, might be included in this
logins to the network and logouts (DHCP/DDNS events)

Re: Twitter server monitor

Posted: Fri Jul 17, 2009 6:43 am
by uipe
services stopped, started or restarted
terminal logins, might be included in this
logins to the network and logouts (DHCP/DDNS events)
humm I think he means physical layer events there.
I think we should keep it simple or the server admin would end up overwhelmed with info and start ignore it, we can't forget this is a home server and ppl just want to be informed of important and possible nefarious things, so the only terminal login that would be useful is root imho. Of course we can put everything there as an option for the most security "freaks" of us ;)

Re: Twitter server monitor

Posted: Fri Jul 17, 2009 11:42 am
by moredruid
I have the following command run on my webhosting server when someone logs in on the terminal (which should only be me ;)):

Code: Select all

mail -s 'Server Access' myname@domain.tld <<end $(who) $(date) end
the output what I get in my mailbox looks like this (with the subject "Server Access" so I can filter it easily):

Code: Select all

username pts/0 2009-07-17 20:38 (XXX.ISP.nl) fr jul 17 20:38:25 CEST 2009
works like a charm for me

Re: Twitter server monitor

Posted: Fri Jul 17, 2009 7:21 pm
by uipe
Well I have been studying the network monitor cause in my case i just used the monitor on my router and didn't have to worry about anything else, but other ppl may not be using an open source router, so we to have a way of monitoring the data in the server himself, as I am not a network expert I went looking for something already coded ;), first I tired vnstat and its really light and easy to use but the problem is that it doesn't have any packet filtering it isn't able to distinguish the traffic, so for people like me that just wants to know the internet traffic it isnt a viable solution. Then I tried ntop and that one is really a fantastic tool but it has a lot of futures that are mostly suited in a router/gateway not a home server (imho). Finally I came across darkstat and it really seems like the way to go, it supports all kinds of filtering and is a lot more simple and lightweight than ntop (can't find the rpm on forge had to download from here http://packages.sw.be/darkstat/darkstat ... f.i386.rpm).
Tomorrow I will try to get the data and place it on the new ruby app, but now its 3h20am and tomorrow morning I have kendo practice ;).

Re: Twitter server monitor

Posted: Sat Jul 18, 2009 8:42 pm
by gjc1000
Just say NO to Twitter.......your life will be better : )