def test_target(self,id): try: i = int(id) except ValueError: print '%s is not a valid id' % id return targetmodel = TargetModel(self.logger,self.config) target = targetmodel.get(i) if target == None: print('id: %d does not exist' % i) return puncher = Puncher(self.logger,targetmodel,None) puncher.punch_it_now(target)
def test_target(self, id): try: i = int(id) except ValueError: print '%s is not a valid id' % id return targetmodel = TargetModel(self.logger, self.config) target = targetmodel.get(i) if target == None: print('id: %d does not exist' % i) return puncher = Puncher(self.logger, targetmodel, None) puncher.punch_it_now(target)
def enable_target(self,enable,id): try: i = int(id) except ValueError: print '%s is not a valid id' % id return targetmodel = TargetModel(self.logger,self.config) target = targetmodel.get(i) if target == None: print('id: %d does not exist' % i) return target.enabled=enable targetmodel.commit() print('Target: %s has been %s'% (target.name,'Enabled'if enable else 'Disabled'))
def enable_target(self, enable, id): try: i = int(id) except ValueError: print '%s is not a valid id' % id return targetmodel = TargetModel(self.logger, self.config) target = targetmodel.get(i) if target == None: print('id: %d does not exist' % i) return target.enabled = enable targetmodel.commit() print('Target: %s has been %s' % (target.name, 'Enabled' if enable else 'Disabled'))
def list_all_targets(self): targets = PrettyTable(['ID', 'Name', 'Status', 'LastUpdated','Enabled','Pass Count','Fail Count']) targets.align = 'l' targetmodel = TargetModel(self.logger,self.config) ids = targetmodel.get_ids() for id in ids: target = targetmodel.get(id) row = [] row.append(target.id) row.append(target.name) row.append(target.status) row.append(target.last_updated) row.append('Yes' if target.enabled else 'No') row.append(target.pass_count) row.append(target.fail_count) targets.add_row(row) print targets
def run(self): print 'starting %s ....' % PROGNAME logger.info('starting %s ....' % PROGNAME) config = SkyPunchConfig(logger) targetmodel = TargetModel(logger,config) notifiermodel = NotifierModel(logger,config) puncher = Puncher(logger,targetmodel,notifiermodel) try: while True: ids = targetmodel.get_ids() for id in ids: target = targetmodel.get(id) if target.enabled: puncher.punch(target) time.sleep(config.getint(skypunchconfig.SETTINGS,skypunchconfig.MAINLOOPTOV)) except SystemExit, e: sys.exit(e)
def run(self): print 'starting %s ....' % PROGNAME logger.info('starting %s ....' % PROGNAME) config = SkyPunchConfig(logger) targetmodel = TargetModel(logger, config) notifiermodel = NotifierModel(logger, config) puncher = Puncher(logger, targetmodel, notifiermodel) try: while True: ids = targetmodel.get_ids() for id in ids: target = targetmodel.get(id) if target.enabled: puncher.punch(target) time.sleep( config.getint(skypunchconfig.SETTINGS, skypunchconfig.MAINLOOPTOV)) except SystemExit, e: sys.exit(e)
def list_all_targets(self): targets = PrettyTable([ 'ID', 'Name', 'Status', 'LastUpdated', 'Enabled', 'Pass Count', 'Fail Count' ]) targets.align = 'l' targetmodel = TargetModel(self.logger, self.config) ids = targetmodel.get_ids() for id in ids: target = targetmodel.get(id) row = [] row.append(target.id) row.append(target.name) row.append(target.status) row.append(target.last_updated) row.append('Yes' if target.enabled else 'No') row.append(target.pass_count) row.append(target.fail_count) targets.add_row(row) print targets
def list_individual_target(self,id): try: i = int(id) except ValueError: print '%s is not a valid id' % id return targetmodel = TargetModel(self.logger,self.config) target = targetmodel.get(i) if target == None: print('id: %d does not exist' % i) return details = PrettyTable(['Name','Value']) details.align = 'l' details.hrules = ALL details.header = False details.add_row(['ID',target.id]) details.add_row(['Name',target.name]) details.add_row(['Status',target.status]) details.add_row(['Enabled','Yes' if target.enabled else 'No']) details.add_row(['Status Description',target.status_description]) details.add_row(['Last Updated',target.last_updated]) details.add_row(['Target URL',target.url]) details.add_row(['Target Method',target.method]) details.add_row(['Authentication',target.authn]) details.add_row(['Expected Value',target.pass_result]) details.add_row(['Frequency (sec)',target.frequency]) details.add_row(['Timeout (sec)',target.timeout]) details.add_row(['Pass Count',target.pass_count]) details.add_row(['Fail Count',target.fail_count]) details.add_row(['200 Status Count',target.count200]) details.add_row(['300 Status Count',target.count300]) details.add_row(['400 Status Count',target.count400]) details.add_row(['500 Status Count',target.count500]) details.add_row(['Network Fail Count',target.network_fails]) details.add_row(['Repeated Fail Count',target.repeated_fails]) print details
def list_individual_target(self, id): try: i = int(id) except ValueError: print '%s is not a valid id' % id return targetmodel = TargetModel(self.logger, self.config) target = targetmodel.get(i) if target == None: print('id: %d does not exist' % i) return details = PrettyTable(['Name', 'Value']) details.align = 'l' details.hrules = ALL details.header = False details.add_row(['ID', target.id]) details.add_row(['Name', target.name]) details.add_row(['Status', target.status]) details.add_row(['Enabled', 'Yes' if target.enabled else 'No']) details.add_row(['Status Description', target.status_description]) details.add_row(['Last Updated', target.last_updated]) details.add_row(['Target URL', target.url]) details.add_row(['Target Method', target.method]) details.add_row(['Authentication', target.authn]) details.add_row(['Expected Value', target.pass_result]) details.add_row(['Frequency (sec)', target.frequency]) details.add_row(['Timeout (sec)', target.timeout]) details.add_row(['Pass Count', target.pass_count]) details.add_row(['Fail Count', target.fail_count]) details.add_row(['200 Status Count', target.count200]) details.add_row(['300 Status Count', target.count300]) details.add_row(['400 Status Count', target.count400]) details.add_row(['500 Status Count', target.count500]) details.add_row(['Network Fail Count', target.network_fails]) details.add_row(['Repeated Fail Count', target.repeated_fails]) print details