limit output lines
after all, there is no point in cluttering the whole screen with output from just one service.
This commit is contained in:
parent
ac32f02604
commit
5e843e5ea7
1 changed files with 23 additions and 2 deletions
25
service
25
service
|
@ -23,9 +23,28 @@ def current_time():
|
||||||
now = now.replace(tzinfo=None)
|
now = now.replace(tzinfo=None)
|
||||||
return now
|
return now
|
||||||
|
|
||||||
|
|
||||||
def to_unixtimestamp(dt):
|
def to_unixtimestamp(dt):
|
||||||
return int(time.mktime(dt.timetuple()))
|
return int(time.mktime(dt.timetuple()))
|
||||||
|
|
||||||
|
|
||||||
|
def limit_output_lines(output, num_lines=10):
|
||||||
|
actual = len(output)
|
||||||
|
|
||||||
|
if actual <= num_lines:
|
||||||
|
return output
|
||||||
|
|
||||||
|
more = actual-(num_lines-1)
|
||||||
|
|
||||||
|
result = output[:(num_lines-1)]
|
||||||
|
result.append('... and {} more line{s}'.format(
|
||||||
|
more,
|
||||||
|
's' if more > 1 else '',
|
||||||
|
))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def regenerate():
|
def regenerate():
|
||||||
now = current_time()
|
now = current_time()
|
||||||
|
|
||||||
|
@ -69,7 +88,7 @@ def regenerate():
|
||||||
'service': '-- HOST --',
|
'service': '-- HOST --',
|
||||||
'state': 2,
|
'state': 2,
|
||||||
'type': int(host['attrs']['state_type']),
|
'type': int(host['attrs']['state_type']),
|
||||||
'output': host['attrs']['last_check_result']['output'].splitlines(),
|
'output': limit_output_lines(host['attrs']['last_check_result']['output'].splitlines(), 3),
|
||||||
'ack': ack,
|
'ack': ack,
|
||||||
'sort': '{}{}{}{}'.format(
|
'sort': '{}{}{}{}'.format(
|
||||||
int(host['attrs']['state_type'])*-1,
|
int(host['attrs']['state_type'])*-1,
|
||||||
|
@ -100,7 +119,7 @@ def regenerate():
|
||||||
'service': svc['attrs']['display_name'],
|
'service': svc['attrs']['display_name'],
|
||||||
'state': int(svc['attrs']['state']),
|
'state': int(svc['attrs']['state']),
|
||||||
'type': int(svc['attrs']['state_type']),
|
'type': int(svc['attrs']['state_type']),
|
||||||
'output': svc['attrs']['last_check_result']['output'].splitlines(),
|
'output': limit_output_lines(svc['attrs']['last_check_result']['output'].splitlines()),
|
||||||
'ack': ack,
|
'ack': ack,
|
||||||
'sort': '{}{}{}{}'.format(
|
'sort': '{}{}{}{}'.format(
|
||||||
int(svc['attrs']['state_type'])*-1,
|
int(svc['attrs']['state_type'])*-1,
|
||||||
|
@ -136,6 +155,7 @@ def regenerate():
|
||||||
with file("services.json", "wb") as f:
|
with file("services.json", "wb") as f:
|
||||||
f.write(json.dumps(services, ensure_ascii=False).encode("utf8"))
|
f.write(json.dumps(services, ensure_ascii=False).encode("utf8"))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
|
@ -145,5 +165,6 @@ def main():
|
||||||
|
|
||||||
time.sleep(20)
|
time.sleep(20)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue