What would be the best way to monitor services like HTTP/FTP/IMAP/POP3/SMTP for a few servers from python? Using sockets and trying to connect to service port http-80, ftp-21, etc... and if connection successful assume service is ok or use python libs to connect to specified services and handle exceptions/return codes/etc...
For example for ftp is it better to
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(("ftp.domain.tld", 21))
print "ok"
except:
print "failed"
s.close()
or to
from ftplib import FTP
try:
ftp = FTP('ftp.domain.tld')
print "FTP service OK"
ftp.close()
except:
print "FTP err"
same goes for the rest, socket vs urllib2, imaplib, etc... and if i go the lib way how do i test for smtp?