diff --git a/conf.d/a10_system_check.yaml.example b/conf.d/a10_system_check.yaml.example new file mode 100644 index 00000000..fdf8710b --- /dev/null +++ b/conf.d/a10_system_check.yaml.example @@ -0,0 +1,7 @@ +init_config: + +instances: + - name: a10_system_check + a10_device: a10_device_ip + a10_username: admin + a10_password: password \ No newline at end of file diff --git a/docs/Plugins.md b/docs/Plugins.md index ca8a8f06..cf5296b2 100644 --- a/docs/Plugins.md +++ b/docs/Plugins.md @@ -118,6 +118,7 @@ The following plugins are delivered via setup as part of the standard plugin che | Setup Plugin Name | Dot File | Detail | | ----------------- | --------- | ---------------------- | +| a10 | | | | apache | /root/.apache.cnf | Apache web server | | cacti | | | | cert_check | | | @@ -289,6 +290,7 @@ These are the detection plugins included with the Monasca Agent. See [Customiza | Detection Plugin Name | Type | | --------------------- | ---------------------- | +| a10 | Plugin | | apache | Plugin | | barbican | ServicePlugin | | bind | Plugin | @@ -441,6 +443,26 @@ These parameters may added to `instances` in the plugin `.yaml` configuration fi By default, all metrics are enabled. +## A10 +This section describes the A10 System Check. + +``` +init_config: + +instances: + - name: a10_system_check + a10_device: a10_device_ip + a10_username: admin + a10_password: password +``` + +| Metric Name | Dimensions | Semantics | +| ----------- | ---------- | --------- | +| a10.memory_total_mb | a10_device, service=networking | Total memory presented in MB +| a10.memory_used_mb | a10_device, service=networking | Memory used presented in MB +| a10.memory_free_mb | a10_device, service=networking | Free memory presented in MB +| a10.memory_used | a10_device, service=networking | Realtime Memory Usage + ## Apache This section describes the Apache Web Server check that can be performed by the Agent. The Apache check gathers metrics on the Apache Web Server. The Apache check requires a configuration file called apache.yaml to be available in the agent conf.d configuration directory. The config file must contain the server url, username and password (If you are using authentication) that you are interested in monitoring. diff --git a/monasca_agent/collector/checks_d/a10_system_check.py b/monasca_agent/collector/checks_d/a10_system_check.py new file mode 100644 index 00000000..c54ff526 --- /dev/null +++ b/monasca_agent/collector/checks_d/a10_system_check.py @@ -0,0 +1,101 @@ +#!/usr/bin/python + +import json +from monasca_agent.collector.checks import AgentCheck +import requests +import requests.adapters +from requests.adapters import HTTPAdapter +from requests.packages import urllib3 +from requests.packages.urllib3.poolmanager import PoolManager +import ssl + + +class SSLHTTPAdapter(HTTPAdapter): + def init_poolmanager(self, connections, maxsize, block=False): + context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + context.options |= ssl.OP_NO_SSLv2 + context.options |= ssl.OP_NO_SSLv3 + self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize, block=block, ssl_version=context) + + +class A10Session(object): + + def __init__(self, device, username, passwd, ssl): + self.device = device + self.username = username + self.passwd = passwd + + def get_authorization_signature(self): + url = "https://" + self.device + "/axapi/v3/auth" + payload = {"credentials": {"username": self.username, "password": self.passwd}} + try: + get_request = requests.post(url=url, headers={"content-type": "application/json"}, + data=json.dumps(payload), verify=False) + except urllib3.exceptions.SSLError as e: + self.log.warning("Caught SSL exception {}".format(e)) + + signature = json.loads(get_request.text) + authorization_signature = str(signature["authresponse"]["signature"]) + return authorization_signature + + def log_out(self, auth_sig): + url = "https://" + self.device + "/axapi/v3/logoff" + requests.post(url=url, headers={"Content-type": "application/json", + "Authorization": "A10 %s" % auth_sig}, verify=False) + + +class A10MemoryCheck(AgentCheck): + + def __init__(self, name, init_config, agent_config): + super(A10MemoryCheck, self).__init__(name, init_config, agent_config) + + def check(self, instance): + a10_device = instance.get("a10_device") + username = instance.get('a10_username') + password = instance.get('a10_password') + dimensions = self._set_dimensions({'service': 'networking', 'a10_device': a10_device}, instance) + + try: + authed_session = A10Session(a10_device, username, password, SSLHTTPAdapter) + self.auth_sig = authed_session.get_authorization_signature() + + # Raise exception and halt program execution + except Exception as e: + self.log.exception(e) + raise + + memory_data = self.get_memory_stats(a10_device) + for key, value in memory_data.items(): + self.gauge(key, value, dimensions) + + try: + authed_session.log_out(self.auth_sig) + # Log a debug exception and continue on + except Exception as e: + self.log.exception(e) + + def get_memory_stats(self, a10_device): + memory_data = {} + try: + url = "https://" + a10_device + "/axapi/v3/system/memory/oper" + try: + request = requests.get(url=url, headers={"Content-type": "application/json", + "Authorization": "A10 %s" % self.auth_sig}, verify=False) + except urllib3.exceptions.SSLError as e: + self.log.warning("Caught SSL exception {}".format(e)) + + data = request.json() + + mem_used = data['memory']['oper']['Usage'] + + convert_kb_to_mb = 1024 + + memory_data['a10.memory_total_mb'] = (data['memory']['oper']['Total']) / convert_kb_to_mb + memory_data['a10.memory_used_mb'] = (data['memory']['oper']['Used']) / convert_kb_to_mb + memory_data['a10.memory_free_mb'] = (data['memory']['oper']['Free']) / convert_kb_to_mb + memory_data['a10.memory_used'] = int(mem_used[:2]) + + except Exception as e: + self.log.exception(e) + + return memory_data