コード例 #1
0
ファイル: fail2ban.py プロジェクト: annttu/collectd-plugins
 def __processCmd(self, jail = "", listjails = False, showRet = True):
     cmd = []
     if listjails is True:
         cmd.append(['status'])
     elif jail != "":
         cmd.append(['status', jail])
     for c in cmd:
         retval = False
         try:
             logSys.debug("%s" % c)
             client = CSocket(self.__conf["socket"])
             ret = client.send(c)
             if ret[0] == 0:
                 if listjails is False:
                     retval =  ret[1][1][1][0][1]
                 else:
                     retval = [i.strip() for i in ret[1][1][1].split(",")]
                 if showRet:
                     logSys.debug("OK : " + `ret[1]`)
                     logSys.debug("retval: %s" % retval)
                 return retval
             else:
                 logSys.debug("NOK: " + `ret[1].args`)
                 logSys.debug(ret[1])
                 return
         except socket.error:
             if showRet:
                 logSys.error("Unable to contact server. Is it running?")
             return
         except Exception, e:
             if showRet:
                 logSys.error(e)
             return
コード例 #2
0
ファイル: sockettestcase.py プロジェクト: Jamyn/fail2ban
	def testSocket(self):
		serverThread = threading.Thread(
			target=self.server.start, args=(self.sock_name, False))
		serverThread.daemon = True
		serverThread.start()
		time.sleep(1)

		client = CSocket(self.sock_name)
		testMessage = ["A", "test", "message"]
		self.assertEqual(client.send(testMessage), testMessage)

		self.server.stop()
		serverThread.join(1)
		self.assertFalse(os.path.exists(self.sock_name))
コード例 #3
0
    def testSocket(self):
        serverThread = threading.Thread(target=self.server.start,
                                        args=(self.sock_name, False))
        serverThread.daemon = True
        serverThread.start()
        time.sleep(1)

        client = CSocket(self.sock_name)
        testMessage = ["A", "test", "message"]
        self.assertEqual(client.send(testMessage), testMessage)

        self.server.stop()
        serverThread.join(1)
        self.assertFalse(os.path.exists(self.sock_name))
コード例 #4
0
 def block_ip(self, ip):
     try:
         client = CSocket(self.__conf["socket"])
         command = ["set", "blocklist", "banip"]
         logSys.debug("Blocking %s", ip)
         ret = client.send(command + [ip])
         if ret[0] == 0:
             logSys.debug("OK : " + str(ret[1]))
         else:
             print ret
             logSys.debug("NOK: %s = %s", ret[1].args, ret[1])
             raise Exception
     except socket.error:
         logSys.error("Unable to contact server. Is it running?")
         raise
     except Exception, e:
         logSys.error(e)
         raise