def parseBouquets(self, xmlnode):
		#print "parsing Bouquets", xmlnode
		list = []
		for bouquet in xmlnode.getElementsByTagName('e2bouquet'):
			bref = urllib_unquote(bouquet.getElementsByTagName('e2bouquetreference')[0].childNodes[0].data)
			bname = urllib_unquote(bouquet.getElementsByTagName('e2bouquetname')[0].childNodes[0].data)
			#print "Bouquet",bref,bname
			list.append({'bname': bname, 'bref': bref, 'services': self.parseServices(bouquet)})
		return list
	def parseServices(self, xmlnode):
		#print "parsing Services", xmlnode
		list = []
		for service in xmlnode.getElementsByTagName('e2servicelist')[0].getElementsByTagName('e2service'):
			sref = urllib_unquote(service.getElementsByTagName('e2servicereference')[0].childNodes[0].data)
			sname = urllib_unquote(service.getElementsByTagName('e2servicename')[0].childNodes[0].data)
			sname = sname.replace(self.undefinded_tag, "<n/a>").replace(self.undefinded_and, "&")
			#print sref,sname
			list.append({'sref': sref, 'sname': sname})
		return list
Exemplo n.º 3
0
 def __init__(self, url):
     self.url = url
     match = rx_url.match(self.url)
     if not match:
         raise InvalidURLException
     self.scheme = match.group("scheme")
     self.user = urllib_unquote(match.group("user"))
     self.password = urllib_unquote(match.group("password"))
     self.host = match.group("host")
     if match.group("port"):
         self.port = int(match.group("port"))
     else:
         self.port = None
     self.path = match.group("path")
Exemplo n.º 4
0
def read_metrics(module_config):
    """
    Registered read call back function that collects
    metrics from all endpoints
    """
    collectd.debug("Executing read_metrics callback")

    alive = get_response(module_config["base_url"], "ping", module_config)

    if alive is not None:
        prepare_and_dispatch_metric(module_config,
                                    NODE_STATUS_METRICS["ping"].name, alive,
                                    NODE_STATUS_METRICS["ping"].type)

    resp_obj = get_response(module_config["base_url"], "computer",
                            module_config)

    if resp_obj is not None:
        report_slave_status(module_config, resp_obj["computer"])

    resp_obj = get_response(module_config["base_url"], "metrics",
                            module_config)

    if resp_obj is not None:
        parse_and_post_metrics(module_config, resp_obj["gauges"])

    resp_obj = get_response(module_config["base_url"], "healthcheck",
                            module_config)

    if resp_obj is not None:
        parse_and_post_healthcheck(module_config, resp_obj)

    if module_config["exclude_job_metrics"]:
        return

    resp_obj = get_response(module_config["base_url"], "job_tree",
                            module_config)

    if resp_obj is not None:
        jobs = []

        items = resp_obj["jobs"]
        while len(items) > 0:
            item = items.pop()
            if "jobs" in item:
                items.extend(item["jobs"])
            elif "url" in item:
                jobs.append(item)

        for job in jobs:
            if job["name"] in module_config["jobs_last_timestamp"]:
                last_timestamp = module_config["jobs_last_timestamp"][
                    job["name"]]
            else:
                last_timestamp = int(time.time() * 1000) - (60 * 1000)
                module_config["jobs_last_timestamp"][
                    job["name"]] = last_timestamp
            # If the Jenkins instance is configured with Jenkins URL, the Job URL will include the prefix
            # Latest Jenkins versions quote job urls, unquoting as the _api_call func quotes urls
            job_path = urllib.parse.urlparse(job["url"]).path
            if module_config["path"] and job_path.startswith(
                    module_config["path"]):
                job_url = urllib_unquote(job["url"])
            else:
                job_url = module_config["base_url"][:-1] + urllib_unquote(
                    job_path)
            read_and_post_job_metrics(module_config, job_url, job["name"],
                                      last_timestamp)