Compare commits
35 commits
build-sens
...
master
Author | SHA1 | Date | |
---|---|---|---|
e435cb56a3 | |||
|
b7ab98837a | ||
44ce4e6002 | |||
d90791d467 | |||
d2568959cb | |||
c4e11210c7 | |||
7f915da61c | |||
632258e746 | |||
69a6d0fb03 | |||
d27714948f | |||
af0452b5f7 | |||
7f5377d2b7 | |||
67027a02b2 | |||
8ea56a7e1b | |||
fdeaea2e88 | |||
910b491ba7 | |||
8bcc51a08c | |||
c201ae66fb | |||
dbee6d7a71 | |||
78422e57e0 | |||
27f07c7a30 | |||
3c155cee59 | |||
43ba51b584 | |||
b72347e5cd | |||
99cfaa40a7 | |||
2c9df1967d | |||
7835763dff | |||
0b5ccfa149 | |||
961ce7a773 | |||
53c0b080e8 | |||
671864be35 | |||
f1fd557466 | |||
461c73c7f5 | |||
a1ca0159db | |||
4a5a1aad1a |
37 changed files with 760 additions and 620 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
.kitchen/*
|
.kitchen/*
|
||||||
|
*.pyc
|
||||||
|
|
32
.kitchen.yml
32
.kitchen.yml
|
@ -1,32 +0,0 @@
|
||||||
---
|
|
||||||
driver:
|
|
||||||
name: docker_cli
|
|
||||||
|
|
||||||
transport:
|
|
||||||
name: docker_cli
|
|
||||||
|
|
||||||
provisioner:
|
|
||||||
name: ansible_playbook
|
|
||||||
hosts: localhost
|
|
||||||
require_ansible_repo: false
|
|
||||||
require_ansible_omnibus: false
|
|
||||||
require_chef_for_busser: true
|
|
||||||
ansible_verbose: false
|
|
||||||
ansible_inventory: ./test/integration/inventory
|
|
||||||
|
|
||||||
platforms:
|
|
||||||
- name: debian-9
|
|
||||||
driver_config:
|
|
||||||
image: "nishiki/debian9:ansible-<%= ENV['ANSIBLE_VERSION'] ? ENV['ANSIBLE_VERSION'] : '2.7' %>"
|
|
||||||
command: /bin/systemd
|
|
||||||
volume:
|
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
|
||||||
security_opt: seccomp=unconfined
|
|
||||||
|
|
||||||
suites:
|
|
||||||
- name: default
|
|
||||||
- name: build
|
|
||||||
provisioner:
|
|
||||||
extra_vars:
|
|
||||||
sensu_build: yes
|
|
||||||
sensu_build_go_version: 1.11
|
|
38
.rubocop.yml
38
.rubocop.yml
|
@ -1,38 +0,0 @@
|
||||||
---
|
|
||||||
AllCops:
|
|
||||||
Exclude:
|
|
||||||
- db/**/*
|
|
||||||
- config/**/*
|
|
||||||
- Vagrantfile
|
|
||||||
TargetRubyVersion: 2.4
|
|
||||||
|
|
||||||
Naming/AccessorMethodName:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Lint/RescueWithoutErrorClass:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Metrics/LineLength:
|
|
||||||
Max: 120
|
|
||||||
Metrics/CyclomaticComplexity:
|
|
||||||
Enabled: false
|
|
||||||
Metrics/PerceivedComplexity:
|
|
||||||
Enabled: false
|
|
||||||
Metrics/MethodLength:
|
|
||||||
Enabled: false
|
|
||||||
Metrics/BlockLength:
|
|
||||||
Enabled: false
|
|
||||||
Metrics/ClassLength:
|
|
||||||
Enabled: false
|
|
||||||
Metrics/AbcSize:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Style/NumericLiteralPrefix:
|
|
||||||
Enabled: false
|
|
||||||
Style/FrozenStringLiteralComment:
|
|
||||||
Enabled: false
|
|
||||||
Style/CommandLiteral:
|
|
||||||
Enabled: true
|
|
||||||
EnforcedStyle: percent_x
|
|
||||||
Style/Documentation:
|
|
||||||
Enabled: false
|
|
29
.travis.yml
Normal file
29
.travis.yml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
---
|
||||||
|
sudo: required
|
||||||
|
dist: bionic
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- python3
|
||||||
|
- python3-pip
|
||||||
|
- python3-setuptools
|
||||||
|
|
||||||
|
env:
|
||||||
|
- ANSIBLE_VERSION=2.7.16
|
||||||
|
- ANSIBLE_VERSION=2.8.8
|
||||||
|
- ANSIBLE_VERSION=2.9.4
|
||||||
|
|
||||||
|
services:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- sudo pip3 install ansible==${ANSIBLE_VERSION}
|
||||||
|
- sudo pip3 install molecule 'molecule[docker]' docker testinfra ansible-lint yamllint
|
||||||
|
- git clone https://github.com/ansible/galaxy-lint-rules.git
|
||||||
|
|
||||||
|
script:
|
||||||
|
- ansible --version
|
||||||
|
- molecule test
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
|
@ -2,7 +2,7 @@
|
||||||
extends: default
|
extends: default
|
||||||
|
|
||||||
ignore: |
|
ignore: |
|
||||||
.kitchen/*
|
.kitchen*
|
||||||
vendor/
|
vendor/
|
||||||
|
|
||||||
rules:
|
rules:
|
||||||
|
|
45
CHANGELOG.md
45
CHANGELOG.md
|
@ -4,8 +4,51 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [1.4.0] - 2020-08-09
|
||||||
|
|
||||||
|
### Feat
|
||||||
|
|
||||||
|
- add hooks
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- add full python3 support
|
||||||
|
- remove useless no_log variable
|
||||||
|
|
||||||
|
## [1.3.0] - 2020-04-04
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- add compatibily with new sensu version
|
||||||
|
- remove no_log warnings with sensu_go libraries
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- test: replace kitchen to molecule
|
||||||
|
- add loop label for sensu_go modules
|
||||||
|
|
||||||
|
## [1.2.0] - 2019-06-22
|
||||||
|
|
||||||
|
- feat: add support for ansible 2.8
|
||||||
|
- feat: add labels in checks
|
||||||
|
- feat: add a debug mode with sensu_no_log variable
|
||||||
|
- feat: add mutators
|
||||||
|
- feat: add sensu_agent_redact variable to add new redact keywords
|
||||||
|
- fix: add new return code for api with the version 5.10
|
||||||
|
- fix: handler, asset and filter wasn't idempotent
|
||||||
|
- fix: create roles before users
|
||||||
|
- doc: add example in readme
|
||||||
|
|
||||||
|
## [1.1.0] - 2019-02-17
|
||||||
|
|
||||||
|
- feat: add support of centos 7
|
||||||
|
- feat: add support of ubuntu 16.04
|
||||||
|
- feat: add support of ubuntu 18.04
|
||||||
|
- feat: add multiple namespaces for the checks, filters, handlers or assets
|
||||||
- fix: install python-requests for backend
|
- fix: install python-requests for backend
|
||||||
- fix: install build-essential for agent
|
- test: add travis ci
|
||||||
|
|
||||||
## [1.0.0] - 2019-02-06
|
## [1.0.0] - 2019-02-06
|
||||||
|
|
||||||
- first version
|
- first version
|
||||||
|
|
8
Gemfile
8
Gemfile
|
@ -1,8 +0,0 @@
|
||||||
source 'https://rubygems.org'
|
|
||||||
|
|
||||||
group :development do
|
|
||||||
gem 'kitchen-ansible'
|
|
||||||
gem 'kitchen-docker_cli'
|
|
||||||
gem 'rubocop', '0.50.0'
|
|
||||||
gem 'test-kitchen'
|
|
||||||
end
|
|
92
Gemfile.lock
92
Gemfile.lock
|
@ -1,92 +0,0 @@
|
||||||
GEM
|
|
||||||
remote: https://rubygems.org/
|
|
||||||
specs:
|
|
||||||
ast (2.4.0)
|
|
||||||
builder (3.2.3)
|
|
||||||
erubis (2.7.0)
|
|
||||||
ffi (1.9.25)
|
|
||||||
gssapi (1.2.0)
|
|
||||||
ffi (>= 1.0.1)
|
|
||||||
gyoku (1.3.1)
|
|
||||||
builder (>= 2.1.2)
|
|
||||||
httpclient (2.8.3)
|
|
||||||
kitchen-ansible (0.49.0)
|
|
||||||
net-ssh (>= 3)
|
|
||||||
test-kitchen (~> 1.4)
|
|
||||||
kitchen-docker_cli (0.19.0)
|
|
||||||
test-kitchen (>= 1.3)
|
|
||||||
little-plugger (1.1.4)
|
|
||||||
logging (2.2.2)
|
|
||||||
little-plugger (~> 1.1)
|
|
||||||
multi_json (~> 1.10)
|
|
||||||
mixlib-install (3.11.5)
|
|
||||||
mixlib-shellout
|
|
||||||
mixlib-versioning
|
|
||||||
thor
|
|
||||||
mixlib-shellout (2.4.4)
|
|
||||||
mixlib-versioning (1.2.7)
|
|
||||||
multi_json (1.13.1)
|
|
||||||
net-scp (1.2.1)
|
|
||||||
net-ssh (>= 2.6.5)
|
|
||||||
net-ssh (4.2.0)
|
|
||||||
net-ssh-gateway (1.3.0)
|
|
||||||
net-ssh (>= 2.6.5)
|
|
||||||
nori (2.6.0)
|
|
||||||
parallel (1.12.1)
|
|
||||||
parser (2.5.3.0)
|
|
||||||
ast (~> 2.4.0)
|
|
||||||
powerpack (0.1.2)
|
|
||||||
rainbow (2.2.2)
|
|
||||||
rake
|
|
||||||
rake (12.3.2)
|
|
||||||
rubocop (0.50.0)
|
|
||||||
parallel (~> 1.10)
|
|
||||||
parser (>= 2.3.3.1, < 3.0)
|
|
||||||
powerpack (~> 0.1)
|
|
||||||
rainbow (>= 2.2.2, < 3.0)
|
|
||||||
ruby-progressbar (~> 1.7)
|
|
||||||
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
||||||
ruby-progressbar (1.10.0)
|
|
||||||
rubyntlm (0.6.2)
|
|
||||||
rubyzip (1.2.2)
|
|
||||||
test-kitchen (1.24.0)
|
|
||||||
mixlib-install (~> 3.6)
|
|
||||||
mixlib-shellout (>= 1.2, < 3.0)
|
|
||||||
net-scp (~> 1.1)
|
|
||||||
net-ssh (>= 2.9, < 5.0)
|
|
||||||
net-ssh-gateway (~> 1.2)
|
|
||||||
thor (~> 0.19)
|
|
||||||
winrm (~> 2.0)
|
|
||||||
winrm-elevated (~> 1.0)
|
|
||||||
winrm-fs (~> 1.1)
|
|
||||||
thor (0.20.3)
|
|
||||||
unicode-display_width (1.4.1)
|
|
||||||
winrm (2.3.1)
|
|
||||||
builder (>= 2.1.2)
|
|
||||||
erubis (~> 2.7)
|
|
||||||
gssapi (~> 1.2)
|
|
||||||
gyoku (~> 1.0)
|
|
||||||
httpclient (~> 2.2, >= 2.2.0.2)
|
|
||||||
logging (>= 1.6.1, < 3.0)
|
|
||||||
nori (~> 2.0)
|
|
||||||
rubyntlm (~> 0.6.0, >= 0.6.1)
|
|
||||||
winrm-elevated (1.1.1)
|
|
||||||
winrm (~> 2.0)
|
|
||||||
winrm-fs (~> 1.0)
|
|
||||||
winrm-fs (1.3.2)
|
|
||||||
erubis (~> 2.7)
|
|
||||||
logging (>= 1.6.1, < 3.0)
|
|
||||||
rubyzip (~> 1.1)
|
|
||||||
winrm (~> 2.0)
|
|
||||||
|
|
||||||
PLATFORMS
|
|
||||||
ruby
|
|
||||||
|
|
||||||
DEPENDENCIES
|
|
||||||
kitchen-ansible
|
|
||||||
kitchen-docker_cli
|
|
||||||
rubocop (= 0.50.0)
|
|
||||||
test-kitchen
|
|
||||||
|
|
||||||
BUNDLED WITH
|
|
||||||
1.16.0
|
|
134
README.md
134
README.md
|
@ -1,13 +1,18 @@
|
||||||
# Ansible role: Sensu
|
# Ansible role: Sensu
|
||||||
[![Version](https://img.shields.io/badge/latest_version-1.0.0-green.svg)](https://git.yaegashi.fr/nishiki/ansible-role-sensu/releases)
|
[![Version](https://img.shields.io/badge/latest_version-1.4.0-green.svg)](https://git.yaegashi.fr/nishiki/ansible-role-sensu/releases)
|
||||||
|
[![Build Status](https://travis-ci.org/nishiki/ansible-role-sensu.svg?branch=master)](https://travis-ci.org/nishiki/ansible-role-sensu)
|
||||||
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/ansible-role-sensu/src/branch/master/LICENSE)
|
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/ansible-role-sensu/src/branch/master/LICENSE)
|
||||||
|
|
||||||
Install and configure sensu-go backend and agent
|
Install and configure sensu-go backend and agent
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* Ansible >= 2.7
|
* Ansible >= 2.5
|
||||||
* Debian Stretch
|
* OS
|
||||||
|
* Debian Stretch
|
||||||
|
* Ubuntu 18.04
|
||||||
|
* Ubuntu 16.04
|
||||||
|
* Centos 7
|
||||||
|
|
||||||
## Role variables
|
## Role variables
|
||||||
### General
|
### General
|
||||||
|
@ -15,6 +20,8 @@ Install and configure sensu-go backend and agent
|
||||||
* `sensu_repository_system` - system for package repository (default: `ansible_distribution`)
|
* `sensu_repository_system` - system for package repository (default: `ansible_distribution`)
|
||||||
* `sensu_repository_release` - system release for package repository (default: `ansible_distribution_release`)
|
* `sensu_repository_release` - system release for package repository (default: `ansible_distribution_release`)
|
||||||
|
|
||||||
|
Notice: for debian9 set `sensu_repository_system` to `ubuntu` and `sensu_repository_release` to `xenial`
|
||||||
|
|
||||||
### Agent
|
### Agent
|
||||||
|
|
||||||
* `sensu_agent` - enable sensu agent installation (default: `yes`)
|
* `sensu_agent` - enable sensu agent installation (default: `yes`)
|
||||||
|
@ -38,9 +45,15 @@ Install and configure sensu-go backend and agent
|
||||||
|
|
||||||
```
|
```
|
||||||
region: Europe
|
region: Europe
|
||||||
disk:
|
disk_critical: 90
|
||||||
critical: 90
|
disk_warning: 75
|
||||||
warning: 75
|
```
|
||||||
|
|
||||||
|
* `sensu_agent_redact` - array with the redact keywords
|
||||||
|
|
||||||
|
```
|
||||||
|
- supersecret
|
||||||
|
- apikey
|
||||||
```
|
```
|
||||||
|
|
||||||
* `sensu_agent_backends` - array with the backends url
|
* `sensu_agent_backends` - array with the backends url
|
||||||
|
@ -60,7 +73,8 @@ Install and configure sensu-go backend and agent
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: http-binary
|
- name: http-binary
|
||||||
namespace: default
|
namespace:
|
||||||
|
- default
|
||||||
url: http://host.local
|
url: http://host.local
|
||||||
sha512: XXXX
|
sha512: XXXX
|
||||||
filters: []
|
filters: []
|
||||||
|
@ -77,7 +91,10 @@ Install and configure sensu-go backend and agent
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: load
|
- name: load
|
||||||
namespace: default
|
namespace:
|
||||||
|
- default
|
||||||
|
labels:
|
||||||
|
criticity: high
|
||||||
command: /usr/bin/load -w 2 -c 5
|
command: /usr/bin/load -w 2 -c 5
|
||||||
handlers:
|
handlers:
|
||||||
- mailer
|
- mailer
|
||||||
|
@ -88,11 +105,23 @@ Install and configure sensu-go backend and agent
|
||||||
ttl: 300
|
ttl: 300
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* `sensu_mutators` - array with the mutator definitions
|
||||||
|
|
||||||
|
```
|
||||||
|
- name: convert2csv
|
||||||
|
namespace:
|
||||||
|
- default
|
||||||
|
command: /usr/local/bin/convert_to_csv
|
||||||
|
options:
|
||||||
|
timeout: 10
|
||||||
|
```
|
||||||
|
|
||||||
* `sensu_handlers` - array with the handler definitions
|
* `sensu_handlers` - array with the handler definitions
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: mailer
|
- name: mailer
|
||||||
namespace: default
|
namespace:
|
||||||
|
- default
|
||||||
type: pipe
|
type: pipe
|
||||||
command: /usr/local/bin/sensu-email-handler -t sensu@host.local
|
command: /usr/local/bin/sensu-email-handler -t sensu@host.local
|
||||||
filters:
|
filters:
|
||||||
|
@ -101,11 +130,22 @@ Install and configure sensu-go backend and agent
|
||||||
timeout: 10
|
timeout: 10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* `sensu_hooks` - array with the hook definitions
|
||||||
|
|
||||||
|
```
|
||||||
|
- name: restart-apache
|
||||||
|
namespace:
|
||||||
|
- default
|
||||||
|
command: /etc/init.d/apache2 restart
|
||||||
|
timeout: 10
|
||||||
|
```
|
||||||
|
|
||||||
* `sensu_filters` - array with the filter definitions
|
* `sensu_filters` - array with the filter definitions
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: max_occurences
|
- name: max_occurences
|
||||||
namespace: default
|
namespace:
|
||||||
|
- default
|
||||||
action: allow
|
action: allow
|
||||||
expressions:
|
expressions:
|
||||||
runtime_assets: []
|
runtime_assets: []
|
||||||
|
@ -140,33 +180,75 @@ Install and configure sensu-go backend and agent
|
||||||
* `sensu_api_password` - password for sensu api (default: `P@ssw0rd!`)
|
* `sensu_api_password` - password for sensu api (default: `P@ssw0rd!`)
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
### Agent
|
||||||
|
|
||||||
|
```
|
||||||
|
- hosts: webserver
|
||||||
|
roles:
|
||||||
|
- sensu
|
||||||
|
vars:
|
||||||
|
sensu_agent_subscriptions:
|
||||||
|
- debian
|
||||||
|
- webserver
|
||||||
|
sensu_agent_labels:
|
||||||
|
datacenter: paris
|
||||||
|
disk_warning: 30
|
||||||
|
disk_critical: 50
|
||||||
|
sensu_agent_plugins:
|
||||||
|
- name: sensu-plugins-disk-checks
|
||||||
|
version: 3.1.1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Backend
|
||||||
|
|
||||||
```
|
```
|
||||||
- hosts: monitoring
|
- hosts: monitoring
|
||||||
roles:
|
roles:
|
||||||
- sensu
|
- sensu
|
||||||
|
vars:
|
||||||
|
sensu_backend: yes
|
||||||
|
sensu_namespaces:
|
||||||
|
- name: production
|
||||||
|
- name: dev
|
||||||
|
sensu_users:
|
||||||
|
- name: johndoe
|
||||||
|
password: secret1234
|
||||||
|
groups:
|
||||||
|
- devops
|
||||||
|
- users
|
||||||
|
sensu_handlers:
|
||||||
|
- name: mail
|
||||||
|
command: /usr/local/bin/handler-mailer
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
|
sensu_filters:
|
||||||
|
- name: state_changed
|
||||||
|
expressions:
|
||||||
|
- event.check.occurrences == 1
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
|
sensu_checks:
|
||||||
|
- name: ping
|
||||||
|
command: ping -c 1 127.0.0.1
|
||||||
|
subscriptions:
|
||||||
|
- linux
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
|
sensu_cluster_roles:
|
||||||
|
- name: superview
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
### Test syntax with yamllint
|
|
||||||
|
|
||||||
* install `python` and `python-pip`
|
### Test with molecule and docker
|
||||||
* install yamllint `pip install yamllint`
|
|
||||||
* run `yamllint .`
|
|
||||||
|
|
||||||
### Test syntax with ansible-lint
|
|
||||||
|
|
||||||
* install `python` and `python-pip`
|
|
||||||
* install yamllint `pip install ansible-lint`
|
|
||||||
* run `ansible-lint .`
|
|
||||||
|
|
||||||
### Tests with docker
|
|
||||||
|
|
||||||
* install [docker](https://docs.docker.com/engine/installation/)
|
* install [docker](https://docs.docker.com/engine/installation/)
|
||||||
* install ruby
|
* install `python3` and `python3-pip`
|
||||||
* install bundler `gem install bundler`
|
* install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
|
||||||
* install dependencies `bundle install`
|
* run `molecule test`
|
||||||
* run the tests `kitchen test`
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,6 @@
|
||||||
sensu_agent: yes
|
sensu_agent: yes
|
||||||
sensu_backend: no
|
sensu_backend: no
|
||||||
|
|
||||||
sensu_build_agent: no
|
|
||||||
sensu_build_go_version: 1.7
|
|
||||||
sensu_build_version: 5.1.1
|
|
||||||
|
|
||||||
sensu_repository_system: '{{ ansible_distribution|lower }}'
|
sensu_repository_system: '{{ ansible_distribution|lower }}'
|
||||||
sensu_repository_release: '{{ ansible_distribution_release }}'
|
sensu_repository_release: '{{ ansible_distribution_release }}'
|
||||||
|
|
||||||
|
@ -19,6 +15,17 @@ sensu_agent_password: 'P@ssw0rd!'
|
||||||
sensu_agent_plugins: []
|
sensu_agent_plugins: []
|
||||||
sensu_agent_subscriptions: []
|
sensu_agent_subscriptions: []
|
||||||
sensu_agent_labels: {}
|
sensu_agent_labels: {}
|
||||||
|
sensu_agent_default_redact:
|
||||||
|
- password
|
||||||
|
- passwd
|
||||||
|
- pass
|
||||||
|
- secret
|
||||||
|
- api_key
|
||||||
|
- api_token
|
||||||
|
- access_key
|
||||||
|
- secret_key
|
||||||
|
- private_key
|
||||||
|
sensu_agent_redact: []
|
||||||
sensu_agent_backends:
|
sensu_agent_backends:
|
||||||
- 'ws://localhost:8081'
|
- 'ws://localhost:8081'
|
||||||
sensu_agent_namespace: default
|
sensu_agent_namespace: default
|
||||||
|
@ -30,6 +37,7 @@ sensu_agent_default_config:
|
||||||
password: '{{ sensu_agent_password }}'
|
password: '{{ sensu_agent_password }}'
|
||||||
subscriptions: '{{ sensu_agent_subscriptions }}'
|
subscriptions: '{{ sensu_agent_subscriptions }}'
|
||||||
labels: '{{ sensu_agent_labels }}'
|
labels: '{{ sensu_agent_labels }}'
|
||||||
|
redact: '{{ sensu_agent_default_redact + sensu_agent_redact }}'
|
||||||
sensu_agent_config: {}
|
sensu_agent_config: {}
|
||||||
sensu_agent_full_config: '{{ sensu_agent_default_config|combine(sensu_agent_config) }}'
|
sensu_agent_full_config: '{{ sensu_agent_default_config|combine(sensu_agent_config) }}'
|
||||||
|
|
||||||
|
@ -45,3 +53,5 @@ sensu_handlers: []
|
||||||
sensu_filters: []
|
sensu_filters: []
|
||||||
sensu_users: []
|
sensu_users: []
|
||||||
sensu_cluster_roles: []
|
sensu_cluster_roles: []
|
||||||
|
sensu_mutators: []
|
||||||
|
sensu_hooks: []
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=The Sensu Agent process.
|
|
||||||
After=network-online.target
|
|
||||||
Wants=network-online.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=sensu
|
|
||||||
Group=sensu
|
|
||||||
LimitNOFILE=65535
|
|
||||||
ExecStart=/usr/local/bin/sensu-agent start
|
|
||||||
Restart=always
|
|
||||||
WorkingDirectory=/
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -21,8 +21,8 @@ class SensuAsset:
|
||||||
}
|
}
|
||||||
|
|
||||||
def has_changed(self, options):
|
def has_changed(self, options):
|
||||||
for option, value in self.options.iteritems():
|
for option, value in self.options.items():
|
||||||
if options[option] != value:
|
if (options[option] or value) and options[option] != value:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -43,13 +43,13 @@ class SensuAsset:
|
||||||
def main():
|
def main():
|
||||||
fields = {
|
fields = {
|
||||||
'name': { 'type': 'str', 'required': True },
|
'name': { 'type': 'str', 'required': True },
|
||||||
'namespace': { 'type': 'str', 'default': 'default' },
|
'namespaces': { 'type': 'list', 'default': ['default'] },
|
||||||
'url': { 'type': 'str', 'required': True },
|
'url': { 'type': 'str', 'required': True },
|
||||||
'sha512': { 'type': 'str', 'required': True },
|
'sha512': { 'type': 'str', 'required': True },
|
||||||
'filters': { 'type': 'list', 'default': [] },
|
'filters': { 'type': 'list', 'default': [] },
|
||||||
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
||||||
'api_user': { 'type': 'str', 'default': 'admin' },
|
'api_user': { 'type': 'str', 'default': 'admin' },
|
||||||
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!', 'no_log': True },
|
||||||
}
|
}
|
||||||
module = AnsibleModule(argument_spec=fields)
|
module = AnsibleModule(argument_spec=fields)
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -67,17 +67,18 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
asset = SensuAsset(
|
for namespace in module.params['namespaces']:
|
||||||
api,
|
asset = SensuAsset(
|
||||||
module.params['name'],
|
api,
|
||||||
module.params['namespace']
|
module.params['name'],
|
||||||
)
|
namespace
|
||||||
asset.get_data()
|
)
|
||||||
|
asset.get_data()
|
||||||
|
|
||||||
if not asset.exist or asset.has_changed(options):
|
if not asset.exist or asset.has_changed(options):
|
||||||
asset.create(options)
|
asset.create(options)
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed)
|
||||||
|
|
||||||
|
|
|
@ -4,21 +4,42 @@ from ansible.module_utils.basic import *
|
||||||
from ansible.module_utils.sensu_api import *
|
from ansible.module_utils.sensu_api import *
|
||||||
|
|
||||||
class SensuCheck:
|
class SensuCheck:
|
||||||
def __init__(self, api, name, namespace):
|
def __init__(self, api, name, namespace, labels):
|
||||||
self.api = api
|
self.api = api
|
||||||
self.name = name
|
self.name = name
|
||||||
self.namespace = namespace
|
self.namespace = namespace
|
||||||
|
self.labels = labels
|
||||||
self.exist = False
|
self.exist = False
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
status_code, data = self.api.get('namespaces/{}/checks/{}'.format(self.namespace, self.name))
|
status_code, data = self.api.get('namespaces/{}/checks/{}'.format(self.namespace, self.name))
|
||||||
if status_code == 200:
|
if status_code == 200:
|
||||||
self.exist = True
|
self.exist = True
|
||||||
self.options = data
|
return data
|
||||||
self.options.pop('metadata')
|
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def labels_has_changed(self, new_labels, old_labels):
|
||||||
|
if not old_labels and not new_labels:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if len(new_labels) != len(old_labels):
|
||||||
|
return True
|
||||||
|
|
||||||
|
for old_label, old_value in old_labels.items():
|
||||||
|
if old_label in new_labels and new_labels[old_label] == old_value:
|
||||||
|
continue
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def has_changed(self, options):
|
def has_changed(self, options):
|
||||||
for option, value in self.options.iteritems():
|
data = self.get_data()
|
||||||
|
if self.labels_has_changed(self.labels, data['metadata'].get('labels')):
|
||||||
|
return True
|
||||||
|
|
||||||
|
data.pop('metadata')
|
||||||
|
for option, value in data.items():
|
||||||
if not option in options:
|
if not option in options:
|
||||||
if value:
|
if value:
|
||||||
return True
|
return True
|
||||||
|
@ -31,7 +52,8 @@ class SensuCheck:
|
||||||
options.update({
|
options.update({
|
||||||
'metadata': {
|
'metadata': {
|
||||||
'name': self.name,
|
'name': self.name,
|
||||||
'namespace': self.namespace
|
'namespace': self.namespace,
|
||||||
|
'labels': self.labels
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -49,7 +71,8 @@ class SensuCheck:
|
||||||
def main():
|
def main():
|
||||||
fields = {
|
fields = {
|
||||||
'name': { 'type': 'str', 'required': True },
|
'name': { 'type': 'str', 'required': True },
|
||||||
'namespace': { 'type': 'str', 'default': 'default' },
|
'namespaces': { 'type': 'list', 'default': ['default'] },
|
||||||
|
'labels': { 'type': 'dict', 'default': {} },
|
||||||
'command': { 'type': 'str', 'required': True },
|
'command': { 'type': 'str', 'required': True },
|
||||||
'handlers': { 'type': 'list', 'default': [] },
|
'handlers': { 'type': 'list', 'default': [] },
|
||||||
'subscriptions': { 'type': 'list', 'required': True },
|
'subscriptions': { 'type': 'list', 'required': True },
|
||||||
|
@ -57,7 +80,7 @@ def main():
|
||||||
'options': { 'type': 'dict', 'default': {} },
|
'options': { 'type': 'dict', 'default': {} },
|
||||||
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
||||||
'api_user': { 'type': 'str', 'default': 'admin' },
|
'api_user': { 'type': 'str', 'default': 'admin' },
|
||||||
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!', 'no_log': True },
|
||||||
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
||||||
}
|
}
|
||||||
module = AnsibleModule(argument_spec=fields)
|
module = AnsibleModule(argument_spec=fields)
|
||||||
|
@ -81,20 +104,22 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
check = SensuCheck(
|
for namespace in module.params['namespaces']:
|
||||||
api,
|
check = SensuCheck(
|
||||||
module.params['name'],
|
api,
|
||||||
module.params['namespace']
|
module.params['name'],
|
||||||
)
|
namespace,
|
||||||
check.get_data()
|
module.params['labels']
|
||||||
|
)
|
||||||
|
check.get_data()
|
||||||
|
|
||||||
if module.params['state'] == 'present':
|
if module.params['state'] == 'present':
|
||||||
if not check.exist or check.has_changed(options):
|
if not check.exist or check.has_changed(options):
|
||||||
check.create(options)
|
check.create(options)
|
||||||
changed = True
|
changed = True
|
||||||
elif check.exist:
|
elif check.exist:
|
||||||
check.delete()
|
check.delete()
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed)
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,14 @@ class SensuClusterRole:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
for i in range(0, len(self.options['rules'])):
|
for i in range(0, len(self.options['rules'])):
|
||||||
for rule, value in self.options['rules'][i].iteritems():
|
for rule, value in self.options['rules'][i].items():
|
||||||
if not rule in options['rules'][i]:
|
if not rule in options['rules'][i]:
|
||||||
if value:
|
if value:
|
||||||
return True
|
return True
|
||||||
elif options['rules'][i][rule] != value:
|
elif options['rules'][i][rule] != value:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
for rule, value in options['rules'][i].iteritems():
|
for rule, value in options['rules'][i].items():
|
||||||
if not rule in self.options['rules'][i]:
|
if not rule in self.options['rules'][i]:
|
||||||
if value:
|
if value:
|
||||||
return True
|
return True
|
||||||
|
@ -63,7 +63,7 @@ def main():
|
||||||
'rules': { 'type': 'list', 'required': True },
|
'rules': { 'type': 'list', 'required': True },
|
||||||
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
||||||
'api_user': { 'type': 'str', 'default': 'admin' },
|
'api_user': { 'type': 'str', 'default': 'admin' },
|
||||||
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!', 'no_log': True },
|
||||||
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
||||||
}
|
}
|
||||||
module = AnsibleModule(argument_spec=fields)
|
module = AnsibleModule(argument_spec=fields)
|
||||||
|
|
|
@ -18,11 +18,11 @@ class SensuFilter:
|
||||||
self.options.pop('metadata')
|
self.options.pop('metadata')
|
||||||
|
|
||||||
def has_changed(self, options):
|
def has_changed(self, options):
|
||||||
for option, value in self.options.iteritems():
|
for option, value in self.options.items():
|
||||||
if not option in options:
|
if not option in options:
|
||||||
if value:
|
if value:
|
||||||
return True
|
return True
|
||||||
elif options[option] != value:
|
elif (options[option] or value) and options[option] != value:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -49,13 +49,13 @@ class SensuFilter:
|
||||||
def main():
|
def main():
|
||||||
fields = {
|
fields = {
|
||||||
'name': { 'type': 'str', 'required': True },
|
'name': { 'type': 'str', 'required': True },
|
||||||
'namespace': { 'type': 'str', 'default': 'default' },
|
'namespaces': { 'type': 'list', 'default': ['default'] },
|
||||||
'action': { 'type': 'str', 'default': 'allow', 'choices': ['allow', 'deny'] },
|
'action': { 'type': 'str', 'default': 'allow', 'choices': ['allow', 'deny'] },
|
||||||
'expressions': { 'type': 'list', 'required': True },
|
'expressions': { 'type': 'list', 'required': True },
|
||||||
'runtime_assets': { 'type': 'list', 'default': [] },
|
'runtime_assets': { 'type': 'list', 'default': [] },
|
||||||
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
||||||
'api_user': { 'type': 'str', 'default': 'admin' },
|
'api_user': { 'type': 'str', 'default': 'admin' },
|
||||||
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!', 'no_log': True },
|
||||||
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
||||||
}
|
}
|
||||||
module = AnsibleModule(argument_spec=fields)
|
module = AnsibleModule(argument_spec=fields)
|
||||||
|
@ -74,20 +74,21 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
filter = SensuFilter(
|
for namespace in module.params['namespaces']:
|
||||||
api,
|
filter = SensuFilter(
|
||||||
module.params['name'],
|
api,
|
||||||
module.params['namespace']
|
module.params['name'],
|
||||||
)
|
namespace
|
||||||
filter.get_data()
|
)
|
||||||
|
filter.get_data()
|
||||||
|
|
||||||
if module.params['state'] == 'present':
|
if module.params['state'] == 'present':
|
||||||
if not filter.exist or filter.has_changed(options):
|
if not filter.exist or filter.has_changed(options):
|
||||||
filter.create(options)
|
filter.create(options)
|
||||||
changed = True
|
changed = True
|
||||||
elif filter.exist:
|
elif filter.exist:
|
||||||
filter.delete()
|
filter.delete()
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed)
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,11 @@ class SensuHandler:
|
||||||
self.options.pop('metadata')
|
self.options.pop('metadata')
|
||||||
|
|
||||||
def has_changed(self, options):
|
def has_changed(self, options):
|
||||||
for option, value in self.options.iteritems():
|
for option, value in self.options.items():
|
||||||
if not option in options:
|
if not option in options:
|
||||||
if value:
|
if value:
|
||||||
return True
|
return True
|
||||||
elif options[option] != value:
|
elif (options[option] or value) and options[option] != value:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -49,14 +49,14 @@ class SensuHandler:
|
||||||
def main():
|
def main():
|
||||||
fields = {
|
fields = {
|
||||||
'name': { 'type': 'str', 'required': True },
|
'name': { 'type': 'str', 'required': True },
|
||||||
'namespace': { 'type': 'str', 'default': 'default' },
|
'namespaces': { 'type': 'list', 'default': ['default'] },
|
||||||
'type': { 'type': 'str', 'default': 'pipe', 'choices': ['pipe', 'tcp', 'udp', 'set'] },
|
'type': { 'type': 'str', 'default': 'pipe', 'choices': ['pipe', 'tcp', 'udp', 'set'] },
|
||||||
'command': { 'type': 'str', 'required': True },
|
'command': { 'type': 'str', 'required': True },
|
||||||
'filters': { 'type': 'list', 'default': [] },
|
'filters': { 'type': 'list', 'default': [] },
|
||||||
'options': { 'type': 'dict', 'default': {} },
|
'options': { 'type': 'dict', 'default': {} },
|
||||||
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
||||||
'api_user': { 'type': 'str', 'default': 'admin' },
|
'api_user': { 'type': 'str', 'default': 'admin' },
|
||||||
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!', 'no_log': True },
|
||||||
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
||||||
}
|
}
|
||||||
module = AnsibleModule(argument_spec=fields)
|
module = AnsibleModule(argument_spec=fields)
|
||||||
|
@ -76,20 +76,21 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
handler = SensuHandler(
|
for namespace in module.params['namespaces']:
|
||||||
api,
|
handler = SensuHandler(
|
||||||
module.params['name'],
|
api,
|
||||||
module.params['namespace']
|
module.params['name'],
|
||||||
)
|
namespace
|
||||||
handler.get_data()
|
)
|
||||||
|
handler.get_data()
|
||||||
|
|
||||||
if module.params['state'] == 'present':
|
if module.params['state'] == 'present':
|
||||||
if not handler.exist or handler.has_changed(options):
|
if not handler.exist or handler.has_changed(options):
|
||||||
handler.create(options)
|
handler.create(options)
|
||||||
changed = True
|
changed = True
|
||||||
elif handler.exist:
|
elif handler.exist:
|
||||||
handler.delete()
|
handler.delete()
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed)
|
||||||
|
|
||||||
|
|
95
library/sensugo_hook.py
Normal file
95
library/sensugo_hook.py
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
from ansible.module_utils.sensu_api import *
|
||||||
|
|
||||||
|
class SensuHook:
|
||||||
|
def __init__(self, api, name, namespace):
|
||||||
|
self.api = api
|
||||||
|
self.name = name
|
||||||
|
self.namespace = namespace
|
||||||
|
self.exists = False
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
status_code, data = self.api.get('namespaces/{}/hooks/{}'.format(self.namespace, self.name))
|
||||||
|
if status_code == 200:
|
||||||
|
self.exists = True
|
||||||
|
return data
|
||||||
|
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def has_changed(self, options):
|
||||||
|
data = self.get_data()
|
||||||
|
data.pop('metadata')
|
||||||
|
for option, value in data.items():
|
||||||
|
if not option in options:
|
||||||
|
if value:
|
||||||
|
return True
|
||||||
|
elif options[option] != value:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def create(self, options):
|
||||||
|
options.update({
|
||||||
|
'metadata': {
|
||||||
|
'name': self.name,
|
||||||
|
'namespace': self.namespace
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.api.put(
|
||||||
|
'namespaces/{}/hooks/{}'.format(self.namespace, self.name),
|
||||||
|
options
|
||||||
|
)
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
self.api.delete(
|
||||||
|
'namespaces/{}/hooks/{}'.format(self.namespace, self.name)
|
||||||
|
)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
fields = {
|
||||||
|
'name': { 'type': 'str', 'required': True },
|
||||||
|
'namespaces': { 'type': 'list', 'default': ['default'] },
|
||||||
|
'command': { 'type': 'str', 'required': True },
|
||||||
|
'timeout': { 'type': 'int', 'default': 10 },
|
||||||
|
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
||||||
|
'api_user': { 'type': 'str', 'default': 'admin' },
|
||||||
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!', 'no_log': True },
|
||||||
|
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
||||||
|
}
|
||||||
|
module = AnsibleModule(argument_spec=fields)
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
options = {
|
||||||
|
'command': module.params['command'],
|
||||||
|
'timeout': module.params['timeout']
|
||||||
|
}
|
||||||
|
api = SensuApi(
|
||||||
|
module.params['api_url'],
|
||||||
|
module.params['api_user'],
|
||||||
|
module.params['api_password']
|
||||||
|
)
|
||||||
|
api.auth()
|
||||||
|
|
||||||
|
for namespace in module.params['namespaces']:
|
||||||
|
hook = SensuHook(
|
||||||
|
api,
|
||||||
|
module.params['name'],
|
||||||
|
namespace
|
||||||
|
)
|
||||||
|
hook.get_data()
|
||||||
|
|
||||||
|
if module.params['state'] == 'present':
|
||||||
|
if not hook.exists or hook.has_changed(options):
|
||||||
|
hook.create(options)
|
||||||
|
changed = True
|
||||||
|
elif hook.exists:
|
||||||
|
hook.delete()
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
module.exit_json(changed=changed)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
94
library/sensugo_mutator.py
Normal file
94
library/sensugo_mutator.py
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
from ansible.module_utils.sensu_api import *
|
||||||
|
|
||||||
|
class SensuMutator:
|
||||||
|
def __init__(self, api, name, namespace):
|
||||||
|
self.api = api
|
||||||
|
self.name = name
|
||||||
|
self.namespace = namespace
|
||||||
|
self.exist = False
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
status_code, data = self.api.get('namespaces/{}/mutators/{}'.format(self.namespace, self.name))
|
||||||
|
if status_code == 200:
|
||||||
|
self.exist = True
|
||||||
|
self.options = data
|
||||||
|
self.options.pop('metadata')
|
||||||
|
|
||||||
|
def has_changed(self, options):
|
||||||
|
for option, value in self.options.items():
|
||||||
|
if not option in options:
|
||||||
|
if value:
|
||||||
|
return True
|
||||||
|
elif options[option] != value:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def create(self, options):
|
||||||
|
options.update({
|
||||||
|
'metadata': {
|
||||||
|
'name': self.name,
|
||||||
|
'namespace': self.namespace
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.api.put(
|
||||||
|
'namespaces/{}/mutators/{}'.format(self.namespace, self.name),
|
||||||
|
options
|
||||||
|
)
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
self.api.delete(
|
||||||
|
'namespaces/{}/mutators/{}'.format(self.namespace, self.name)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
fields = {
|
||||||
|
'name': { 'type': 'str', 'required': True },
|
||||||
|
'namespaces': { 'type': 'list', 'default': ['default'] },
|
||||||
|
'command': { 'type': 'str', 'required': True },
|
||||||
|
'options': { 'type': 'dict', 'default': {} },
|
||||||
|
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
||||||
|
'api_user': { 'type': 'str', 'default': 'admin' },
|
||||||
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!', 'no_log': True },
|
||||||
|
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
||||||
|
}
|
||||||
|
module = AnsibleModule(argument_spec=fields)
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
options = {
|
||||||
|
'command': module.params['command'],
|
||||||
|
}
|
||||||
|
options.update(module.params['options'])
|
||||||
|
|
||||||
|
api = SensuApi(
|
||||||
|
module.params['api_url'],
|
||||||
|
module.params['api_user'],
|
||||||
|
module.params['api_password']
|
||||||
|
)
|
||||||
|
api.auth()
|
||||||
|
|
||||||
|
for namespace in module.params['namespaces']:
|
||||||
|
mutator = SensuMutator(
|
||||||
|
api,
|
||||||
|
module.params['name'],
|
||||||
|
namespace
|
||||||
|
)
|
||||||
|
mutator.get_data()
|
||||||
|
|
||||||
|
if module.params['state'] == 'present':
|
||||||
|
if not mutator.exist or mutator.has_changed(options):
|
||||||
|
mutator.create(options)
|
||||||
|
changed = True
|
||||||
|
elif mutator.exist:
|
||||||
|
mutator.delete()
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
module.exit_json(changed=changed)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -31,7 +31,7 @@ def main():
|
||||||
'name': { 'type': 'str', 'required': True },
|
'name': { 'type': 'str', 'required': True },
|
||||||
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
||||||
'api_user': { 'type': 'str', 'default': 'admin' },
|
'api_user': { 'type': 'str', 'default': 'admin' },
|
||||||
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!', 'no_log': True },
|
||||||
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
||||||
}
|
}
|
||||||
module = AnsibleModule(argument_spec=fields)
|
module = AnsibleModule(argument_spec=fields)
|
||||||
|
|
|
@ -21,7 +21,7 @@ class SensuUser:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def has_changed(self, options):
|
def has_changed(self, options):
|
||||||
for option, value in self.options.iteritems():
|
for option, value in self.options.items():
|
||||||
if options[option] != value:
|
if options[option] != value:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -55,10 +55,10 @@ def main():
|
||||||
fields = {
|
fields = {
|
||||||
'name': { 'type': 'str', 'required': True },
|
'name': { 'type': 'str', 'required': True },
|
||||||
'groups': { 'type': 'list', 'default': [] },
|
'groups': { 'type': 'list', 'default': [] },
|
||||||
'password': { 'type': 'str', 'default': None },
|
'password': { 'type': 'str', 'default': None, 'no_log': True },
|
||||||
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:8080' },
|
||||||
'api_user': { 'type': 'str', 'default': 'admin' },
|
'api_user': { 'type': 'str', 'default': 'admin' },
|
||||||
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!', 'no_log': True },
|
||||||
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
'state': { 'type': 'str', 'default': 'present', 'choices': ['present', 'absent'] }
|
||||||
}
|
}
|
||||||
module = AnsibleModule(argument_spec=fields)
|
module = AnsibleModule(argument_spec=fields)
|
||||||
|
|
|
@ -5,15 +5,26 @@ galaxy_info:
|
||||||
company: Adrien Waksberg
|
company: Adrien Waksberg
|
||||||
description: Install and configure sensu-go
|
description: Install and configure sensu-go
|
||||||
license: Apache2
|
license: Apache2
|
||||||
min_ansible_version: 2.7
|
min_ansible_version: 2.5
|
||||||
|
|
||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
- stretch
|
- stretch
|
||||||
|
- name: Ubuntu
|
||||||
|
versions:
|
||||||
|
- xenial
|
||||||
|
- cosmic
|
||||||
|
- name: el
|
||||||
|
versions:
|
||||||
|
- 7
|
||||||
|
|
||||||
galaxy_tags:
|
galaxy_tags:
|
||||||
- sensu
|
- sensu
|
||||||
|
- sensugo
|
||||||
|
- dashboard
|
||||||
|
- agent
|
||||||
|
- backend
|
||||||
- monitoring
|
- monitoring
|
||||||
- alerting
|
- alerting
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class SensuApi:
|
||||||
if r.status_code == 401:
|
if r.status_code == 401:
|
||||||
raise Exception('Authentification has failed')
|
raise Exception('Authentification has failed')
|
||||||
|
|
||||||
self.headers = { 'Authorization': r.json()['access_token'] }
|
self.headers = { 'Authorization': 'Bearer %s' % (r.json()['access_token']) }
|
||||||
|
|
||||||
def get(self, path):
|
def get(self, path):
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
|
@ -59,7 +59,7 @@ class SensuApi:
|
||||||
raise Exception('Server return 500 error: {}'.format(r.text))
|
raise Exception('Server return 500 error: {}'.format(r.text))
|
||||||
elif r.status_code == 401:
|
elif r.status_code == 401:
|
||||||
raise Exception('Authentification has failed')
|
raise Exception('Authentification has failed')
|
||||||
elif r.status_code != 200:
|
elif r.status_code not in [200, 201, 204]:
|
||||||
raise Exception('Server return an unknown error: {}'.format(r.text))
|
raise Exception('Server return an unknown error: {}'.format(r.text))
|
||||||
|
|
||||||
def delete(self, path):
|
def delete(self, path):
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
---
|
---
|
||||||
- hosts: default
|
- name: Converge
|
||||||
connection: local
|
hosts: all
|
||||||
|
roles:
|
||||||
|
- ansible-role-sensu
|
||||||
vars:
|
vars:
|
||||||
sensu_backend: yes
|
|
||||||
sensu_repository_system: ubuntu
|
sensu_repository_system: ubuntu
|
||||||
sensu_repository_release: xenial
|
sensu_repository_release: xenial
|
||||||
|
sensu_backend: yes
|
||||||
|
sensu_agent_redact:
|
||||||
|
- supersecret
|
||||||
sensu_agent_plugins:
|
sensu_agent_plugins:
|
||||||
- name: sensu-plugins-disk-checks
|
- name: sensu-plugins-disk-checks
|
||||||
version: 3.1.1
|
version: 3.1.1
|
||||||
sensu_agent_labels:
|
sensu_agent_labels:
|
||||||
test: coucou
|
test: coucou
|
||||||
hello:
|
supersecret: password
|
||||||
warning: 30
|
|
||||||
critical: 50
|
|
||||||
sensu_namespaces:
|
sensu_namespaces:
|
||||||
- name: supernamespace
|
- name: production
|
||||||
|
- name: dev
|
||||||
sensu_users:
|
sensu_users:
|
||||||
- name: johndoe
|
- name: johndoe
|
||||||
password: secret1234
|
password: secret1234
|
||||||
|
@ -27,18 +30,44 @@
|
||||||
sha512: >
|
sha512: >
|
||||||
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce
|
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce
|
||||||
47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
|
sensu_mutators:
|
||||||
|
- name: transform
|
||||||
|
command: /path/value_to_csv
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
sensu_handlers:
|
sensu_handlers:
|
||||||
- name: mail
|
- name: mail
|
||||||
command: echo test | mail -s coucou
|
command: echo test | mail -s coucou
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
sensu_filters:
|
sensu_filters:
|
||||||
- name: state_changed
|
- name: state_changed
|
||||||
expressions:
|
expressions:
|
||||||
- event.check.occurrences == 1
|
- event.check.occurrences == 1
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
|
sensu_hooks:
|
||||||
|
- name: restart-apache
|
||||||
|
command: /etc/init.d/apache2 restart
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
sensu_checks:
|
sensu_checks:
|
||||||
- name: ping
|
- name: ping
|
||||||
command: ping -c 1 127.0.0.1
|
command: ping -c 1 127.0.0.1
|
||||||
|
labels:
|
||||||
|
ping_warning: '200'
|
||||||
subscriptions:
|
subscriptions:
|
||||||
- linux
|
- linux
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
sensu_cluster_roles:
|
sensu_cluster_roles:
|
||||||
- name: superview
|
- name: superview
|
||||||
rules:
|
rules:
|
||||||
|
@ -47,6 +76,3 @@
|
||||||
- list
|
- list
|
||||||
resources:
|
resources:
|
||||||
- '*'
|
- '*'
|
||||||
|
|
||||||
roles:
|
|
||||||
- ansible-role-sensu
|
|
18
molecule/default/molecule.yml
Normal file
18
molecule/default/molecule.yml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
platforms:
|
||||||
|
- name: debian10
|
||||||
|
image: nishiki/debian10:molecule
|
||||||
|
privileged: true
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||||
|
command: /bin/systemd
|
||||||
|
capabilities:
|
||||||
|
- SYS_ADMIN
|
||||||
|
lint: |
|
||||||
|
set -e
|
||||||
|
yamllint .
|
||||||
|
ansible-lint
|
||||||
|
verifier:
|
||||||
|
name: testinfra
|
64
molecule/default/tests/test_default.py
Normal file
64
molecule/default/tests/test_default.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import re
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
|
def test_packages(host):
|
||||||
|
for package_name in ['sensu-go-agent', 'sensu-go-cli', 'sensu-go-backend']:
|
||||||
|
package = host.package(package_name)
|
||||||
|
assert package.is_installed
|
||||||
|
|
||||||
|
def test_services(host):
|
||||||
|
for service_name in ['sensu-backend', 'sensu-agent']:
|
||||||
|
service = host.service(service_name)
|
||||||
|
assert service.is_running
|
||||||
|
assert service.is_enabled
|
||||||
|
|
||||||
|
def test_sockets(host):
|
||||||
|
for port in [3000, 8080, 8081]:
|
||||||
|
socket = host.socket('tcp://0.0.0.0:%d' % (port))
|
||||||
|
assert socket.is_listening
|
||||||
|
|
||||||
|
def test_configure_sensuctl(host):
|
||||||
|
cmd = host.run('sensuctl configure -n --password "P@ssw0rd!" --url http://127.0.0.1:8080 --username admin --format tabular')
|
||||||
|
assert cmd.succeeded
|
||||||
|
|
||||||
|
def test_sensu_namespace(host):
|
||||||
|
cmd = host.run('sensuctl namespace list')
|
||||||
|
assert cmd.succeeded
|
||||||
|
assert 'production' in cmd.stdout
|
||||||
|
assert 'dev' in cmd.stdout
|
||||||
|
|
||||||
|
def test_sensu_user(host):
|
||||||
|
cmd = host.run('sensuctl user list')
|
||||||
|
assert cmd.succeeded
|
||||||
|
assert re.search('johndoe.*\\s+devops,users\\s+.*true', cmd.stdout)
|
||||||
|
|
||||||
|
def test_sensu_entity(host):
|
||||||
|
cmd = host.run('sensuctl entity info debian10 --format json')
|
||||||
|
assert cmd.succeeded
|
||||||
|
assert '"supersecret": "REDACTED"' in cmd.stdout
|
||||||
|
|
||||||
|
def test_sensu_check(host):
|
||||||
|
for namespace in ['production', 'dev']:
|
||||||
|
cmd = host.run('sensuctl asset list --namespace %s' % namespace)
|
||||||
|
assert cmd.succeeded
|
||||||
|
assert re.search('superasset.*\\s+.*test.sh\\s+cf83e13', cmd.stdout)
|
||||||
|
|
||||||
|
cmd = host.run('sensuctl mutator list --namespace %s' % namespace)
|
||||||
|
assert cmd.succeeded
|
||||||
|
assert re.search('transform.*\\s+.*/path/value_to_csv', cmd.stdout)
|
||||||
|
|
||||||
|
cmd = host.run('sensuctl handler list --namespace %s' % namespace)
|
||||||
|
assert cmd.succeeded
|
||||||
|
assert re.search('mail.*\\s+pipe\\s+.*echo test | mail -s coucou\\s+', cmd.stdout)
|
||||||
|
|
||||||
|
cmd = host.run('sensuctl check list --namespace %s' % namespace)
|
||||||
|
assert cmd.succeeded
|
||||||
|
assert re.search('ping.*\\s+ping -c 1 127.0.0.1\\s+60\\s+.*\\s+linux\\s+', cmd.stdout)
|
||||||
|
|
||||||
|
cmd = host.run('sensuctl filter list --namespace %s' % namespace)
|
||||||
|
assert cmd.succeeded
|
||||||
|
assert re.search('state_changed.*\\s+allow\\s+\\(event.check.occurrences == 1\\)', cmd.stdout)
|
||||||
|
|
||||||
|
cmd = host.run('sensuctl hook list --namespace %s' % namespace)
|
||||||
|
assert cmd.succeeded
|
||||||
|
assert re.search('restart-apache.*\\s+/etc/init.d/apache2 restart\\s+10\\s+false', cmd.stdout)
|
|
@ -1,23 +1,17 @@
|
||||||
---
|
---
|
||||||
- name: install sensu-agent packages
|
- name: install sensu-agent packages
|
||||||
apt:
|
package:
|
||||||
name: '{{ packages }}'
|
name: '{{ packages }}'
|
||||||
vars:
|
vars:
|
||||||
packages:
|
packages:
|
||||||
- sensu-go-agent
|
- sensu-go-agent
|
||||||
- sensu-plugins-ruby
|
- sensu-plugins-ruby
|
||||||
- build-essential
|
|
||||||
- monitoring-plugins-basic
|
|
||||||
register: result
|
register: result
|
||||||
retries: 3
|
retries: 3
|
||||||
delay: 1
|
delay: 1
|
||||||
until: result is success
|
until: result is success
|
||||||
when: not sensu_build
|
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- import_tasks: build_agent.yml
|
|
||||||
when: sensu_build
|
|
||||||
|
|
||||||
- name: copy agent configuration file
|
- name: copy agent configuration file
|
||||||
copy:
|
copy:
|
||||||
content: '{{ sensu_agent_full_config|to_nice_yaml }}'
|
content: '{{ sensu_agent_full_config|to_nice_yaml }}'
|
||||||
|
|
11
tasks/backend-dependencies-debian.yml
Normal file
11
tasks/backend-dependencies-debian.yml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
- name: install backend dependencies
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- python-requests
|
||||||
|
- python3-requests
|
||||||
|
register: result
|
||||||
|
retries: 3
|
||||||
|
delay: 1
|
||||||
|
until: result is success
|
||||||
|
tags: sensu
|
27
tasks/backend-dependencies-redhat.yml
Normal file
27
tasks/backend-dependencies-redhat.yml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
---
|
||||||
|
- name: uninstall bad dependencies
|
||||||
|
package:
|
||||||
|
name: '{{ packages }}'
|
||||||
|
state: absent
|
||||||
|
vars:
|
||||||
|
packages:
|
||||||
|
- python-urllib3
|
||||||
|
- python-requests
|
||||||
|
register: result
|
||||||
|
retries: 1
|
||||||
|
delay: 1
|
||||||
|
until: result is success
|
||||||
|
tags: sensu
|
||||||
|
|
||||||
|
- name: install backend dependencies
|
||||||
|
pip:
|
||||||
|
name: '{{ packages }}'
|
||||||
|
vars:
|
||||||
|
packages:
|
||||||
|
- urllib3
|
||||||
|
- requests
|
||||||
|
register: result
|
||||||
|
retries: 3
|
||||||
|
delay: 1
|
||||||
|
until: result is success
|
||||||
|
tags: sensu
|
|
@ -1,12 +1,13 @@
|
||||||
---
|
---
|
||||||
|
- include_tasks: 'backend-dependencies-{{ ansible_os_family|lower }}.yml'
|
||||||
|
|
||||||
- name: install sensu-backend packages
|
- name: install sensu-backend packages
|
||||||
apt:
|
package:
|
||||||
name: '{{ packages }}'
|
name: '{{ packages }}'
|
||||||
vars:
|
vars:
|
||||||
packages:
|
packages:
|
||||||
- sensu-go-backend
|
- sensu-go-backend
|
||||||
- sensu-go-cli
|
- sensu-go-cli
|
||||||
- python-requests
|
|
||||||
register: result
|
register: result
|
||||||
retries: 3
|
retries: 3
|
||||||
delay: 1
|
delay: 1
|
||||||
|
@ -36,18 +37,22 @@
|
||||||
delay: 5
|
delay: 5
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- name: manage users
|
- name: init backend
|
||||||
sensugo_user:
|
command:
|
||||||
name: '{{ item.name }}'
|
cmd: sensu-backend init
|
||||||
groups: '{{ item.groups }}'
|
creates: /etc/sensu/.backend-init
|
||||||
password: '{{ item.password }}'
|
environment:
|
||||||
state: '{{ item.state|default("present") }}'
|
SENSU_BACKEND_CLUSTER_ADMIN_USERNAME: '{{ sensu_api_user }}'
|
||||||
api_url: '{{ sensu_api_url }}'
|
SENSU_BACKEND_CLUSTER_ADMIN_PASSWORD: '{{ sensu_api_password }}'
|
||||||
api_user: '{{ sensu_api_user }}'
|
tags: sensu
|
||||||
api_password: '{{ sensu_api_password }}'
|
|
||||||
loop: '{{ sensu_users }}'
|
- name: hold init
|
||||||
run_once: true
|
copy:
|
||||||
no_log: true
|
content: ''
|
||||||
|
dest: /etc/sensu/.backend-init
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0600
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- name: manage cluster roles
|
- name: manage cluster roles
|
||||||
|
@ -59,8 +64,24 @@
|
||||||
api_user: '{{ sensu_api_user }}'
|
api_user: '{{ sensu_api_user }}'
|
||||||
api_password: '{{ sensu_api_password }}'
|
api_password: '{{ sensu_api_password }}'
|
||||||
loop: '{{ sensu_cluster_roles }}'
|
loop: '{{ sensu_cluster_roles }}'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.name }}'
|
||||||
|
run_once: true
|
||||||
|
tags: sensu
|
||||||
|
|
||||||
|
- name: manage users
|
||||||
|
sensugo_user:
|
||||||
|
name: '{{ item.name }}'
|
||||||
|
groups: '{{ item.groups }}'
|
||||||
|
password: '{{ item.password }}'
|
||||||
|
state: '{{ item.state|default("present") }}'
|
||||||
|
api_url: '{{ sensu_api_url }}'
|
||||||
|
api_user: '{{ sensu_api_user }}'
|
||||||
|
api_password: '{{ sensu_api_password }}'
|
||||||
|
loop: '{{ sensu_users }}'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.name }}'
|
||||||
run_once: true
|
run_once: true
|
||||||
no_log: true
|
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- name: manage namespaces
|
- name: manage namespaces
|
||||||
|
@ -71,14 +92,15 @@
|
||||||
api_user: '{{ sensu_api_user }}'
|
api_user: '{{ sensu_api_user }}'
|
||||||
api_password: '{{ sensu_api_password }}'
|
api_password: '{{ sensu_api_password }}'
|
||||||
loop: '{{ sensu_namespaces }}'
|
loop: '{{ sensu_namespaces }}'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.name }}'
|
||||||
run_once: true
|
run_once: true
|
||||||
no_log: true
|
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- name: manage assets
|
- name: manage assets
|
||||||
sensugo_asset:
|
sensugo_asset:
|
||||||
name: '{{ item.name }}'
|
name: '{{ item.name }}'
|
||||||
namespace: '{{ item.namespace|default("default") }}'
|
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
||||||
url: '{{ item.url }}'
|
url: '{{ item.url }}'
|
||||||
sha512: '{{ item.sha512 }}'
|
sha512: '{{ item.sha512 }}'
|
||||||
filters: '{{ item.filters|default([]) }}'
|
filters: '{{ item.filters|default([]) }}'
|
||||||
|
@ -86,14 +108,15 @@
|
||||||
api_user: '{{ sensu_api_user }}'
|
api_user: '{{ sensu_api_user }}'
|
||||||
api_password: '{{ sensu_api_password }}'
|
api_password: '{{ sensu_api_password }}'
|
||||||
loop: '{{ sensu_assets }}'
|
loop: '{{ sensu_assets }}'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.name }}'
|
||||||
run_once: true
|
run_once: true
|
||||||
no_log: true
|
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- name: manage filters
|
- name: manage filters
|
||||||
sensugo_filter:
|
sensugo_filter:
|
||||||
name: '{{ item.name }}'
|
name: '{{ item.name }}'
|
||||||
namespace: '{{ item.namespace|default("default") }}'
|
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
||||||
action: '{{ item.action|default("allow") }}'
|
action: '{{ item.action|default("allow") }}'
|
||||||
expressions: '{{ item.expressions }}'
|
expressions: '{{ item.expressions }}'
|
||||||
runtime_assets: '{{ item.runtime_assets|default([]) }}'
|
runtime_assets: '{{ item.runtime_assets|default([]) }}'
|
||||||
|
@ -102,14 +125,30 @@
|
||||||
api_user: '{{ sensu_api_user }}'
|
api_user: '{{ sensu_api_user }}'
|
||||||
api_password: '{{ sensu_api_password }}'
|
api_password: '{{ sensu_api_password }}'
|
||||||
loop: '{{ sensu_filters }}'
|
loop: '{{ sensu_filters }}'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.name }}'
|
||||||
|
run_once: true
|
||||||
|
tags: sensu
|
||||||
|
|
||||||
|
- name: manage mutators
|
||||||
|
sensugo_mutator:
|
||||||
|
name: '{{ item.name }}'
|
||||||
|
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
||||||
|
command: '{{ item.command }}'
|
||||||
|
options: '{{ item.options|default({}) }}'
|
||||||
|
api_url: '{{ sensu_api_url }}'
|
||||||
|
api_user: '{{ sensu_api_user }}'
|
||||||
|
api_password: '{{ sensu_api_password }}'
|
||||||
|
loop: '{{ sensu_mutators }}'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.name }}'
|
||||||
run_once: true
|
run_once: true
|
||||||
no_log: true
|
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- name: manage handlers
|
- name: manage handlers
|
||||||
sensugo_handler:
|
sensugo_handler:
|
||||||
name: '{{ item.name }}'
|
name: '{{ item.name }}'
|
||||||
namespace: '{{ item.namespace|default("default") }}'
|
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
||||||
type: '{{ item.type|default("pipe") }}'
|
type: '{{ item.type|default("pipe") }}'
|
||||||
command: '{{ item.command }}'
|
command: '{{ item.command }}'
|
||||||
filters: '{{ item.filters|default([]) }}'
|
filters: '{{ item.filters|default([]) }}'
|
||||||
|
@ -118,14 +157,31 @@
|
||||||
api_user: '{{ sensu_api_user }}'
|
api_user: '{{ sensu_api_user }}'
|
||||||
api_password: '{{ sensu_api_password }}'
|
api_password: '{{ sensu_api_password }}'
|
||||||
loop: '{{ sensu_handlers }}'
|
loop: '{{ sensu_handlers }}'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.name }}'
|
||||||
|
run_once: true
|
||||||
|
tags: sensu
|
||||||
|
|
||||||
|
- name: manage hooks
|
||||||
|
sensugo_hook:
|
||||||
|
name: '{{ item.name }}'
|
||||||
|
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
||||||
|
command: '{{ item.command }}'
|
||||||
|
timeout: '{{ item.timeout|default(10) }}'
|
||||||
|
api_url: '{{ sensu_api_url }}'
|
||||||
|
api_user: '{{ sensu_api_user }}'
|
||||||
|
api_password: '{{ sensu_api_password }}'
|
||||||
|
loop: '{{ sensu_hooks }}'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.name }}'
|
||||||
run_once: true
|
run_once: true
|
||||||
no_log: true
|
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- name: manage checks
|
- name: manage checks
|
||||||
sensugo_check:
|
sensugo_check:
|
||||||
name: '{{ item.name }}'
|
name: '{{ item.name }}'
|
||||||
namespace: '{{ item.namespace|default("default") }}'
|
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
||||||
|
labels: '{{ item.labels|default({}) }}'
|
||||||
command: '{{ item.command }}'
|
command: '{{ item.command }}'
|
||||||
handlers: '{{ item.handlers|default([]) }}'
|
handlers: '{{ item.handlers|default([]) }}'
|
||||||
subscriptions: '{{ item.subscriptions }}'
|
subscriptions: '{{ item.subscriptions }}'
|
||||||
|
@ -136,6 +192,7 @@
|
||||||
api_user: '{{ sensu_api_user }}'
|
api_user: '{{ sensu_api_user }}'
|
||||||
api_password: '{{ sensu_api_password }}'
|
api_password: '{{ sensu_api_password }}'
|
||||||
loop: '{{ sensu_checks }}'
|
loop: '{{ sensu_checks }}'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.name }}'
|
||||||
run_once: true
|
run_once: true
|
||||||
no_log: true
|
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
|
@ -1,98 +0,0 @@
|
||||||
---
|
|
||||||
- name: install build dependencies
|
|
||||||
apt:
|
|
||||||
name: 'golang-{{ sensu_build_go_version }}'
|
|
||||||
tags: sensu
|
|
||||||
|
|
||||||
- name: check if binary exist
|
|
||||||
stat:
|
|
||||||
path: /usr/local/bin/sensu-agent
|
|
||||||
register: bin
|
|
||||||
tags: sensu
|
|
||||||
|
|
||||||
- name: download source code
|
|
||||||
git:
|
|
||||||
repo: https://github.com/sensu/sensu-go/
|
|
||||||
version: '{{ sensu_build_version }}'
|
|
||||||
dest: /usr/local/src/sensu-go
|
|
||||||
register: git
|
|
||||||
tags: sensu
|
|
||||||
|
|
||||||
- name: install dependencies
|
|
||||||
command:
|
|
||||||
args:
|
|
||||||
chdir: /usr/local/src/sensu-go
|
|
||||||
argv:
|
|
||||||
- '/usr/lib/go-{{ sensu_build_go_version }}/bin/go'
|
|
||||||
- get
|
|
||||||
- ./cmd/sensu-agent/
|
|
||||||
environment:
|
|
||||||
GOPATH: /usr/local/src/go
|
|
||||||
GOBIN: /usr/local/src/go/bin
|
|
||||||
when: git.changed or not bin.stat.exists
|
|
||||||
tags: sensu
|
|
||||||
|
|
||||||
- name: build program
|
|
||||||
command:
|
|
||||||
args:
|
|
||||||
chdir: /usr/local/src/sensu-go
|
|
||||||
argv:
|
|
||||||
- '/usr/lib/go-{{ sensu_build_go_version }}/bin/go'
|
|
||||||
- build
|
|
||||||
- '-o'
|
|
||||||
- /usr/local/bin/sensu-agent
|
|
||||||
- ./cmd/sensu-agent/
|
|
||||||
environment:
|
|
||||||
GOPATH: /usr/local/src/go
|
|
||||||
GOBIN: /usr/local/src/go/bin
|
|
||||||
when: git.changed or not bin.stat.exists
|
|
||||||
tags: go
|
|
||||||
|
|
||||||
- name: set permission on binary
|
|
||||||
file:
|
|
||||||
path: /usr/local/bin/sensu-agent
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0755
|
|
||||||
tags: go
|
|
||||||
|
|
||||||
- name: create configuration folder
|
|
||||||
file:
|
|
||||||
path: /etc/sensu
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0755
|
|
||||||
state: directory
|
|
||||||
tags: go
|
|
||||||
|
|
||||||
- name: create sensu group
|
|
||||||
group:
|
|
||||||
name: sensu
|
|
||||||
gid: 998
|
|
||||||
tags: go
|
|
||||||
|
|
||||||
- name: create sensu user
|
|
||||||
user:
|
|
||||||
name: sensu
|
|
||||||
group: sensu
|
|
||||||
uid: 996
|
|
||||||
home: /opt/sensu
|
|
||||||
shell: /bin/false
|
|
||||||
comment: Sensu Monitoring Framework
|
|
||||||
tags: go
|
|
||||||
|
|
||||||
- name: copy systemd service
|
|
||||||
copy:
|
|
||||||
src: sensu-agent.service
|
|
||||||
dest: /etc/systemd/system/sensu-agent.service
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0644
|
|
||||||
register: systemd
|
|
||||||
tags: go
|
|
||||||
|
|
||||||
- name: reload systemd
|
|
||||||
systemd:
|
|
||||||
daemon_reload: yes
|
|
||||||
when: systemd.changed
|
|
||||||
tags: go
|
|
|
@ -1,9 +1,8 @@
|
||||||
---
|
---
|
||||||
- import_tasks: repository.yml
|
- include_tasks: 'repository-{{ ansible_os_family|lower }}.yml'
|
||||||
when: not sensu_build
|
|
||||||
|
|
||||||
- import_tasks: agent.yml
|
- import_tasks: agent.yml
|
||||||
when: sensu_agent
|
when: sensu_agent|bool
|
||||||
|
|
||||||
- import_tasks: backend.yml
|
- import_tasks: backend.yml
|
||||||
when: sensu_backend
|
when: sensu_backend|bool
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
- name: install dependencies packages
|
- name: install dependencies packages
|
||||||
apt:
|
package:
|
||||||
name: '{{ packages }}'
|
name: '{{ packages }}'
|
||||||
vars:
|
vars:
|
||||||
packages:
|
packages:
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
- ca-certificates
|
- ca-certificates
|
||||||
- gnupg2
|
- gnupg2
|
||||||
- software-properties-common
|
- software-properties-common
|
||||||
|
- build-essential
|
||||||
register: result
|
register: result
|
||||||
retries: 3
|
retries: 3
|
||||||
delay: 1
|
delay: 1
|
13
tasks/repository-redhat.yml
Normal file
13
tasks/repository-redhat.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
- name: add sensu repository
|
||||||
|
yum_repository:
|
||||||
|
name: sensu-{{ item }}
|
||||||
|
description: Sensu {{ item }} repository
|
||||||
|
gpgkey: 'https://packagecloud.io/sensu/{{ item }}/gpgkey'
|
||||||
|
gpgcheck: false
|
||||||
|
repo_gpgcheck: true
|
||||||
|
baseurl: 'https://packagecloud.io/sensu/{{ item }}/el/$releasever/$basearch'
|
||||||
|
loop:
|
||||||
|
- stable
|
||||||
|
- community
|
||||||
|
tags: sensu
|
|
@ -1,18 +0,0 @@
|
||||||
---
|
|
||||||
- hosts: default
|
|
||||||
connection: local
|
|
||||||
vars:
|
|
||||||
sensu_agent_labels:
|
|
||||||
test: coucou
|
|
||||||
hello:
|
|
||||||
warning: 30
|
|
||||||
critical: 50
|
|
||||||
|
|
||||||
roles:
|
|
||||||
- ansible-role-sensu
|
|
||||||
|
|
||||||
pre_tasks:
|
|
||||||
- name: add repo backports
|
|
||||||
apt_repository:
|
|
||||||
repo: 'deb http://httpredir.debian.org/debian {{ansible_distribution_release}}-backports main'
|
|
||||||
state: present
|
|
|
@ -1,78 +0,0 @@
|
||||||
require 'serverspec'
|
|
||||||
|
|
||||||
set :backend, :exec
|
|
||||||
|
|
||||||
puts
|
|
||||||
puts '================================'
|
|
||||||
puts %x(ansible --version)
|
|
||||||
puts '================================'
|
|
||||||
|
|
||||||
%w[
|
|
||||||
sensu-go-agent
|
|
||||||
sensu-go-cli
|
|
||||||
sensu-go-backend
|
|
||||||
monitoring-plugins-basic
|
|
||||||
].each do |package|
|
|
||||||
describe package(package) do
|
|
||||||
it { should be_installed }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%w[
|
|
||||||
sensu-agent
|
|
||||||
sensu-backend
|
|
||||||
].each do |service|
|
|
||||||
describe service(service) do
|
|
||||||
it { should be_enabled }
|
|
||||||
it { should be_running }
|
|
||||||
it { should be_running.under('systemd') }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
[3000, 8080, 8081].each do |port|
|
|
||||||
describe port(port) do
|
|
||||||
it { should be_listening.with('tcp6') }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command(
|
|
||||||
'sensuctl configure -n --password "P@ssw0rd!" ' \
|
|
||||||
'--url http://127.0.0.1:8080 --username admin --format tabular'
|
|
||||||
) do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl namespace list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match 'supernamespace' }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl user list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/johndoe.*\s+devops,users\s+.*true/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl asset list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/superasset.*\s+.*test.sh\s+cf83e13/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl handler list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/mail.*\s+pipe\s+.*echo test \| mail -s coucou\s+/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl filter list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/state_changed.*\s+allow\s+event\.check\.occurrences == 1/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl cluster-role list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/view.*\s+1/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl check list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/ping.*\s+ping -c 1 127.0.0.1\s+60\s+.*\s+linux\s+/) }
|
|
||||||
end
|
|
|
@ -1,80 +0,0 @@
|
||||||
require 'serverspec'
|
|
||||||
|
|
||||||
set :backend, :exec
|
|
||||||
|
|
||||||
puts
|
|
||||||
puts '================================'
|
|
||||||
puts %x(ansible --version)
|
|
||||||
puts '================================'
|
|
||||||
|
|
||||||
%w[
|
|
||||||
sensu-go-agent
|
|
||||||
sensu-go-cli
|
|
||||||
sensu-go-backend
|
|
||||||
build-essential
|
|
||||||
monitoring-plugins-basic
|
|
||||||
python-requests
|
|
||||||
].each do |package|
|
|
||||||
describe package(package) do
|
|
||||||
it { should be_installed }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%w[
|
|
||||||
sensu-agent
|
|
||||||
sensu-backend
|
|
||||||
].each do |service|
|
|
||||||
describe service(service) do
|
|
||||||
it { should be_enabled }
|
|
||||||
it { should be_running }
|
|
||||||
it { should be_running.under('systemd') }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
[3000, 8080, 8081].each do |port|
|
|
||||||
describe port(port) do
|
|
||||||
it { should be_listening.with('tcp6') }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command(
|
|
||||||
'sensuctl configure -n --password "P@ssw0rd!" ' \
|
|
||||||
'--url http://127.0.0.1:8080 --username admin --format tabular'
|
|
||||||
) do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl namespace list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match 'supernamespace' }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl user list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/johndoe.*\s+devops,users\s+.*true/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl asset list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/superasset.*\s+.*test.sh\s+cf83e13/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl handler list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/mail.*\s+pipe\s+.*echo test \| mail -s coucou\s+/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl filter list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/state_changed.*\s+allow\s+event\.check\.occurrences == 1/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl cluster-role list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/view.*\s+1/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('sensuctl check list') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should match(/ping.*\s+ping -c 1 127.0.0.1\s+60\s+.*\s+linux\s+/) }
|
|
||||||
end
|
|
|
@ -1,2 +0,0 @@
|
||||||
[default]
|
|
||||||
localhost
|
|
Loading…
Reference in a new issue