def check(self, schedule, data): start_timestamp = time.time() start_dt = datetime.now() receiver = data["mailbox"] sender = self.config.get("Inbox_plugin", "sender") result = False try: self.log.info("composing email") hash_code, msg = self.compose_email(sender, receiver) self.log.info("sending email") self.send_email(sender, receiver, msg) self.log.info("checking email") if "password_enc" in data: password = ciphor.decrypt(self.config.get("Checker", "password_secret"), data["password_enc"]) else: password = data["password"] result = self.check_email(schedule.ip_address, data["username"], password, hash_code, int(data["timeout"])) except: self.log.exception("got exception, we'll say that the email wasn't found") result = False result = int(result) duration = time.time() - start_timestamp return start_dt, result, duration
def check(self, schedule, data): """ Basic FTP checker, makes a connection, logs in and pulls down the main directory list. Looks in metadata dictionary for optional parameters, including: - username: username for FTP login. If missing, uses 'anonymous' - password: password for FTP login. If missing, uses '*****@*****.**' """ result = 1 metadata = None fqdn = schedule.fqdn ip = schedule.ip_address # Determine the port to connect to - either what's listed in the schedule or the default port = self.default_port if schedule.port: port = int(schedule.port) # Determine the we're performing authenticated FTP if data.has_key('username') and (data.has_key('password') or data.has_key('password_enc')): username = data['username'] if "password_enc" in data: password = ciphor.decrypt(self.config.get("Checker", "password_secret"), data["password_enc"]) else: password = data["password"] else: username = '******' password = '******' start_time = datetime.now() start = time.time() try: f = ftplib.FTP() f.connect(ip, port) f.login(username, password) r = f.retrlines('LIST', blackhole) f.quit() pieces = r.split(' ') retcode = int(pieces[0]) if retcode < 400: result = 1 else: result = 0 metadata = a except ftplib.all_errors, e: result = 0 metadata = str(e)
def check(self, schedule, data): """ Basic SSH checker, makes a connection, logs in and pulls down the main directory list. Looks in metadata dictionary for required parameters, including: - username: username for SSH login. - password: password for SSH login. - command: command to execute after ssh login. Defaults to "hostname" if not present. """ start_time = datetime.now() result = 1 metadata = None fqdn = schedule.fqdn ip = schedule.ip_address # Determine the port to connect to - either what's listed in the schedule or the default port = self.default_port if schedule.port: port = int(schedule.port) # Determine the we're performing authenticated SSH if data.has_key('username') and (data.has_key('password') or data.has_key('password_enc')): username = data['username'] if "password_enc" in data: password = ciphor.decrypt(self.config.get("Checker", "password_secret"), data["password_enc"]) else: password = data["password"] else: self.reportResults(schedule, start_time, -1, 0, "Missing username and/or password") # Determine the check command to execute, if present if data.has_key('command'): command = data['command'] else: command = 'hostname' start = time.time() try: s = paramiko.SSHClient() s.load_system_host_keys() s.set_missing_host_key_policy(paramiko.WarningPolicy()) s.connect(ip, port, username, password) stdin, stdout, stderr = s.exec_command(command) s.close() except paramiko.SSHException, e: result = 0 metadata = str(e)
def check(self, schedule, data): """ Basic MSSQL databas checker, makes a connection, logs in and pulls down a list of databases on the server. Looks in metadata dictionary for required parameters, including: - username, password, : username for database login. TODO: Add support for passing arbitrary queries to be performed on a regular basis. """ result = 1 metadata = None start_time = datetime.now() fqdn = schedule.fqdn ip = schedule.ip_address # Determine the port to connect to - either what's listed in the schedule or the default port = self.default_port if schedule.port: port = int(schedule.port) # Determine the we're performing authenticated FTP if not data.has_key('username'): return start_time, -1, 0, "Missing username" if not data.has_key('password') and not data.has_key("password_enc"): return start_time, -1, 0, "Missing password" username = data['username'] if "password_enc" in data: password = ciphor.decrypt(self.config.get("Checker", "password_secret"), data["password_enc"]) else: password = data["password"] start = time.time() try: m = pymssql.connect(user=username, password=password, host=ip, port=port) c = m.cursor() try: c.execute("select name from master.dbo.sysdatabases") except pymssql.ProgrammingError: c.execute("select name from sysobjects") c.close() except pymssql.OperationalError, e: result = 0 metadata = str(e)
def check(self, schedule, data): """ Basic POP checker, makes a connection, logs in and pulls down the main directory list. Looks in metadata dictionary for optional parameters, including: - username: username for POP login. If missing, we just get the welcome and don't login. - password: password for POP login. If missing, we just get the welcome and don't login. """ result = 1 metadata = None fqdn = schedule.fqdn ip = schedule.ip_address # Determine the port to connect to - either what's listed in the schedule or the default port = self.default_port if schedule.port: port = int(schedule.port) # Determine the we're performing a full login username = None password = None if data.has_key('username') and (data.has_key('password') or data.has_key('password_enc')): username = data['username'] if "password_enc" in data: password = ciphor.decrypt(self.config.get("Checker", "password_secret"), data["password_enc"]) else: password = data["password"] start_time = datetime.now() start = time.time() try: p = self.default_class(ip, port) p.getwelcome() if username: p.user(username) p.pass_(password) p.stat() p.quit() except poplib.error_proto, e: result = 0 metadata = str(e)
def check(self, schedule, data): owa_domain = "https://"+schedule.fqdn sel = selenium(self.config.get("Selenium", "host"), self.config.get("Selenium", "port"), "*chrome", owa_domain) sel.start() start = time.time() start_time = datetime.now() result = False try: sel.open("/OWA") sel.wait_for_page_to_load("30000") # if we don't sleep, some of the more evil versions of OWA won't # display the "20XX Microsoft" text right away... time.sleep(3) if "password_enc" in data: password = ciphor.decrypt(self.config.get("Checker", "password_secret"), data["password_enc"]) else: password = data["password"] if "password_enc" in data: password = ciphor.decrypt(self.config.get("Checker", "password_secret"), data["password_enc"]) else: password = data["password"] if sel.is_text_present("2009 Microsoft"): #self.log.info("detected OWA 2009") may_double_login = sel.get_text("css=td.nowrap > label") == "Domain\\user name:" sel.type("id=username", data["username"]) sel.type("id=password", password) sel.click("id=chkBsc") if may_double_login: sel.click("id=SubmitCreds") sel.wait_for_page_to_load("30000") sel.type("id=username", data["username"]) sel.type("id=password", password) sel.click("css=input.btn") sel.wait_for_page_to_load("30000") result = int(sel.get_text("id=lnkHdrnewmsg") == "New Message") elif sel.is_text_present("2007 Microsoft"): #self.log.info("detected OWA 2007") sel.type("id=username", data["username"]) sel.type("id=password", password) sel.click("id=chkBsc") sel.click("css=input.btn") sel.wait_for_page_to_load("30000") result = int(sel.get_text("id=lnkHdrnewmsg") == "New Message") elif sel.is_text_present("2010 Microsoft"): #self.log.info("detected OWA 2010") sel.type("id=username", data["username"]) sel.type("id=password", password) sel.click("id=chkBsc") sel.click("css=input.btn") sel.wait_for_page_to_load("30000") result = int(sel.get_text("id=lnkHdrnewmsg") == "New Message") else: # Default to OWA 2013 for the time being #self.log.info("detected OWA 2013") sel.type("id=username", data["username"]) sel.type("id=password", password) sel.click("css=span.signinTxt") sel.wait_for_page_to_load("30000") result = int(sel.get_text("id=_ariaId_15") == "Mail") except: pass duration = time.time() - start sel.stop() return start_time, result, duration