def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:f:c:", ["help"]) except getopt.error, msg: raise Usage(msg) apiKey = None apiSecret = None monitorTag = "loadMonitor" monitorId = None action = 'addResult' filePath = None config = None # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value if option in ("-c"): config = value # cannot continue without the API key and secret if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) if config: # read id, file path, and search depth from config file in CSV reader = csv.reader(open(config, 'r')) for row in reader: (monitorId, path, depth) = map(strip, row) # print fileStats(path,int(depth)) (size, count) = fileStats(path, int(depth)) result = 'size:{0};count:{1}'.format(size, count) print monitis.addResult(monitorId=monitorId, result=result)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:f:c:", ["help"]) except getopt.error, msg: raise Usage(msg) apiKey = None apiSecret = None monitorTag = "loadMonitor" monitorId = None action = "addResult" filePath = None config = None # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value if option in ("-c"): config = value # cannot continue without the API key and secret if (apiKey is None) or (apiSecret is None): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) if config: # read id, file path, and search depth from config file in CSV reader = csv.reader(open(config, "r")) for row in reader: (monitorId, path, depth) = map(strip, row) # print fileStats(path,int(depth)) (size, count) = fileStats(path, int(depth)) result = "size:{0};count:{1}".format(size, count) print monitis.addResult(monitorId=monitorId, result=result)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:", ["help"]) except getopt.error, msg: raise Usage(msg) apiKey = None apiSecret = None monitorTag = "loadMonitor" monitorId = None action = 'addResult' # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value # cannot continue without the API key and secret if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) # Do the disk measurement d = os.statvfs("/") mult = d.f_frsize / 1024 # adjust to report size in kb r = ((d.f_blocks - d.f_bavail) * mult, d.f_blocks * mult, d.f_bavail * mult) print r freespaceResult = \ 'free:{d[0]};cap:{d[1]};avail:{d[2]}'.format(d=r) print monitis.addResult(monitorTag='spaceMonitor', result=freespaceResult)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:",["help"]) except getopt.error, msg: raise Usage(msg) apiKey = None apiSecret = None monitorTag = "loadMonitor" monitorId = None action='addResult' # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value # cannot continue without the API key and secret if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) # Do the disk measurement d = os.statvfs("/") mult = d.f_frsize/1024 # adjust to report size in kb r = ((d.f_blocks - d.f_bavail)*mult,d.f_blocks*mult,d.f_bavail*mult) print r freespaceResult = \ 'free:{d[0]};cap:{d[1]};avail:{d[2]}'.format(d=r) print monitis.addResult(monitorTag='spaceMonitor', result=freespaceResult)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:", ["help"]) except getopt.error, msg: raise Usage(msg) apiKey = None apiSecret = None monitorTag = "loadMonitor" monitorId = None action = 'addResult' # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value # cannot continue without the API key and secret if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) # Do the load averages check, and the add the result to monitis loadAverages = os.getloadavg() loadAveragesResult = \ '1m:{la[0]};5m:{la[1]};15m:{la[2]}'.format(la=loadAverages) print monitis.addResult(monitorTag='loadMonitor', result=loadAveragesResult)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:", ["help"]) except getopt.error, msg: raise Usage(msg) apiKey = None apiSecret = None monitorTag = "loadMonitor" monitorId = None action = "addResult" # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value # cannot continue without the API key and secret if (apiKey is None) or (apiSecret is None): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) # Do the load averages check, and the add the result to monitis loadAverages = os.getloadavg() loadAveragesResult = "1m:{la[0]};5m:{la[1]};15m:{la[2]}".format(la=loadAverages) print monitis.addResult(monitorTag="loadMonitor", result=loadAveragesResult)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:", ["help", "sandbox"]) except getopt.error, msg: raise Usage(msg) apiKey = None apiSecret = None url = None sandbox = False monitorTag = "loadMonitor" monitorId = None action='addResult' # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value if option in ("--sandbox"): sandbox = True url = 'http://sandbox.monitis.com/customMonitorApi' # cannot continue without the API key and secret try: if apiKey: pass elif sandbox: apiKey = os.environ['MONITIS_SANDBOX_APIKEY'] else: apiKey = os.environ['MONITIS_APIKEY'] except: apiKey = None try: if apiSecret: pass elif sandbox: apiSecret = os.environ['MONITIS_SANDBOX_SECRETKEY'] else: apiSecret = os.environ['MONITIS_SECRETKEY'] except: apiSecret = None if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests if url: monitis = MonitisServer(apiKey, apiSecret, url) else: monitis = MonitisServer(apiKey, apiSecret) # Do the load averages check, and the add the result to monitis loadAverages = os.getloadavg() loadAveragesResult = \ '1m:{la[0]};5m:{la[1]};15m:{la[2]}'.format(la=loadAverages) print monitis.addResult(monitorTag='loadMonitor', result=loadAveragesResult)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:q:u:", ["help"]) except getopt.error, msg: raise Usage(msg) # Defaults try: apiKey = os.environ['MONITIS_APIKEY'] except: apiKey = None try: apiSecret = os.environ['MONITIS_SECRET'] except: apiSecret = None monitorTag = "svnMonitor" monitorId = None action = 'addResult' queries = list() repoUrl = None # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value if option in ("-q"): queries.append(value) if option in ("-u"): repoUrl = value # default for queries if none were specified in the args if len(queries) == 0: queries = ['files'] # cannot continue without the API key and secret if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # without the repository URL, there is nothing to query if (repoUrl is None): raise Usage("Repository URL must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) if monitorId is None: try: monitorId = monitis.requestMonitorId(monitorTag) except: raise Usage("Couldn't get ID for monitor tag: " + monitorTag) # query the repository repo = SvnRepository(repoUrl) results = list() for query in queries: # files query if query == 'files': count = len(repo.files()) results.append('svnfiles:{0}'.format(count)) # commits elif query == 'commits': count = len(repo.log()) results.append('commits:{0}'.format(count)) elif query == 'authors': count = len(repo.authors()) results.append('authors:{0}'.format(count)) else: print "Unsupported query type:", query # report the collected value all_results = ';'.join(results) print "Sending result:", all_results print monitis.addResult(monitorId=monitorId, result=all_results)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:f:c:", ["help", "sandbox"]) except getopt.error, msg: raise Usage(msg) apiKey = None apiSecret = None sandbox = False url = None monitorTag = "loadMonitor" monitorId = None action='addResult' filePath = None config = None # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value if option in ("-c"): config = value if option in ("--sandbox"): sandbox = True url = 'http://sandbox.monitis.com/customMonitorApi' try: if apiKey: pass elif sandbox: apiKey = os.environ['MONITIS_SANDBOX_APIKEY'] else: apiKey = os.environ['MONITIS_APIKEY'] except: apiKey = None try: if apiSecret: pass elif sandbox: apiSecret = os.environ['MONITIS_SANDBOX_SECRETKEY'] else: apiSecret = os.environ['MONITIS_SECRETKEY'] except: apiSecret = None # cannot continue without the API key and secret if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests if url: monitis = MonitisServer(apiKey, apiSecret, url) else: monitis = MonitisServer(apiKey, apiSecret) if config: # read id, file path, and search depth from config file in CSV reader = csv.reader(open(config,'r')) for row in reader: (monitorId,path,depth) = map(strip,row) # print fileStats(path,int(depth)) (size,count) = fileStats(path,int(depth)) result = 'size:{0};count:{1}'.format(size,count) print monitis.addResult(monitorId=monitorId,result=result)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "hdla:s:m:i:r:n:", ["help"]) except getopt.error, msg: raise Usage(msg) try: apiKey = os.environ['MONITIS_APIKEY'] except: apiKey = None try: apiSecret = os.environ['MONITIS_SECRET'] except: apiSecret = None monitorTag = None monitorName = None monitorId = None resultParams = None action='addMonitor' # default to add, unless we see a -d opt # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-l"): action = 'listMonitors' if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-n"): monitorName = value if option in ("-r"): resultParams = value if option in ("-i"): monitorId = value if option in ("-d"): action = 'deleteMonitor' # cannot continue without the API key and secret if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) if action is 'addMonitor': if monitorTag is None or monitorTag is '': raise Usage('monitor tag (-m) is required') elif resultParams is None or resultParams is '': raise Usage('result params (-r) is required') elif monitorName is None or monitorName is '': raise Usage('monitor name (-n) is required') else: print monitis.addMonitor(tag=monitorTag, name=monitorName, resultParams=resultParams) elif action is 'deleteMonitor': if monitorId is None or monitorId is '': # try to get id from tag if monitorTag is None or monitorTag is '': raise Usage('A monitor tag or ID is required') else: monitorId = monitis.requestMonitorId(monitorTag) else: print monitis.deleteMonitor(monitorId=monitorId) elif action is 'listMonitors': for monitor in monitis.listMonitors(): print "\t".join(monitor)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "ha:s:m:i:t:q:u:",["help"]) except getopt.error, msg: raise Usage(msg) # Defaults try: apiKey = os.environ['MONITIS_APIKEY'] except: apiKey = None try: apiSecret = os.environ['MONITIS_SECRET'] except: apiSecret = None monitorTag = "svnMonitor" monitorId = None action='addResult' queries=list() repoUrl = None # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-i"): monitorId = value if option in ("-t"): timeStamp = value if option in ("-q"): queries.append(value) if option in ("-u"): repoUrl = value # default for queries if none were specified in the args if len(queries) == 0: queries = ['files'] # cannot continue without the API key and secret if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # without the repository URL, there is nothing to query if (repoUrl is None): raise Usage("Repository URL must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) if monitorId is None: try: monitorId = monitis.requestMonitorId(monitorTag) except: raise Usage("Couldn't get ID for monitor tag: " + monitorTag) # query the repository repo = SvnRepository(repoUrl) results = list() for query in queries: # files query if query == 'files': count = len(repo.files()) results.append('svnfiles:{0}'.format(count)) # commits elif query == 'commits': count = len(repo.log()) results.append('commits:{0}'.format(count)) elif query == 'authors': count = len(repo.authors()) results.append('authors:{0}'.format(count)) else: print "Unsupported query type:", query # report the collected value all_results = ';'.join(results) print "Sending result:", all_results print monitis.addResult(monitorId=monitorId, result=all_results)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "hdla:s:m:i:r:n:", ["help"]) except getopt.error, msg: raise Usage(msg) try: apiKey = os.environ['MONITIS_APIKEY'] except: apiKey = None try: apiSecret = os.environ['MONITIS_SECRET'] except: apiSecret = None monitorTag = None monitorName = None monitorId = None resultParams = None action = 'addMonitor' # default to add, unless we see a -d opt # option processing for option, value in opts: if option in ("-h", "--help"): raise Usage(help_message) if option in ("-a"): apiKey = value if option in ("-l"): action = 'listMonitors' if option in ("-s"): apiSecret = value if option in ("-m"): monitorTag = value if option in ("-n"): monitorName = value if option in ("-r"): resultParams = value if option in ("-i"): monitorId = value if option in ("-d"): action = 'deleteMonitor' # cannot continue without the API key and secret if ((apiKey is None) or (apiSecret is None)): raise Usage("API key and secret must be specified") # Monitis server will be used for all requests monitis = MonitisServer(apiKey, apiSecret) if action is 'addMonitor': if monitorTag is None or monitorTag is '': raise Usage('monitor tag (-m) is required') elif resultParams is None or resultParams is '': raise Usage('result params (-r) is required') elif monitorName is None or monitorName is '': raise Usage('monitor name (-n) is required') else: print monitis.addMonitor(tag=monitorTag, name=monitorName, resultParams=resultParams) elif action is 'deleteMonitor': if monitorId is None or monitorId is '': # try to get id from tag if monitorTag is None or monitorTag is '': raise Usage('A monitor tag or ID is required') else: monitorId = monitis.requestMonitorId(monitorTag) else: print monitis.deleteMonitor(monitorId=monitorId) elif action is 'listMonitors': for monitor in monitis.listMonitors(): print "\t".join(monitor)