# HG changeset patch # User ft # Date 1386580377 -3600 # Node ID 0a5ba0ef10587a2933e792d77d1d002243dcc16c # Parent e75bc05c279d5e4758217c64e82b42571dc28b7b added sendNotification function diff -r e75bc05c279d -r 0a5ba0ef1058 src/OsecFS.py --- a/src/OsecFS.py Fri Dec 06 13:15:45 2013 +0100 +++ b/src/OsecFS.py Mon Dec 09 10:12:57 2013 +0100 @@ -17,6 +17,9 @@ import subprocess import urllib3 +import urllib +import netifaces +import netaddr MINOPTS = { "Main" : ["Logfile", "Mountpoint", "Rootpath", "LocalScanserverURL", "RemoteScanserverURL", "ReadOnly"]} @@ -212,6 +215,29 @@ return whitelisted +def sendNotification (type, message): + netifaces.ifaddresses("eth0")[2][0]["addr"] + + # Get first address in network (0 = network ip -> 192.168.0.0) + remote_ip = netaddr.IPNetwork("%s/%s" %(netifaces.ifaddresses("eth0")[2][0]["addr"], netifaces.ifaddresses("eth0")[2][0]["netmask"]))[1] + + url_options = {"type" : type, "message" : message } + url = ("http://%s/notification?%s" %(remote_ip, urllib.urlencode(url_options))) + + LOG.debug ("Send notification to \"%s\"" %(url, )) + + try: + response = httpPool.request_encode_body('GET', url, retries = 0) + except: + LOG.error("Remote host not reachable") + LOG.error ("Exception: %s" %(sys.exc_info()[0])) + return + + if response.status == STATUS_CODE_OK: + LOG.info("Notification sent successfully") + else: + LOG.error("Server returned errorcode: %s" %(response.status,)) + class OsecFS (Fuse): __rootpath = None @@ -368,6 +394,8 @@ config = loadConfig () initLog (config) + + #sendNotification("Info", "OsecFS started") scanserverTimestamp = time.time()