Commits

Cédric Bonhomme committed 36cbb55

It is now possible to send alerts to an irc channel via irker.

  • Participants
  • Parent commits 11db8a9

Comments (0)

Files changed (3)

File conf.cfg-sample

 [globals]
 nb_bits = 752
+[irc]
+channel = irc://chat.freenode.net/#testpyHIDS
 [email]
 enabled = 0
 mail_from = pyHIDS@no-reply.com
 
 NB_BITS = int(config.get('globals','nb_bits'))
 
+IRC_CHANNEL = config.get('irc','channel')
+
 MAIL_ENABLED = bool(int(config.get('email','enabled')))
 MAIL_FROM = config.get('email','mail_from')
 MAIL_TO = [config.get('email','mail_to')]
 __license__ = "GPL v3"
 
 import os
+import socket
+import json
 import time
 import pickle
 import hashlib
 
 import conf
 
+irker_lock = threading.Lock()
+
 def load_base():
     """
     Load the base file.
             message = target_file + " changed."
             log_syslog(message)
 
+            log_irker(conf.IRC_CHANNEL, message)
+
             if conf.MAIL_ENABLED:
                 # reporting alert via mail
                 # this list contains the admins to prevent
         message = " ".join(command) + " command output has changed."
         log_syslog(message)
 
+        log_irker(conf.IRC_CHANNEL, message)
+
         if conf.MAIL_ENABLED:
             # reporting alert via mail
             # this list contains the admins to prevent
     server.send_message(email)
     server.quit()
 
+def log_irker(target, message):
+    irker_lock.acquire()
+    data = {"to": target, "privmsg" : message}
+    try:
+        s = socket.create_connection(("localhost", 6659))
+        s.sendall(json.dumps(data).encode('utf-8'))
+    except socket.error as e:
+        sys.stderr.write("irkerd: write to server failed: %r\n" % e)
+    finally:
+        irker_lock.release()
 
 if __name__ == "__main__":
     # Point of entry in execution mode