Siprun commando om commando files door te sturen

This commit is contained in:
Marcel Nijenhof
2019-02-13 15:56:17 +01:00
parent 9b54eeac9e
commit 20abc37e32
2 changed files with 46 additions and 4 deletions

46
siprun
View File

@@ -1,8 +1,46 @@
#!/usr/bin/python3
import sys
import getopt
from lmwsip import LmwSip
lmwsip = LmwSip("NAGIOS", "NAGIOS")
print(lmwsip.ti())
print(lmwsip.value("WN", "HOEK", "H10"))
lmwsip.logout()
def usage():
print("siprun [-s] [-h <host>] [-p <port>] [<files>]")
print("\t-s: SSL connection")
print("\t-h <host>: Connect to host")
print("\t-p <port>: Connect to port")
print("\t-<files>: LMW commando files")
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "sh:p:", ["help", "output="])
except getopt.GetoptError as err:
# print help information and exit:
print(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
ssl=False
host=None
port=None
for o, a in opts:
if o == "-s":
ssl=True
elif o == "-h":
host=a
elif o == "-p":
port=a
if (host==None or port==None):
print("Set host and port")
usage()
sys.exit(3)
lmwsip = LmwSip(ssl=ssl, host=host, port=port)
for cmdfile in args:
with open(cmdfile, "r") as f:
for cmd in f:
print("> [%s]" % (cmd.strip('\n')))
lmwsip.send(cmd)
print("< [%s]" % (lmwsip.recv().decode('utf-8').strip('\r')))
f.close()
if __name__ == "__main__":
main()