Beispiel #1
0
    def _get_data(self, instance):
        url = instance.get('nginx_status_url')
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if 'user' in instance and 'password' in instance:
            add_basic_auth(req, instance['user'], instance['password'])

        # Submit a service check for status page availability.
        parsed_url = urlparse.urlparse(url)
        nginx_host = parsed_url.hostname
        nginx_port = parsed_url.port or 80
        service_check_name = 'nginx.can_connect'
        service_check_tags = ['host:%s' % nginx_host, 'port:%s' % nginx_port]
        try:
            response = urllib2.urlopen(req)
        except Exception:
            self.service_check(service_check_name, AgentCheck.CRITICAL,
                               tags=service_check_tags)
            raise
        else:
            self.service_check(service_check_name, AgentCheck.OK,
                               tags=service_check_tags)

        body = response.read()
        resp_headers = response.info()
        return body, resp_headers.get('Content-Type', 'text/plain')
Beispiel #2
0
    def _get_data(self, instance):
        url = instance.get('nginx_status_url')
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if 'user' in instance and 'password' in instance:
            add_basic_auth(req, instance['user'], instance['password'])

        # Submit a service check for status page availability.
        parsed_url = urlparse.urlparse(url)
        nginx_host = parsed_url.hostname
        nginx_port = parsed_url.port or 80
        service_check_name = 'nginx.can_connect'
        service_check_tags = ['host:%s' % nginx_host, 'port:%s' % nginx_port]
        try:
            response = urllib2.urlopen(req)
        except Exception:
            self.service_check(service_check_name, AgentCheck.CRITICAL,
                               tags=service_check_tags)
            raise
        else:
            self.service_check(service_check_name, AgentCheck.OK,
                               tags=service_check_tags)

        body = response.read()
        resp_headers = response.info()
        return body, resp_headers.get('Content-Type', 'text/plain')
Beispiel #3
0
 def _get_data(self, instance):
     url = instance.get('nginx_status_url')
     req = urllib2.Request(url, None, headers(self.agentConfig))
     if 'user' in instance and 'password' in instance:
         add_basic_auth(req, instance['user'], instance['password'])
     request = urllib2.urlopen(req)
     return request.read()
Beispiel #4
0
    def _get_data(self,
                  url,
                  auth=None,
                  send_service_check=False,
                  service_check_tags=None):
        """ Hit a given URL and return the parsed json
            `auth` is a tuple of (username, password) or None
        """
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if auth:
            add_basic_auth(req, *auth)
        try:
            request = urllib2.urlopen(req)
        except urllib2.URLError as e:
            if send_service_check:
                self.service_check(self.SERVICE_CHECK_CONNECT_NAME,
                                   AgentCheck.CRITICAL,
                                   tags=service_check_tags,
                                   message=e.reason)
            raise
        except Exception as e:
            if send_service_check:
                self.service_check(self.SERVICE_CHECK_CONNECT_NAME,
                                   AgentCheck.CRITICAL,
                                   tags=service_check_tags,
                                   message=str(e))
            raise

        response = request.read()
        return json.loads(response)
Beispiel #5
0
 def _get_data(self, instance):
     url = instance.get('nginx_status_url')
     req = urllib2.Request(url, None, headers(self.agentConfig))
     if 'user' in instance and 'password' in instance:
         add_basic_auth(req, instance['user'], instance['password'])
     response = urllib2.urlopen(req)
     body = response.read()
     resp_headers = response.info()
     return body, resp_headers.get('Content-Type', 'text/plain')
Beispiel #6
0
 def _get_data(self, instance):
     url = instance.get("nginx_status_url")
     req = urllib2.Request(url, None, headers(self.agentConfig))
     if "user" in instance and "password" in instance:
         add_basic_auth(req, instance["user"], instance["password"])
     response = urllib2.urlopen(req)
     body = response.read()
     resp_headers = response.info()
     return body, resp_headers.get("Content-Type", "text/plain")
Beispiel #7
0
 def _get_data(self, instance):
     url = instance.get('nginx_status_url')
     req = urllib2.Request(url, None, headers(self.agentConfig))
     if 'user' in instance and 'password' in instance:
         add_basic_auth(req, instance['user'], instance['password'])
     response = urllib2.urlopen(req)
     body = response.read()
     resp_headers = response.info()
     return body, resp_headers.get('Content-Type', 'text/plain')
Beispiel #8
0
    def check(self, instance):
        if 'lighttpd_status_url' not in instance:
            raise Exception("Missing 'lighttpd_status_url' variable in Lighttpd config")

        url = self.assumed_url.get(instance['lighttpd_status_url'], instance['lighttpd_status_url'])

        tags = instance.get('tags', [])
        self.log.debug("Connecting to %s" % url)
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if 'user' in instance and 'password' in instance:
            add_basic_auth(req, instance['user'], instance['password'])
        request = urllib2.urlopen(req)
        headers_resp = request.info().headers
        server_version = self._get_server_version(headers_resp)
        response = request.read()

        metric_count = 0
        # Loop through and extract the numerical values
        for line in response.split('\n'):
            values = line.split(': ')
            if len(values) == 2: # match
                metric, value = values
                try:
                    value = float(value)
                except ValueError:
                    continue

                # Special case: kBytes => bytes
                if metric == 'Total kBytes':
                    value = value * 1024

                # Send metric as a gauge, if applicable
                if metric in self.GAUGES:
                    metric_count += 1
                    metric_name = self.GAUGES[metric]
                    self.gauge(metric_name, value, tags=tags)

                # Send metric as a rate, if applicable
                if metric in self.RATES:
                    metric_count += 1
                    metric_name = self.RATES[metric]
                    self.rate(metric_name, value, tags=tags)

                # Send metric as a counter, if applicable
                if metric in self.COUNTERS:
                    metric_count += 1
                    metric_name = self.COUNTERS[metric]
                    self.increment(metric_name, value, tags=tags)

        if metric_count == 0:
            url_suffix = self.URL_SUFFIX_PER_VERSION[server_version]
            if self.assumed_url.get(instance['lighttpd_status_url'], None) is None and url[-len(url_suffix):] != url_suffix:
                self.assumed_url[instance['lighttpd_status_url']] = '%s%s' % (url, url_suffix)
                self.warning("Assuming url was not correct. Trying to add %s suffix to the url" % url_suffix)
                self.check(instance)
            else:
                raise Exception("No metrics were fetched for this instance. Make sure that %s is the proper url." % instance['lighttpd_status_url'])
Beispiel #9
0
 def _get_data(self, url, auth=None):
     """ Hit a given URL and return the parsed json
         `auth` is a tuple of (username, password) or None
     """
     req = urllib2.Request(url, None, headers(self.agentConfig))
     if auth:
         add_basic_auth(req, *auth)
     request = urllib2.urlopen(req)
     response = request.read()
     return json.loads(response)
Beispiel #10
0
 def _get_data(self, url, auth=None):
     """ Hit a given URL and return the parsed json
         `auth` is a tuple of (username, password) or None
     """
     req = urllib2.Request(url, None, headers(self.agentConfig))
     if auth:
         add_basic_auth(req, *auth)
     request = urllib2.urlopen(req)
     response = request.read()
     return json.loads(response)
Beispiel #11
0
    def _get_stats(self, url, instance):
        """ Hit a given URL and return the parsed json. """
        self.log.debug('Fetching Couchbase stats at url: %s' % url)
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if 'user' in instance and 'password' in instance:
            add_basic_auth(req, instance['user'], instance['password'])

        timeout = float(instance.get('timeout', DEFAULT_TIMEOUT))
        request = urllib2.urlopen(req, timeout=timeout)
        response = request.read()
        return json.loads(response)
Beispiel #12
0
    def _get_stats(self, url, instance):
        "Hit a given URL and return the parsed json"
        self.log.debug('Fetching Couchbase stats at url: %s' % url)
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if 'user' in instance and 'password' in instance:
            add_basic_auth(req, instance['user'], instance['password'])

        # Do the request, log any errors
        request = urllib2.urlopen(req)
        response = request.read()
        return json.loads(response)
Beispiel #13
0
    def _get_stats(self, url, instance):
        """ Hit a given URL and return the parsed json. """
        self.log.debug('Fetching Couchbase stats at url: %s' % url)
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if 'user' in instance and 'password' in instance:
            add_basic_auth(req, instance['user'], instance['password'])

        timeout = float(instance.get('timeout', DEFAULT_TIMEOUT))
        request = urllib2.urlopen(req, timeout=timeout)
        response = request.read()
        return json.loads(response)
Beispiel #14
0
    def _get_stats(self, url, instance):
        "Hit a given URL and return the parsed json"
        self.log.debug('Fetching Couchdb stats at url: %s' % url)
        req = urllib2.Request(url, None, headers(self.agentConfig))

        if 'user' in instance and 'password' in instance:
            add_basic_auth(req, instance['user'], instance['password'])

        # Do the request, log any errors
        request = urllib2.urlopen(req)
        response = request.read()
        return json.loads(response)
Beispiel #15
0
    def check(self, instance):
        if 'apache_status_url' not in instance:
            raise Exception("Missing 'apache_status_url' in Apache config")

        url = self.assumed_url.get(instance['apache_status_url'], instance['apache_status_url'])

        tags = instance.get('tags', [])
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if 'apache_user' in instance and 'apache_password' in instance:
            add_basic_auth(req, instance['apache_user'], instance['apache_password'])
        request = urllib2.urlopen(req)
        response = request.read()

        metric_count = 0
        # Loop through and extract the numerical values
        for line in response.split('\n'):
            values = line.split(': ')
            if len(values) == 2: # match
                metric, value = values
                try:
                    value = float(value)
                except ValueError:
                    continue

                # Special case: kBytes => bytes
                if metric == 'Total kBytes':
                    value = value * 1024

                # Send metric as a gauge, if applicable
                if metric in self.GAUGES:
                    metric_count += 1
                    metric_name = self.GAUGES[metric]
                    self.gauge(metric_name, value, tags=tags)

                # Send metric as a rate, if applicable
                if metric in self.RATES:
                    metric_count += 1
                    metric_name = self.RATES[metric]
                    self.rate(metric_name, value, tags=tags)

        if metric_count == 0:
            if self.assumed_url.get(instance['apache_status_url'], None) is None and url[-5:] != '?auto':
                self.assumed_url[instance['apache_status_url']]= '%s?auto' % url
                self.warning("Assuming url was not correct. Trying to add ?auto suffix to the url")
                self.check(instance)
            else:
                raise Exception("No metrics were fetched for this instance. Make sure that %s is the proper url." % instance['apache_status_url'])
Beispiel #16
0
    def check(self, instance):
        if 'apache_status_url' not in instance:
            raise Exception("Missing 'apache_status_url' in Apache config")

        url = self.assumed_url.get(instance['apache_status_url'], instance['apache_status_url'])

        tags = instance.get('tags', [])
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if 'apache_user' in instance and 'apache_password' in instance:
            add_basic_auth(req, instance['apache_user'], instance['apache_password'])
        request = urllib2.urlopen(req)
        response = request.read()

        metric_count = 0
        # Loop through and extract the numerical values
        for line in response.split('\n'):
            values = line.split(': ')
            if len(values) == 2: # match
                metric, value = values
                try:
                    value = float(value)
                except ValueError:
                    continue

                # Special case: kBytes => bytes
                if metric == 'Total kBytes':
                    value = value * 1024

                # Send metric as a gauge, if applicable
                if metric in self.GAUGES:
                    metric_count += 1
                    metric_name = self.GAUGES[metric]
                    self.gauge(metric_name, value, tags=tags)

                # Send metric as a rate, if applicable
                if metric in self.RATES:
                    metric_count += 1
                    metric_name = self.RATES[metric]
                    self.rate(metric_name, value, tags=tags)

        if metric_count == 0:
            if self.assumed_url.get(instance['apache_status_url'], None) is None and url[-5:] != '?auto':
                self.assumed_url[instance['apache_status_url']]= '%s?auto' % url
                self.warning("Assuming url was not correct. Trying to add ?auto suffix to the url")
                self.check(instance)
            else:
                raise Exception("No metrics were fetched for this instance. Make sure that %s is the proper url." % instance['apache_status_url'])
Beispiel #17
0
    def _get_primary_addr(self, url, node_name, auth):
        """ Returns a list of primary interface addresses as seen by ES.
            Used in ES < 0.19
        """
        req = urllib2.Request(url, None, headers(self.agentConfig))
        # Load basic authentication configuration, if available.
        if auth:
            add_basic_auth(req, *auth)
        request = urllib2.urlopen(req)
        response = request.read()
        data = json.loads(response)

        if node_name in data['nodes']:
            node = data['nodes'][node_name]
            if 'network' in node\
            and 'primary_interface' in node['network']\
            and 'address' in node['network']['primary_interface']:
                return node['network']['primary_interface']['address']

        raise NodeNotFound()
Beispiel #18
0
    def _get_primary_addr(self, url, node_name, auth):
        """ Returns a list of primary interface addresses as seen by ES.
            Used in ES < 0.19
        """
        req = urllib2.Request(url, None, headers(self.agentConfig))
        # Load basic authentication configuration, if available.
        if auth:
            add_basic_auth(req, *auth)
        request = urllib2.urlopen(req)
        response = request.read()
        data = json.loads(response)

        if node_name in data['nodes']:
            node = data['nodes'][node_name]
            if 'network' in node\
            and 'primary_interface' in node['network']\
            and 'address' in node['network']['primary_interface']:
                return node['network']['primary_interface']['address']

        raise NodeNotFound()
Beispiel #19
0
    def _get_data(self, url, auth=None, send_service_check=False, service_check_tags=None):
        """ Hit a given URL and return the parsed json
            `auth` is a tuple of (username, password) or None
        """
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if auth:
            add_basic_auth(req, *auth)
        try:
            request = urllib2.urlopen(req)
        except urllib2.URLError as e:
            if send_service_check:
                self.service_check(self.SERVICE_CHECK_CONNECT_NAME, AgentCheck.CRITICAL,
                tags=service_check_tags, message=e.reason)
            raise
        except Exception as e:
            if send_service_check:
                self.service_check(self.SERVICE_CHECK_CONNECT_NAME, AgentCheck.CRITICAL,
                tags=service_check_tags, message=str(e))
            raise

        response = request.read()
        return json.loads(response)
Beispiel #20
0
    def check(self, instance):
        if 'lighttpd_status_url' not in instance:
            raise Exception("Missing 'lighttpd_status_url' variable in Lighttpd config")

        url = self.assumed_url.get(instance['lighttpd_status_url'], instance['lighttpd_status_url'])

        tags = instance.get('tags', [])
        self.log.debug("Connecting to %s" % url)
        req = urllib2.Request(url, None, headers(self.agentConfig))
        if 'user' in instance and 'password' in instance:
            add_basic_auth(req, instance['user'], instance['password'])

        # Submit a service check for status page availability.
        parsed_url = urlparse.urlparse(url)
        lighttpd_url = parsed_url.hostname
        lighttpd_port = parsed_url.port or 80
        service_check_name = 'lighthttpd.can_connect'
        service_check_tags = ['host:%s' % lighttpd_url, 'port:%s' % lighttpd_port]
        try:
            request = urllib2.urlopen(req)
        except Exception:
            self.service_check(service_check_name, AgentCheck.CRITICAL,
                               tags=service_check_tags)
            raise
        else:
            self.service_check(service_check_name, AgentCheck.OK,
                               tags=service_check_tags)

        headers_resp = request.info().headers
        server_version = self._get_server_version(headers_resp)
        response = request.read()

        metric_count = 0
        # Loop through and extract the numerical values
        for line in response.split('\n'):
            values = line.split(': ')
            if len(values) == 2: # match
                metric, value = values
                try:
                    value = float(value)
                except ValueError:
                    continue

                # Special case: kBytes => bytes
                if metric == 'Total kBytes':
                    value = value * 1024

                # Send metric as a gauge, if applicable
                if metric in self.GAUGES:
                    metric_count += 1
                    metric_name = self.GAUGES[metric]
                    self.gauge(metric_name, value, tags=tags)

                # Send metric as a rate, if applicable
                if metric in self.RATES:
                    metric_count += 1
                    metric_name = self.RATES[metric]
                    self.rate(metric_name, value, tags=tags)

                # Send metric as a counter, if applicable
                if metric in self.COUNTERS:
                    metric_count += 1
                    metric_name = self.COUNTERS[metric]
                    self.increment(metric_name, value, tags=tags)

        if metric_count == 0:
            url_suffix = self.URL_SUFFIX_PER_VERSION[server_version]
            if self.assumed_url.get(instance['lighttpd_status_url'], None) is None and url[-len(url_suffix):] != url_suffix:
                self.assumed_url[instance['lighttpd_status_url']] = '%s%s' % (url, url_suffix)
                self.warning("Assuming url was not correct. Trying to add %s suffix to the url" % url_suffix)
                self.check(instance)
            else:
                raise Exception("No metrics were fetched for this instance. Make sure that %s is the proper url." % instance['lighttpd_status_url'])