diff --git a/src/measure.py b/src/measure.py index 33f3d02..0bdf8c3 100644 --- a/src/measure.py +++ b/src/measure.py @@ -22,24 +22,26 @@ def influx_escape(string): string = string.replace(c, "\\"+c) return string -def send_data(date, status, time, url, protocol): - data = "response_time,url={url},status={status},protocol={protocol} value={time} {timestamp}".format( +def send_data(date, status, time, url, protocol, station=00): + data = "response_time,url={url},status={status},protocol={protocol},station={station} value={time} {timestamp}".format( url=influx_escape(url), status=influx_escape(str(status)), time=time, timestamp=int(date.timestamp()*1e9), - protocol=influx_escape(protocol) + protocol=influx_escape(protocol), + station=station ) r=requests.post(INFLUX_URL, data=data) log.warn(str(r) + " " + str(r.text)) class Measurement(threading.Thread): - def __init__(self, measure_fn, url, exlog): + def __init__(self, measure_fn, url, exlog, station=00): threading.Thread.__init__(self) self.url = url self.measure_fn = measure_fn self.exlog = exlog + self.station = station def run(self): start_date = datetime.now() @@ -50,7 +52,8 @@ class Measurement(threading.Thread): url=url, status=result.status, time=result.time, - protocol=result.protocol + protocol=result.protocol, + station ) def run_measurements(targets): @@ -69,6 +72,7 @@ if __name__ == "__main__": parser.add_argument("--smtp", "-s", nargs="*", help="SMTP STARTSSL hosts to measure") parser.add_argument("--pop3", "-p", nargs="*", help="POP3 SSL hosts to measure") parser.add_argument("--imap", "-m", nargs="*", help="IMAP SSL hosts to measure") + parser.add_argument("--station", default=00, help="set station name (default: 00)") args = parser.parse_args() exlog = logging.getLogger("exceptions") @@ -93,9 +97,9 @@ if __name__ == "__main__": parser.print_help() sys.exit(1) - schedule.every(args.interval).seconds.do(lambda: run_measurements(targets)) + schedule.every(args.interval).seconds.do(lambda: run_measurements(targets, args.station)) - run_measurements(targets) + run_measurements(targets, args.station) while True: try: