Initial alarm setup.
For the library merged code from https://github.com/hpcloud-mon/ansible-module-monasca Change-Id: Ie387a60f787b79e13d5d430c23dc25a15f5aa2e2
This commit is contained in:
parent
ab85b6291e
commit
fbf1a0074c
10
library/README.md
Normal file
10
library/README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
This directory is for Ansible modules used by this project.
|
||||||
|
|
||||||
|
The modules typically are maintained in separate git repos and added here. The preferred way to add in these repos
|
||||||
|
is with [git-subtree](https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt) as it avoids the end
|
||||||
|
user having to do anything special when downloading the code. Unfortunately this does not play well with gerrit which
|
||||||
|
is used by OpenStack. With the desire to still avoid the special clone syntax used with git submodule the files were just
|
||||||
|
imported from the upstream libraries.
|
||||||
|
|
||||||
|
- monasca comes from https://github.com/hpcloud-mon/ansible-module-monasca.git
|
||||||
|
|
1
library/monasca/.gitignore
vendored
Normal file
1
library/monasca/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea
|
17
library/monasca/README.md
Normal file
17
library/monasca/README.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# ansible-module-monasca
|
||||||
|
Ansible module for crud operations on Monasca alarm definitions
|
||||||
|
|
||||||
|
Example usage
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: Create System Alarm Definitions
|
||||||
|
monasca_alarm_definition:
|
||||||
|
name: "{{item.name}}"
|
||||||
|
expression: "{{item.expression}}"
|
||||||
|
keystone_url: "{{keystone_url}}"
|
||||||
|
keystone_user: "{{keystone_user}}"
|
||||||
|
keystone_password: "{{keystone_password}}"
|
||||||
|
with_items:
|
||||||
|
- { name: "High CPU usage", expression: "avg(cpu.idle_perc) < 10 times 3" }
|
||||||
|
|
||||||
|
More information on [Monasca](https://wiki.openstack.org/wiki/Monasca)
|
145
library/monasca/monasca_alarm_definition
Normal file
145
library/monasca/monasca_alarm_definition
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: monasca_alarm_definition
|
||||||
|
short_description: crud operations on Monasca alarm definitions
|
||||||
|
description:
|
||||||
|
- Performs crud operations (create/update/delete) on monasca alarm definitions
|
||||||
|
- Monasca project homepage - https://wiki.openstack.org/wiki/Monasca
|
||||||
|
author: Tim Kuhlman <tim@backgroundprocess.com>
|
||||||
|
requirements: [ python-monascaclient ]
|
||||||
|
options:
|
||||||
|
api_version:
|
||||||
|
required: false
|
||||||
|
default: '2_0'
|
||||||
|
description:
|
||||||
|
- The monasca api version.
|
||||||
|
description:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- The description associated with the alarm
|
||||||
|
expression:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- The alarm expression, required for create/update operations.
|
||||||
|
keystone_password:
|
||||||
|
required: true
|
||||||
|
description:
|
||||||
|
- Keystone password to use for authentication.
|
||||||
|
keystone_url:
|
||||||
|
required: true
|
||||||
|
description:
|
||||||
|
- Keystone url to authenticate against. Example http://192.168.10.5:5000/v3
|
||||||
|
keystone_user:
|
||||||
|
required: true
|
||||||
|
description:
|
||||||
|
- Keystone user to log in as.
|
||||||
|
monasca_api_url:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- If unset the service endpoing registered with keystone will be used.
|
||||||
|
name:
|
||||||
|
required: true
|
||||||
|
description:
|
||||||
|
- The alarm definition name
|
||||||
|
severity:
|
||||||
|
required: false
|
||||||
|
default: "LOW"
|
||||||
|
description:
|
||||||
|
- The severity set for the alarm must be LOW, MEDIUM, HIGH or CRITICAL
|
||||||
|
state:
|
||||||
|
required: false
|
||||||
|
default: "present"
|
||||||
|
choices: [ present, absent ]
|
||||||
|
description:
|
||||||
|
- Whether the account should exist. When C(absent), removes the user account.
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
monasca_alarm: expression='avg(cpu.idle_perc) < 10 times 3' state=present name='High CPU Usage'
|
||||||
|
keystone_url=http://localhost:5000/v3.0 keystone_user=admin keystone_password=password
|
||||||
|
'''
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
|
||||||
|
try:
|
||||||
|
from monascaclient import client
|
||||||
|
from monascaclient import ksclient
|
||||||
|
import requests
|
||||||
|
except ImportError:
|
||||||
|
monascaclient_found = False
|
||||||
|
else:
|
||||||
|
monascaclient_found = True
|
||||||
|
|
||||||
|
# Todo support check_mode
|
||||||
|
# ),
|
||||||
|
# supports_check_mode=True
|
||||||
|
# todo support setting alarm actions
|
||||||
|
# todo keep the keystone token across multiple runs
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec=dict(
|
||||||
|
api_version=dict(required=False, default='2_0', type='str'),
|
||||||
|
description=dict(required=False, type='str'),
|
||||||
|
expression=dict(required=False, type='str'),
|
||||||
|
keystone_password=dict(required=True, type='str'),
|
||||||
|
keystone_url=dict(required=True, type='str'),
|
||||||
|
keystone_user=dict(required=True, type='str'),
|
||||||
|
monasca_api_url=dict(required=False, type='str'),
|
||||||
|
name=dict(required=True, type='str'),
|
||||||
|
severity=dict(default='LOW', type='str'),
|
||||||
|
state=dict(default='present', choices=['present', 'absent'], type='str')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
name = module.params['name']
|
||||||
|
expression = module.params['expression']
|
||||||
|
|
||||||
|
if not monascaclient_found:
|
||||||
|
module.fail_json(msg="python-monascaclient >= 1.0.9 is required")
|
||||||
|
|
||||||
|
# Authenticate to Keystone
|
||||||
|
ks = ksclient.KSClient(auth_url=module.params['keystone_url'], username=module.params['keystone_user'],
|
||||||
|
password=module.params['keystone_password'])
|
||||||
|
|
||||||
|
# construct the mon client
|
||||||
|
if module.params['monasca_api_url'] is None:
|
||||||
|
api_url = ks.monasca_url
|
||||||
|
else:
|
||||||
|
api_url = module.params['monasca_api_url']
|
||||||
|
monasca = client.Client(module.params['api_version'], api_url, token=ks.token)
|
||||||
|
|
||||||
|
# Find existing definitions
|
||||||
|
definitions = {definition['name']: definition for definition in monasca.alarm_definitions.list()}
|
||||||
|
|
||||||
|
if module.params['state'] == 'absent':
|
||||||
|
if name not in definitions.keys():
|
||||||
|
module.exit_json(changed=False)
|
||||||
|
|
||||||
|
resp = monasca.alarm_definitions.delete(alarm_id=definitions[name].id)
|
||||||
|
if resp.status_code == requests.codes.ok:
|
||||||
|
module.exit_json(changed=True)
|
||||||
|
else:
|
||||||
|
module.fail_json(msg=resp.text)
|
||||||
|
else: # Only other option is state=present
|
||||||
|
def_kwargs = {"name": name, "description": module.params['description'], "expression": expression,
|
||||||
|
"match_by": ["hostname"], "severity": module.params['severity']}
|
||||||
|
|
||||||
|
if name in definitions.keys():
|
||||||
|
if definitions[name]['expression'] == expression:
|
||||||
|
module.exit_json(changed=False)
|
||||||
|
body = monasca.alarm_definitions.patch(**def_kwargs)
|
||||||
|
else:
|
||||||
|
body = monasca.alarm_definitions.create(**def_kwargs)
|
||||||
|
|
||||||
|
if 'id' in body:
|
||||||
|
module.exit_json(changed=True)
|
||||||
|
else:
|
||||||
|
module.fail_json(msg=body)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
40
mini-mon.yml
40
mini-mon.yml
@ -99,3 +99,43 @@
|
|||||||
mysql_password: password,
|
mysql_password: password,
|
||||||
tags: [thresh]}
|
tags: [thresh]}
|
||||||
- {role: tkuhlman.monasca-agent, tags: [agent]}
|
- {role: tkuhlman.monasca-agent, tags: [agent]}
|
||||||
|
|
||||||
|
- name: Define default alarms
|
||||||
|
hosts: mini-mon
|
||||||
|
gather_facts: no
|
||||||
|
vars:
|
||||||
|
keystone_url: http://192.168.10.5:35357/v3/
|
||||||
|
keystone_user: mini-mon
|
||||||
|
keystone_password: password
|
||||||
|
tasks:
|
||||||
|
- name: Create System Alarm Definitions
|
||||||
|
monasca_alarm_definition:
|
||||||
|
name: "{{item.name}}"
|
||||||
|
expression: "{{item.expression}}"
|
||||||
|
keystone_url: "{{keystone_url}}"
|
||||||
|
keystone_user: "{{keystone_user}}"
|
||||||
|
keystone_password: "{{keystone_password}}"
|
||||||
|
with_items:
|
||||||
|
- { name: "High CPU usage", expression: "avg(cpu.idle_perc) < 10 times 3" }
|
||||||
|
- { name: "Disk Inode Usage", expression: "disk.inode_used_perc > 90" }
|
||||||
|
- { name: "Disk Usage", expression: "disk.space_used_perc > 90" }
|
||||||
|
- { name: "Memory usage", expression: "avg(mem.usable_perc) < 10 times 3" }
|
||||||
|
- { name: "Network Errors", expression: "net.in_errors >5 or net.out_errors > 5" }
|
||||||
|
tags:
|
||||||
|
- alarms
|
||||||
|
- system_alarms
|
||||||
|
- name: Create Monasca Alarm Definitions
|
||||||
|
monasca_alarm_definition:
|
||||||
|
name: "{{item.name}}"
|
||||||
|
expression: "{{item.expression}}"
|
||||||
|
keystone_url: "{{keystone_url}}"
|
||||||
|
keystone_user: "{{keystone_user}}"
|
||||||
|
keystone_password: "{{keystone_password}}"
|
||||||
|
with_items:
|
||||||
|
- { name: "Monasca Agent emit time", expression: "avg(monasca.emit_time_sec) > 2 times 3" }
|
||||||
|
- { name: "Monasca Agent collection time", expression: "avg(monasca.collection_time_sec) > 5 times 3" }
|
||||||
|
- { name: "Monasca Configuration DB query time", expression: "avg(monasca.config_db_time.95percentile) > 5 times 3" }
|
||||||
|
- { name: "Zookeeper Average Latency", expression: "avg(zookeeper.avg_latency_sec) > 1 times 3" }
|
||||||
|
tags:
|
||||||
|
- alarms
|
||||||
|
- monasca_alarms
|
||||||
|
Loading…
x
Reference in New Issue
Block a user