Fix -i/-I arguments type

This commit is contained in:
Théophile Bastian 2022-12-12 15:28:32 +01:00
parent f7adc95045
commit 065fb5da49

View file

@ -36,6 +36,7 @@ def record(target: str, interval: int, outage_interval: int):
"INSERT INTO errors (from_time, to_time, host) VALUES (?, ?, ?);", "INSERT INTO errors (from_time, to_time, host) VALUES (?, ?, ?);",
(int(outage), int(time.time()), target), (int(outage), int(time.time()), target),
) )
outage = None
time.sleep(interval if outage is None else outage_interval) time.sleep(interval if outage is None else outage_interval)
except KeyboardInterrupt as exn: except KeyboardInterrupt as exn:
if outage is not None: if outage is not None:
@ -50,11 +51,14 @@ def record(target: str, interval: int, outage_interval: int):
def entry(): def entry():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("host", help="Remote host to ping (IP address preferred)") parser.add_argument("host", help="Remote host to ping (IP address preferred)")
parser.add_argument("-i", "--interval", default=30, help="Time between two pings") parser.add_argument(
"-i", "--interval", default=30, type=int, help="Time between two pings"
)
parser.add_argument( parser.add_argument(
"-I", "-I",
"--outage-interval", "--outage-interval",
default=2, default=2,
type=int,
help="Time between two pings while the network is down", help="Time between two pings while the network is down",
) )
args = parser.parse_args() args = parser.parse_args()