From ea8f1c89c8cd30f565047a6eda341ecdc18b30f4 Mon Sep 17 00:00:00 2001 From: Stefan Weiher Date: Tue, 30 May 2017 16:42:56 +0200 Subject: [PATCH] Added a file with examples. Fixed the boolean -l option for wc_getTrend. Implemented a -u and -p option for parsing username and password to the WebCTRL server. If -p is not specified one will be prompted in the command line to enter the password. --- EXAMPLES | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ README | 7 +++-- wc_getReport.py | 39 ++++++++++++++++++----- wc_getTrend.py | 58 +++++++++++++++++++++------------- wc_getValue.py | 41 +++++++++++++++++++----- wc_query.py | 43 ++++++++++++++++++++----- 6 files changed, 223 insertions(+), 48 deletions(-) create mode 100644 EXAMPLES diff --git a/EXAMPLES b/EXAMPLES new file mode 100644 index 0000000..2e01a26 --- /dev/null +++ b/EXAMPLES @@ -0,0 +1,83 @@ +Example(s) for each of the webctrl command line tools +--------------------------------------------------- + +### wc_query - Query the children of a node + +$ ./wc_query -u wsdl -n /trees/geographic +No password specified via -p. Please enter your WebCTRL login password: +Children of "/trees/geographic": +[#verbrauchszaehlung, #geb_a, #geb_b, #geb_c, #geb_d, #geb_e, #geb_f, #geb_g, #geb_k, #geb_l, #geb_m, #geb_pnq, ...] + +$ ./wc_query -u wsdl -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel +No password specified via -p. Please enter your WebCTRL login password: +Children of "/trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel": +[m032, m007, m008, m034, m033, m001, m005, m004, m003, m002, m006, ...] + + +### wc_getValue - get the present value (the present_value attribute) of a m??? controller + +$ ./wc_getValue -u wsdl -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel/m001 +No password specified via -p. Please enter your WebCTRL login password: +Present value of /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel/m001 is: 15.600924 + + +### wc_getReport - get a report for a node (one level lower than m???) + +$ ./wc_getReport -u wsdl -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel/m001 +No password specified via -p. Please enter your WebCTRL login password: +| Standort | +|--------------------------------------------------------------- +| Fr die aktuellen Optionen wurden keine Ergebnisse gefunden.x | + +$ ./wc_getReport -u wsdl -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel +No password specified via -p. Please enter your WebCTRL login password: +| Standort | Regelungsprogramm | Name | Wert | Typ | Objekt-ID | Gerte-ID | Objektname | Offset/Polaritt | Pfad | +|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +| /Fritz-Haber-Institut/Bauteil E/Kaltwassererzeuger | Kaltwassererzeuger | FEL Kaltwasser Durchflussmenge Verteiler | 6.5 m3/Std. | BMAI | AI:315818 | DEV:34157 | m032_5 | | #km_speicher_fel/m032 | +| /Fritz-Haber-Institut/Bauteil E/Kaltwassererzeuger | Kaltwassererzeuger | FEL Kaltwasser Kltemaschine Rcklauftemperatur x | 9.724116 C | BMAI | AI:2796280 | DEV:34157 | m007_5 | | #km_speicher_fel/m007 | +| /Fritz-Haber-Institut/Bauteil E/Kaltwassererzeuger | Kaltwassererzeuger | FEL Kaltwasser Kltemaschine Vorlauftemperatur | 8.348758 C | BMAI | AI:2796279 | DEV:34157 | m008_5 | | #km_speicher_fel/m008 | +| ... + + +### wc_getTrend - get timestamps and data values of a specific controller for a specific time period + +### If no time period and number of values to retrieve are specified you'll get the last ten values +$ python wc_getTrend.py -u wsdl -n /trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006 +No password specified via -p. Please enter your WebCTRL login password: +Start time is undefined. Use -s to define date and time. +End time is undefined. Use -e to define date and time. +05/30/2017 02:19:00 PM 63.292435 +05/30/2017 02:20:00 PM 63.292435 +05/30/2017 02:21:00 PM 63.292435 +05/30/2017 02:22:00 PM 63.292435 +05/30/2017 02:23:00 PM 63.292435 +05/30/2017 02:24:00 PM 63.292435 +05/30/2017 02:25:00 PM 63.292435 +05/30/2017 02:26:00 PM 63.292435 +05/30/2017 02:27:00 PM 63.292435 +05/30/2017 02:28:00 PM 63.292435 + +### Specify the amount of values you want to retrieve starting from the time of retrieval +$ python wc_getTrend.py -u wsdl -n /trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006 -m 5 +No password specified via -p. Please enter your WebCTRL login password: +Start time is undefined. Use -s to define date and time. +End time is undefined. Use -e to define date and time. +05/30/2017 04:25:00 PM 63.783897 +05/30/2017 04:26:00 PM 63.783897 +05/30/2017 04:27:00 PM 63.783897 +05/30/2017 04:28:00 PM 63.783897 +05/30/2017 04:29:00 PM 63.783897 + +### Specify the amount of values you want to retrieve starting from the beginning of recording the specified controller +$ python wc_getTrend.py -u wsdl -n /trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006 -m 5 -l +No password specified via -p. Please enter your WebCTRL login password: +Start time is undefined. Use -s to define date and time. +End time is undefined. Use -e to define date and time. +03/15/2017 04:10:48 PM 0.0 +03/15/2017 04:10:48 PM 0.0 +03/15/2017 04:12:21 PM 33.726974 +05/30/2017 04:27:00 PM 63.783897 +05/30/2017 04:28:00 PM 63.783897 + + + diff --git a/README b/README index f6fd6c3..be85264 100644 --- a/README +++ b/README @@ -5,10 +5,10 @@ Prerequisits 1) Python 2.7 2) In order to use the WSDL API you need to download and install the SUDS python package - Download suds-0.4.tar.gz here: https://pypi.python.org/pypi/suds + Download suds-0.4.tar.gz here: https://pypi.python.org/pypi/suds Install via command line: $ sudo pip install suds-0.4.tar.gz 3) If you don't want to execute the scripts from within an IDE (e.g. Pycharm) you could install - pythoninstaller to build the tools: $ sudo pip install pyinstaller + pythoninstaller to build the tools: $ sudo pip install pyinstaller Building the tools ------------------ @@ -17,6 +17,9 @@ webctrl$ ./build_project.sh The executables can be found in ./dist/wc_*/wc_* +Add the directory to the PATH environment variable (in your ~/.bashrc in order to be able to execute the wc_* commands +everywhere: PATH=$PATH:$HOME/.../webctrl/dist/wc_query:$HOME/.../webctrl/dist/wc_getValue:... + Running the tools ----------------- diff --git a/wc_getReport.py b/wc_getReport.py index 5df9f8f..3532de3 100644 --- a/wc_getReport.py +++ b/wc_getReport.py @@ -3,18 +3,40 @@ import numpy import xml import argparse +import getpass + if len(sys.argv) < 2: - print "You haven't specified any arguments but I need a path. Use -h to get more details on how to use this command." + print "You haven't specified any arguments. Use -h to get more details on how to use this command." + parser = argparse.ArgumentParser() -parser.add_argument('--path', '-p', type=str, default=None, - help='Path to the point or node for which you want to get a report.') +parser.add_argument('--username', '-u', type=str, default=None, help='User name for the login to the WebCTRL server') +parser.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') +parser.add_argument('--node', '-n', type=str, default=None, + help='Path to the point or node for which you want to retrieve a report.') +parser.add_argument('-url', type=str, default='https://webctrl.rz-berlin.mpg.de', help="URL of the WebCTRL server as e.g. http://google.de") args = parser.parse_args() -username = 'wsdl' -password = 'seife' -wsdlFile = 'https://webctrl.rz-berlin.mpg.de/_common/webservices/Report?wsdl' + +if args.username is None: + print 'No user name specified. Login to WebCTRL needs a user name and password. Check all options for this command via -h' + sys.exit(1) +else: + username = args.username +if args.password is None: + password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') +else: + password = args.password +if args.node is None: + print 'No path to a node specified. Check all options for this command via -h' + sys.exit(1) +if args.url is None: + print 'No URL given. Specify the URL to the WebCTRL server analogous to http://google.de' + sys.exit(1) +else: + wsdlFile = args.url + '/_common/webservices/Report?wsdl' + try: client = suds.client.Client(wsdlFile, username=username, password=password) @@ -27,9 +49,10 @@ print("Unexpected error:", sys.exc_info()[0]) sys.exit(1) + # Get the report try: - report = client.service.runReport(args.path, '~point-list-report', 'csv') + report = client.service.runReport(args.node, '~point-list-report', 'csv') except suds.WebFault as fault: print fault sys.exit(1) @@ -40,7 +63,7 @@ # Declare arrays maxColumnWidth = [0 for i in range(nColumns)] -emptyColumns = numpy.full((nColumns), True, dtype=bool) +emptyColumns = numpy.full(nColumns, True, dtype=bool) # Initialize the maximum column widths by the width of the column headers column = lines[0].replace('"', '').split(",") diff --git a/wc_getTrend.py b/wc_getTrend.py index c23cff5..bcf1e4e 100644 --- a/wc_getTrend.py +++ b/wc_getTrend.py @@ -2,41 +2,53 @@ import sys import xml import argparse +import getpass + if len(sys.argv) < 2: - print "You haven't specified any arguments. Need at least a path. Use -h to get more details on how to use this command." + print "You haven't specified any arguments. Use -h to get more details on how to use this command." + parser = argparse.ArgumentParser() -parser.add_argument('--path', '-p', type=str, default=None, - help='The full path to the point, or trend log node whose trend data is desired.') +parser.add_argument('--username', '-u', type=str, default=None, help='User name for the login to the WebCTRL server') +parser.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') +parser.add_argument('--node', '-n', type=str, default=None, + help='The full path to the point or trend log node whose trend data is desired.') +parser.add_argument('-url', type=str, default='https://webctrl.rz-berlin.mpg.de', + help="URL of the WebCTRL server as e.g. http://google.de") parser.add_argument('--sTime', '-s', type=str, default=None, help="Start Time. Returns trend data values starting with this time. Like this: 'MM/DD/YYYY HH:MM:SS AM'.") parser.add_argument('--eTime', '-e', type=str, default=None, help="End Time. Returns trend data values until this time. Like this: 'MM/DD/YYYY HH:MM:SS PM'.") -parser.add_argument('--limit', '-l', type=bool, default=False, - help='Use True to retrieve maxRecords from the start or False to retrieve maxRecords from the end.') +parser.add_argument('--limit', '-l', action='store_true', default=False, + help='If specified maxRecords are retrieved from the start or maxRecords are retrieved from the end.') parser.add_argument('--maxRec', '-m', type=int, default=10, help='Maximum number of records desired. Use a number >0 to limit records; use 0 to retrieve unlimited records.') args = parser.parse_args() -#location = '/trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006' -#location = '#g_primzuluft_trend/m006' -#startDate = '05/10/2017 08:00:00 AM' -#endDate = '05/10/2017 01:00:00 PM' -#limitFromStart = False -#maxRecords = 10 - -if args.path == None: - print 'Path is undifined. Type "$ wc_getTrend --help" for details.' - sys.exit(0) -if args.sTime == None: + +if args.username is None: + print 'No user name specified. Login to WebCTRL needs a user name and password. Check all options for this command via -h' + sys.exit(1) +else: + username = args.username +if args.password is None: + password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') +else: + password = args.password +if args.sTime is None: print 'Start time is undefined. Use -s to define date and time.' -if args.eTime == None: +if args.eTime is None: print 'End time is undefined. Use -e to define date and time.' +if args.node is None: + print 'No path to a node specified. Check all options for this command via -h' + sys.exit(1) +if args.url is None: + print 'No URL given. Specify the URL to the WebCTRL server analogous to http://google.de' + sys.exit(1) +else: + wsdlFile = args.url + '/_common/webservices/Trend?wsdl' -username = 'wsdl' -password = 'seife' -wsdlFile = 'https://webctrl.rz-berlin.mpg.de/_common/webservices/Trend?wsdl' try: client = suds.client.Client(wsdlFile, username=username, password=password) @@ -49,13 +61,15 @@ print("Unexpected error:", sys.exc_info()[0]) sys.exit(1) + try: - trendData = client.service.getTrendData(args.path, args.sTime, args.eTime, args.limit, args.maxRec) + trendData = client.service.getTrendData(args.node, args.sTime, args.eTime, args.limit, args.maxRec) except suds.WebFault as fault: print fault sys.exit(1) -for x in range(0, args.maxRec*2-1, 2): +for x in range(0, len(trendData)-1, 2): print trendData[x] + ' ' + trendData[x+1] + sys.exit(0) diff --git a/wc_getValue.py b/wc_getValue.py index be59623..d0bcfb1 100644 --- a/wc_getValue.py +++ b/wc_getValue.py @@ -2,18 +2,40 @@ import sys import xml import argparse +import getpass + if len(sys.argv) < 2: - print "You haven't specified any arguments but I need a path. Use -h to get more details on how to use this command." + print "You haven't specified any arguments. Use -h to get more details on how to use this command." + parser = argparse.ArgumentParser() -parser.add_argument('--path', '-p', type=str, default=None, - help='Full path to the point or node whose value is desired. Start querying by typing: $ wc_query /trees/geographic') +parser.add_argument('--username', '-u', type=str, default=None, help='User name for the login to the WebCTRL server') +parser.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') +parser.add_argument('--node', '-n', type=str, default=None, + help='Path to the point or node for which you want to retrieve the present value.') +parser.add_argument('-url', type=str, default='https://webctrl.rz-berlin.mpg.de', help="URL of the WebCTRL server as e.g. http://google.de") args = parser.parse_args() -username = 'wsdl' -password = 'seife' -wsdlFile = 'https://webctrl.rz-berlin.mpg.de/_common/webservices/Eval?wsdl' + +if args.username is None: + print 'No user name specified. Login to WebCTRL needs a user name and password. Check all options for this command via -h' + sys.exit(1) +else: + username = args.username +if args.password is None: + password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') +else: + password = args.password +if args.node is None: + print 'No path to a node specified. Check all options for this command via -h' + sys.exit(1) +if args.url is None: + print 'No URL given. Specify the URL to the WebCTRL server analogous to http://google.de' + sys.exit(1) +else: + wsdlFile = args.url + '/_common/webservices/Eval?wsdl' + try: client = suds.client.Client(wsdlFile, username=username, password=password) @@ -26,16 +48,19 @@ print("Unexpected error:", sys.exc_info()[0]) sys.exit(1) + try: - value = client.service.getValue(args.path) + value = client.service.getValue(args.node) except suds.WebFault as fault: print fault sys.exit(1) + if value is None: print "You haven't specified a particular controller. The command could look like this:" print '$ wc_getValue "#controller/m001"' else: - print "Present value of " + args.path + " is: " + value + print "Present value of " + args.node + " is: " + value + sys.exit(0) diff --git a/wc_query.py b/wc_query.py index f52d7b4..f48cf90 100644 --- a/wc_query.py +++ b/wc_query.py @@ -2,18 +2,42 @@ import sys import xml import argparse +import getpass + if len(sys.argv) < 2: - print "You haven't specified any arguments but I need a path. Use -h to get more details on how to use this command." + print "You haven't specified any arguments. Use -h to get more details on how to use this command." + sys.exit(1) + parser = argparse.ArgumentParser() -parser.add_argument('--path', '-p', type=str, default=None, - help='Path to the point or node whose children you want to retrieve. Start querying with "-p /trees/geographic"') +parser.add_argument('--username', '-u', type=str, default=None, help='User name for the login to the WebCTRL server') +parser.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') +parser.add_argument('--node', '-n', type=str, default=None, + help='Path to the point or node whose children you want to retrieve. Start querying at the lowest level with "-n /trees/geographic"') +parser.add_argument('-url', type=str, default='https://webctrl.rz-berlin.mpg.de', + help="URL of the WebCTRL server as e.g. http://google.de") args = parser.parse_args() -username = 'wsdl' -password = 'seife' -wsdlFile = 'https://webctrl.rz-berlin.mpg.de/_common/webservices/Eval?wsdl' + +if args.username is None: + print 'No user name specified. Login to WebCTRL needs a user name and password. Check all options for this command via -h' + sys.exit(1) +else: + username = args.username +if args.password is None: + password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') +else: + password = args.password +if args.node is None: + print 'No path to a node specified. Check all options for this command via -h' + sys.exit(1) +if args.url is None: + print 'No URL given. Specify the URL to the WebCTRL server analogous to http://google.de' + sys.exit(1) +else: + wsdlFile = args.url + '/_common/webservices/Eval?wsdl' + try: client = suds.client.Client(wsdlFile, username=username, password=password) @@ -24,13 +48,16 @@ sys.exit(1) except: print("Unexpected error:", sys.exc_info()[0]) + print('Perhaps your URL to the WSDL file is not correct.') sys.exit(1) + try: - print 'Children of "' + args.path + '":' - print client.service.getChildren(args.path) + print 'Children of "' + args.node + '":' + print client.service.getChildren(args.node) except suds.WebFault as fault: print fault sys.exit(1) + sys.exit(0)