def run_ping(): self.logger.debug("Starting ping, stanza=%s", stanza) # Get the time that the input last ran last_ran = self.last_ran(input_config.checkpoint_dir, stanza) for dest in dests: try: def output_result_callback(result): """ Output the result """ self.send_result(result, stanza, index, sourcetype, host, source) if port not in [None, ""]: results = tcp_ping_all( dest, port, count=runs, logger=self.logger, callback=output_result_callback) else: results = ping_all(dest, count=runs, logger=self.logger, callback=output_result_callback) if len(results) == 1: self.logger.debug( "Successfully pinged the host=%s", str(dest)) elif len(results) > 1: self.logger.info( "Successfully pinged all hosts in the network=%s", str(dest)) except Exception as e: self.logger.exception(e) # Save the checkpoint so that we remember when we last ran the input self.save_checkpoint_data( input_config.checkpoint_dir, stanza, { 'last_run': self.get_non_deviated_last_run(last_ran, interval, stanza) }) self.logger.debug("Ping complete, stanza=%s", stanza)
def handle_results(self, results, session_key, in_preview): # FYI: we ignore results since this is a generating command # Make sure that the dest field was provided if self.dest is None: self.logger.warn("No dest was provided") return # Get the index if self.index is not None: index = self.index else: index = get_default_index(session_key) # Do the ping if self.port is None: results = ping_all(self.dest, self.count, index=index, logger=self.logger) else: results = tcp_ping_all(self.dest, self.port, self.count, index=index, logger=self.logger) # Output the results self.output_results(results)