Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)