/moira-trigger-role

Ansible role to create, update and delete Moira triggers

Primary LanguagePythonMIT LicenseMIT

moira-trigger-role

If you're new here, better check out our main README.

Ansible role to create, update and delete Moira triggers based on python-moira-client

Role usage

Installation

Configuration

Role tasks

Installation

Ansible Galaxy

ansible-galaxy install moira-alert.moira-trigger-role

Ansible Role with Makefile

Place the contents from example inside your Makefile to download role from Ansible Galaxy
and create playbook to manage triggers with predefined parameters inside your vars files:

- name: manage moira triggers
  hosts: serviceName
  roles:
    - role: moira-alert.moira-trigger-role
      moira_api: http://localhost:8081/api
      moira_triggers: '{{ ServiceNameTriggers }}'
      delegate_to: 127.0.0.1
      run_once: True
      dry_run: False

Note: All tasks must be done from your ansible control machine

Configuration

Predefine following parameters inside your vars files. Working examples can be found here

Authentication

Parameter Description Type Required Default Example
moira_api Url of Moira API String True N/A http://localhost/api/
moira_auth_custom Custom authorization headers Dictionary False None Authorization: apiKey
moira_auth_user Auth User (Basic Auth) String False None admin
moira_auth_pass Auth Password (Basic Auth) String False None pass
moira_auth_login Auth Login (Basic Auth) String False None admin

Note: Use moira_auth_custom if you're using additional authentication mechanisms instead of
single basic auth, use moira_auth_user, moira_auth_pass and moira_auth_login otherwise.
moira_auth_login must contain value for X-Webauth-User header.

Trigger state

Parameter Description Type Required Choices Default Example
state Desired state of a trigger String True present
absent
N/A present
id Trigger id String True N/A N/A trigger_1
name Trigger name String True N/A N/A Trigger 1
tags List of trigger tags List True N/A N/A - Project
- Service
targets List of trigger targets
See available graphite functions
List True N/A N/A - prefix.*.postfix
warn_value Value to set WARN status Float False N/A None 300
error_value Value to set ERROR status Float False N/A None 600
trigger_type Type of a trigger String False rising
falling
expression
N/A rising
expression C-like expression String False N/A Empty string t1 >= 10 ? ERROR : (t1 >= 1 ? WARN : OK)
ttl When there are no metrics for trigger, Moira will switch metric to TTLState state after TTL seconds Int False N/A 600 600
ttl_state Trigger state at the expiration of 'ttl' String False NODATA
DEL
ERROR
WARN
OK
NODATA WARN
is_remote Use remote storage. Deprecated, use trigger_source instead Bool False True
False
False False
trigger_source Specify trigger source, overrides is_remote String False graphite_local
graphite_remote
prometheus_remote
None graphite_local
cluster_id Specify cluster id String False N/A None default
desc Trigger description String False N/A Empty string trigger test description
mute_new_metrics If true, first event NODATA → OK will be omitted Bool False True
False
False False
disabled_days Days for trigger to be in silent mode List False N/A Empty list - Mon
- Wed
timezone_offset Timezone offset (minutes) Int False N/A 0 -180
start_hour Start hour to send alerts Int False N/A 0 9
start_minute Start minute to send alerts Int False N/A 0 0
end_hour End hour to send alerts Int False N/A 23 17
end_minute End minute to send alerts Int False N/A 59 0
alone_metrics Set some target as single metric Object, example: False N/A {'t1': False, 't2': True, ... 'tN': True} {'t1': False, 't2': False}

Role tasks

Manage dependencies

Task to check python-moira-client is installed (via pip)

Manage triggers

Use state 'present' to create and edit existing triggers:

 - name: create trigger
   moira_trigger:
      ...
      state: present
      ...  

To delete existing triggers use state 'absent':

 - name: remove trigger
   moira_trigger:
      ...
      state: absent
      ...