Archive for the ‘python’ Category

Click on one of the items below to go to the post

Automatic Web Server Monitoring

Hi there! Here’s another quick suggestion for all of you out there who have to deal with a lot of web server environments and need to make sure that they’re all alive and responsive. Sure there are all sorts of tools for server monitoring and performance tracking, but I found that most of the time you just need to know if the server is up & running. And of course you should be notified if it’s not. Here’s my short Python script that does just that. You will need to tweak it a little to use in your environment. First of all I’ve set the content threshold to 2000 Bytes which means that the expected length of the page content returned is no less than 2000 Bytes. If it’s below this value, one could assume that something’s fishy going on. You might want to change this value to something else depending on what your web server returns. Another thing that you’ll want to change is the servers dictionary in the main() method. The logic behind this is that each of the web servers is assigned a responsible person that you would need to inform if something is wrong with the server. You should list all your servers that need to be monitored and the responsible person’s e-mails. The final change is on the line where you instantiate the HeartbeatMonitor class. The first parameter admins is a list of e-mails of the people who will receive the notification if any of the servers are down. You can leave this list empty if you want, but I usually put my e-mail in there since I like to be in the loop. The second parameter mailServer is the SMTP server which will be used to send notifications so make sure this one is set correctly. This parameter is actually optional and localhost will be used as the default mail server if you decide to skip it.

Search for Files on Remote FTP Server

I’ll keep this one short. Don’t know about you, but I’ve always been frustrated about how most FTP clients won’t let you search for files on a remote FTP server. I remember I used some client that had this functionality, but this was quite a while ago so I can’t even remember the name of it. If someone else knows any lightweight tools that let you do that, please leave a comment. Recently I needed to do some quick searches on the servers that I have only FTP access to. And you know what they say… “when you can’t find the right tool for the job – write it yourself” Actually I don’t know if anyone says that :) but I decided to do it and put together a Python script just for this task. I’m not sure if many others have run into a similar problem, but I put it on GitHub anyway. I called it FTP search for obvious reasons. You can find the script and a short documentation there. The only prerequisite is that you have Python 2.7.x installed. I can’t promise you that it will work with Python 3.x but you’re welcome to try.  If you have any ideas on how to improve this little tool and wish to contribute then leave a comment bellow or contact me via e-mail that’s specified on GitHub’s project page.

Creating thumbnails from photos with Python PIL

This time around I want to share with you a little Python library I found called PIL. If you’re a Python developer chances are you already know of it, but I use Python only from time to time, usually to automate some tasks so I was very excited to come across such a library. First thing’s first, download PIL and install it. I’m using it on a Windows platform so I used the packaged binary version, but you can get the source code and use it on any platform that supports Python. There’s also links to documentation on the same page. If you already know Python it should be fairly easy to use the library. What I liked best about it is speed, though my comparison is to Java-based image processing which can be painfully slow. One of the first things I did with it was create a simple little thumbnail generator to help me handle my photo collection which you can see below. Simply specify a directory with .jpg files in it and the script will go through each file