Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
webctrl/wc_getTrend.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
80 lines (66 sloc)
3.12 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import suds | |
import sys | |
import xml | |
import argparse | |
import getpass | |
if len(sys.argv) < 2: | |
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('--username', '-u', type=str, default=None, help='Username 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', action='store_true', default=False, | |
help='If specified maxRecords are retrieved from the start. If not specified 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() | |
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 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' | |
try: | |
client = suds.client.Client(wsdlFile, username=username, password=password) | |
except AttributeError: | |
print 'Error: Incorrect username and/or password' | |
except xml.sax._exceptions.SAXParseException: | |
print 'Error: Incorrect/Misspelled WSDL file. It should be: http(s)://URL?wsdl' | |
sys.exit(1) | |
except: | |
print("Unexpected error:", sys.exc_info()[0]) | |
sys.exit(1) | |
try: | |
trendData = client.service.getTrendData(args.node, args.sTime, args.eTime, args.limit, args.maxRec) | |
except suds.WebFault as fault: | |
print fault | |
sys.exit(1) | |
if trendData: | |
for x in range(0, len(trendData) - 1, 2): | |
print trendData[x] + ' ' + trendData[x + 1] | |
else: | |
print 'No data caught. Check your -s and -e time specifications. Perhaps the end time is before the start time.' | |
sys.exit(1) | |
sys.exit(0) |