Twitter server monitor

uipe
Posts: 3
Joined: Tue Jul 14, 2009 5:13 pm

Twitter server monitor

Postby uipe » Thu Jul 16, 2009 8:32 am

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...
Attachments
twitCron.py.zip
V1 of twirCron a server monitor script using Twitter
(1.63 KiB) Downloaded 251 times

rampage537
Posts: 124
Joined: Mon Jun 29, 2009 9:41 am
Location: Hazel Park, MI
Contact:

Re: Twitter server monitor

Postby rampage537 » Thu Jul 16, 2009 9:02 am

Very nice, I will have to give this a try sometime soon.
Testmaster Manager
Amahi HDA Custom Dual 2.7 GHz, 3 GB DDR2 (667MHz) Ram, 80GB HDD for OS + 1TB and 320GB HDD for Share Drives

User avatar
cpg
Administrator
Posts: 2618
Joined: Wed Dec 03, 2008 7:40 am
Contact:

Re: Twitter server monitor

Postby cpg » Thu Jul 16, 2009 12:11 pm

This is very cool!!

We should turn this into an app!
My HDA: Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz on MSI board, 8GB RAM, 1TBx2+3TBx1

User avatar
cpg
Administrator
Posts: 2618
Joined: Wed Dec 03, 2008 7:40 am
Contact:

Re: Twitter server monitor

Postby cpg » Fri Jul 17, 2009 5:51 am

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
My HDA: Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz on MSI board, 8GB RAM, 1TBx2+3TBx1

User avatar
cpg
Administrator
Posts: 2618
Joined: Wed Dec 03, 2008 7:40 am
Contact:

Re: Twitter server monitor

Postby cpg » Fri Jul 17, 2009 5:54 am

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? :)
My HDA: Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz on MSI board, 8GB RAM, 1TBx2+3TBx1

rampage537
Posts: 124
Joined: Mon Jun 29, 2009 9:41 am
Location: Hazel Park, MI
Contact:

Re: Twitter server monitor

Postby rampage537 » Fri Jul 17, 2009 6:09 am

services stopped, started or restarted
terminal logins, might be included in this
logins to the network and logouts (DHCP/DDNS events)
Testmaster Manager
Amahi HDA Custom Dual 2.7 GHz, 3 GB DDR2 (667MHz) Ram, 80GB HDD for OS + 1TB and 320GB HDD for Share Drives

uipe
Posts: 3
Joined: Tue Jul 14, 2009 5:13 pm

Re: Twitter server monitor

Postby uipe » Fri Jul 17, 2009 6:43 am

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 ;)

User avatar
moredruid
Expert
Posts: 791
Joined: Tue Jan 20, 2009 1:33 am
Location: Netherlands
Contact:

Re: Twitter server monitor

Postby moredruid » Fri Jul 17, 2009 11:42 am

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
echo '16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D2173656C7572206968616D41snlbxq' | dc
Galileo - HP Proliant ML110 G6 quad core Xeon 2.4GHz, 4GB RAM, 2x750GB RAID1 + 2x1TB RAID1 HDD

uipe
Posts: 3
Joined: Tue Jul 14, 2009 5:13 pm

Re: Twitter server monitor

Postby uipe » Fri Jul 17, 2009 7:21 pm

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 ;).

gjc1000
Pro User
Pro User
Posts: 133
Joined: Sat Jan 03, 2009 8:30 am

Re: Twitter server monitor

Postby gjc1000 » Sat Jul 18, 2009 8:42 pm

Just say NO to Twitter.......your life will be better : )
gjc1000
Chi pecora si fa, il lupo se la mangia.

Who is online

Users browsing this forum: No registered users and 11 guests