Beispiel #1
0
    def __init__(self,
                 url,
                 juser,
                 jpass,
                 authtype,
                 ruser=None,
                 rpass=None,
                 proxy='',
                 base='jira',
                 logdir=LOGDIR,
                 logfile=LOGFILE,
                 loglevel=LOGLEVEL,
                 logname=LOGNAME):
        '''Jira connector constructor :
            - url      - server to connect
            - juser    - jira user to use
            - jpass    - jira pass to use
            - ruser    - proxy user to use [Default - None]
            - rpass    - proxy pass to use [Default - None]
            - authtype - Athorization type [Default - BasicAuth]
            - proxy    - Proxy server name if exists [Default - '']
            - base     - REST API base url [Default - 'jira']
        '''

        loglevel = eval('logging.' + os.getenv('LOGLEVEL', loglevel))

        self.log = initLog(logdir, logfile, loglevel, logname)
        self.s_url = "%s/%s/%s" % (url, base, URL_S)
        self.j_url = "%s/%s/%s" % (url, base, URL_J)
        self.juser = juser
        self.jpass = jpass
        self.ruser = ruser
        self.rpass = rpass
        self.authtype = authtype
        self.headers = HEADER
        self.proxy = proxy

        self.sql = ConnectorJiraDjangoSQL()

        # Set noproxy setting
        ips_no_proxy = self.sql.getNoProxyIPsLst()

        if ips_no_proxy:
            ips_no_proxy_str = ','.join(ips_no_proxy)
            os.environ['NO_PROXY'] = "%s;%s" % (os.environ['NO_PROXY'],
                                                ips_no_proxy_str)

        if self.authtype == 'BasicAuthProxy':
            self.auth = HTTPBasicAuth(self.ruser, self.rpass)
        else:
            self.auth = ''

        self.authdata = json.dumps({
            'username': self.juser,
            'password': self.jpass,
        })

        #Get connection session
        self.session = self.getSession()
Beispiel #2
0
    def __init__(self,
                 logdir=LOGDIR,
                 logfile=LOGFILE,
                 loglevel=LOGLEVEL,
                 logname=LOGNAME):
        '''Initialising DataManager object'''

        loglevel = eval('logging.' + os.getenv('LOGLEVEL', loglevel))
        self.log = initLog(logdir, logfile, loglevel, logname)
Beispiel #3
0
    def __init__(self,logdir=LOGDIR, logfile=LOGFILE, loglevel=LOGLEVEL, logname=LOGNAME):

        # If loglevel is supplied on environment level overwrite program supplied
        # value with environment
        self.logdir   = logdir
        self.logfile  = logfile
        self.loglevel = loglevel
        self.logname  = logname

        loglevel = eval('logging.' + os.getenv('LOGLEVEL', loglevel))
        self.log = initLog(logdir, logfile, loglevel, logname)
    def __init__(self,
                 collector_id,
                 logdir=LOGDIR,
                 logfile=LOGFILE,
                 loglevel=LOGLEVEL,
                 logname=LOGNAME):
        '''Constructor : Initialising Jenkins MYSQL collector
            - logdir       - directory to store log data
            - logfile      - name of log file
            - loglevel     - verbose level of logged data
            - logname      - string indefying this log enteries. Used to destinguish between different loggers
        '''

        # If loglevel is supplied on environment level overwrite program supplied
        # value with environmen
        self.logdir = logdir
        self.logfile = logfile
        self.loglevel = loglevel
        self.logname = logname

        self.collector_id = collector_id

        loglevel = eval('logging.' + os.getenv('LOGLEVEL', loglevel))
        self.log = initLog(logdir, logfile, loglevel, logname)

        # Initiate Django SQL connector
        self.sql = ConnectorJiraDjangoSQL()

        # collector ID is set then get data from Database
        (self.hostname, self.project, self.types, self.username, self.password,
         self.rproxyuser, self.rproxypass, self.proxy, self.auth,
         self.apibase) = self.sql.getConnectorConfig(self.collector_id)

        if self.apibase == None:
            self.apibase = ''

        # Check for right collector type - we deal here with Jenkins collectors only
        if not re.match(CTYPE, self.types):
            raise ValueError(
                "Wrong collector type : Collector record with id [%s] is of type [%s] instead of [Jenkins]"
                % (collector_id, ctype))

        # Now specific issue data colelction in case of database read
        self.issue = None

        # In case wrong collector_id was supplied abort execution
        if self.hostname == None or self.project == None:
            self.log.error("Wrong collector id - [%s] ... Aborting ..." %
                           collector_id)
            sys.exit(1)
Beispiel #5
0
    def __init__(self,
                 collector_id,
                 depth=None,
                 logdir=LOGDIR,
                 logfile=LOGFILE,
                 loglevel=LOGLEVEL,
                 logname=LOGNAME):
        '''Constructor : Initialising Jenkins MYSQL collector
            - collector_id - id of collector holding Jenkins access data
            - depth        - depth of data pull
            - logdir       - directory to store log data
            - logfile      - name of log file
            - loglevel     - verbose level of logged data
            - logname      - string indefying this log enteries. Used to destinguish between different self.logs
        '''

        self.collector_id = collector_id
        self.depth = depth

        # If loglevel is supplied on environment level overwrite program supplied
        # value with environment
        self.logdir = logdir
        self.logfile = logfile
        self.loglevel = loglevel
        self.logname = logname
        self.colid = collector_id

        loglevel = eval('logging.' + os.getenv('LOGLEVEL', loglevel))
        self.log = initLog(logdir, logfile, loglevel, logname)

        self.sql = ConnectorJenkinsDjangoSQL()

        #Get connector data based on supplied connector id
        (self.hostname, self.project, ctype, self.username, self.password,
         self.pattern) = self.sql.getConnectorConfig(self.collector_id)

        #Check for right collector type - we deal here with Jenkins collectors only
        if not re.match('[Jj]enkins', ctype):
            raise ValueError(
                "Wrong collector type : Collector record with id [%s] is of type [%s] instead of [Jenkins]"
                % (collector_id, ctype))

        # Initialize tmp directory to store tmp files with collected data sets
        if not os.path.exists(TMP):
            os.makedirs(TMP)

        # Initialise jenkins data collector
        self.jen_data_collector = JenkinsDataCollector(
            self.hostname, self.username, self.password, self.project,
            self.pattern, PIPEBASE, PIPESFX, PIPEWFAPI, PIPENODE, PIPELOG)
    def __init__(self,
                 url=None,
                 juser=None,
                 jpass=None,
                 project=None,
                 issue=None,
                 proxy='',
                 rproxyuser=None,
                 rproxypass='',
                 authtype=None,
                 apibase='',
                 logdir=LOGDIR,
                 logfile=LOGFILE,
                 loglevel=LOGLEVEL,
                 logname=LOGNAME):
        """Jira collector construcor"""

        self.url = url
        self.juser = juser
        self.jpass = jpass
        self.project = project
        self.issue = issue

        #Jira connection additional settings
        self.proxy = proxy  # Possible corporation proxy URL
        self.ruser = rproxyuser  # Reverse proxy user
        self.rpass = rproxypass  # Reverse proxy password
        self.rauth = authtype  # BasicAuth | BacicAuthProxy | ...
        self.apibase = apibase

        #If loglevel is supplied on environment level overwrite program supplied
        #value with environment
        loglevel = eval('logging.' + os.getenv('LOGLEVEL', loglevel))
        self.log = initLog(logdir, logfile, loglevel, logname)

        #Initialize tmp directory to store tmp files with collected data sets
        if not os.path.exists(TMP):
            os.makedirs(TMP)

        #Initialize JIRA connector object
        self.jira = JIRAConnector(self.url, self.juser, self.jpass, self.rauth,
                                  self.ruser, self.rpass, self.proxy,
                                  self.apibase)

        #Initialize tmp file to store results
        self.tfile = tempfile.NamedTemporaryFile(dir=TMP,
                                                 mode='a',
                                                 delete=False,
                                                 prefix='jira')
Beispiel #7
0
    def __init__(self,
                 hostname=None,
                 username=None,
                 password=None,
                 pipeline=None,
                 ptrn=None,
                 pbase=PIPEBASE,
                 psuffix=PIPESFX,
                 wfapi=PIPEWFAPI,
                 pnode=PIPENODE,
                 plog=PIPELOG,
                 pend=PIPEPEND,
                 logdir=LOGDIR,
                 logfile=LOGFILE,
                 loglevel=LOGLEVEL,
                 logname=LOGNAME):
        '''Class constructor'''

        self.hostname = hostname
        self.username = username
        self.password = password
        self.pipeline = pipeline
        self.urlbase = pbase
        self.urlsfx = psuffix
        self.urlwfapi = wfapi
        self.urlnode = pnode
        self.urllog = plog
        self.urlpend = pend
        self.ptrn = ptrn

        # If loglevel is supplied on environment level overwrite program supplied
        # value with environment
        loglevel = eval('logging.' + os.getenv('LOGLEVEL', loglevel))

        self.log = initLog(logdir, logfile, loglevel, logname)
        self.log.info("Initialising Jenkins connector object")

        # Initialising Jenkins collector object
        self.jenkins = ConnectorJenkins(self.hostname, self.username,
                                        self.password, self.pipeline,
                                        self.urlbase, self.urlsfx,
                                        self.urlwfapi, self.urlnode,
                                        self.urllog, self.urlpend)

        # Initialising SQL collector object
        self.sql = ConnectorJenkinsDjangoSQL()
Beispiel #8
0
    def __init__(self,
                 url=None,
                 juser=None,
                 jpass=None,
                 pipeline=None,
                 pbase=PIPEBASE,
                 psuffix=PIPESFX,
                 wfapi=PIPEWFAPI,
                 pnode=PIPENODE,
                 plog=PIPELOG,
                 pend=PIPEPEND,
                 logdir=LOGDIR,
                 logfile=LOGFILE,
                 loglevel=LOGLEVEL,
                 logname=LOGNAME):
        '''Jenkins connector constructor :
                    - jurl     - jenkins server url
                    - juser    - jenkis user to use
                    - jpass    - jenkins pass to use
                    - pipeline - jenkins pipline to fetch as a test
        '''

        loglevel = eval('logging.' + os.getenv('LOGLEVEL', loglevel))

        self.log = initLog(logdir, logfile, loglevel, logname)

        self.jurl = url
        self.juser = juser
        self.jpass = jpass
        self.pipeline = pipeline
        self.urlbase = pbase + '/' + pipeline
        self.urlsfx = psuffix
        self.urlwfapi = wfapi
        self.urlnode = pnode
        self.urllog = plog
        self.urlpend = pend

        self.sql = ConnectorJenkinsDjangoSQL()

        #Get existing noproxy setting name/ip
        ips_no_proxy = self.sql.getNoProxyIPsLst()

        #Set noProxy parameter
        self.setNoProxy(ips_no_proxy)

        #Update /etc/hosts file received settings
        self.setEtcHosts(ips_no_proxy)

        #Verify mandatory parameters.
        errors = 0
        if not url:
            self.log.error("Missing mandatory parameter server URL")
            errors = 1

        if not pipeline:
            self.log.error("Missing mandatory parameter pipeline name")
            errors = 1

        if errors:
            #Abort due to unrecoverable errors
            raise