Test: Have a web server send me critical messages via Twitter.
I set up automated scripts to update and upgrade the IPKG packages automatically once a week and to refresh the Fever° data daily. I care about the result of these actions, so I logged them locally… only to never look at them.
I have decided to try the following: create a Twitter account and have the server send only the most important status messages to Twitter. Only a select few every day… not to be the one who breaks Twitter…!
Now I can keep up with my server’s health by simply following it on Twitter. Cloud based logging? Let’s see, how this works out!
I still have to figure out what to do with long messages, for now I just crop them.
I simply call the following PHP script from my batch file using curl and passing the log file to be posted as a parameter.
$filename = "/share/logs/" . $_GET["file"];
$fd = fopen ($filename, "r");
$contents = fread ($fd,filesize ($filename));
$tweet = substr($contents, 0, 140);
$username = 'x';
$password = 'y';
$url = 'http://twitter.com/statuses/update.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url")
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$msg");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);