nagios-plugins/check_z_heartbeat

47 lines
1.4 KiB
Python
Executable File

#!/bin/python3
#
import argparse
import nagios
import os
import time
from z_server import config
from z_server import tcp_socket
from z_server.z_protocol import server as client_prot
from z_server.z_protocol import DIDS
from z_server import socket_protocol
import sys
if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog='ProgramName',
description='What the program does',
epilog='Text at the bottom of help')
parser.add_argument('-s', '--stg', required=True)
parser.add_argument('-l', '--loc', required=True)
parser.add_argument('-r', '--roo', required=True)
parser.add_argument('-f', '--fun', required=True)
args = parser.parse_args()
#
c = tcp_socket.tcp_client_stp('127.0.0.1', config.SOCK_PROT_PORT)
sp = client_prot(c, channel_name='example_client')
#
data = {
"stg": args.stg,
"loc": args.loc,
"roo": args.roo,
"fun": args.fun
}
#
did = os.path.basename(sys.argv[0])[8:]
#
if did not in DIDS:
print("Unknown data id %s. You might add it in z_server.z_protocol." % did)
sys.exit(100)
else:
sp.send(socket_protocol.SID_READ_REQUEST, did, data)
sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, did).get_data() or {
"status": 101, "msg": "No answer from device for \"%s\". You might want to add it in z_server.devices" % did}
nagios.Nagios().exit(**sp_data)