Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # coding=utf-8
- import time
- import vertica_python
- from checks import AgentCheck
- from hashlib import md5
- class VerticaCheck(AgentCheck):
- def check(self, instance):
- # Load values from config
- default_host = 'localhost'
- default_port = '5433'
- default_database = ''
- default_user = 'dbadmin'
- default_password = ''
- default_schema = 'public'
- default_name = 'name'
- default_timeout = self.init_config.get('default_timeout', 5)
- if 'host' not in instance:
- self.log.info("No host configured, using %s" % default_host)
- elif 'port' not in instance:
- self.log.info("No port configured, using %s" % default_port)
- elif 'database' not in instance:
- self.log.info("No host configured, using %s" % default_database)
- elif 'user' not in instance:
- self.log.info("No user configured, using %s" % default_user)
- elif 'password' not in instance:
- self.log.info("No password configured, using %s" % default_password)
- elif 'schema' not in instance:
- self.log.info("No schema configured, using %s" % default_schema)
- elif 'name' not in instances:
- self.log.info("No name configure, using %s" % default_name)
- host = instance.get('host', default_host)
- port = instance.get('port', default_port)
- database = instance.get('database', default_database)
- user = instance.get('user', default_user)
- password = instance.get('password', default_password)
- schema = instance.get('schema', default_schema)
- name = instance.get('name', default_name)
- aggregation_key = md5(host).hexdigest()
- conn_info = {'host': host, 'port': int(port), 'user': user, 'password': password, 'database': database, 'schema': schema}
- try:
- c = vertica_python.connect(**conn_info)
- except vertica_python.errors.ConnectionError as e:
- self.log.info("Connection error: %s" % e)
- self.vertica_error_event(e, "Could not connect to: %s" % host, host, aggregation_key)
- return
- cursor = c.cursor('dict')
- cursor.execute('select * from system;')
- row = cursor.fetchone()
- cursor.close()
- for col, value in row.iteritems():
- self.gauge('%s.%s' % (name, col), value, tags=['service:vertica'])
- if col == 'node_down_count' and value > 0:
- self.vertica_error_event('%s Vertica node down' % name, '%s Vertica node down' % name, host, aggregation_key)
- def vertica_error_event(self, msg_text, msg_title, host, aggregation_key):
- self.event({
- 'timestamp': int(time.time()),
- 'event_type': 'vertica_check',
- 'msg_title': '%s' % msg_title,
- 'msg_text': 'Error Mesage:\n%s' % msg_text,
- 'aggregation_key': aggregation_key,
- 'alert_type': 'error',
- 'host': host,
- 'tags': ['service:vertica']
- })
- if __name__ == '__main__':
- check, instances = VerticaCheck.from_yaml('/etc/dd-agent/conf.d/vertica.yaml')
- for instance in instances:
- check.check(instances)
- print "\nChecking %s" % (instance['name'])
- if check.has_events():
- print 'Events: %s' % (check.get_events())
- print '%s: %s' % (instance['name'], check.get_metrics())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement