Compare commits
2 commits
master
...
build-sens
Author | SHA1 | Date | |
---|---|---|---|
5024bfa3ea | |||
130854c97e |
37 changed files with 620 additions and 760 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
.kitchen/*
|
.kitchen/*
|
||||||
*.pyc
|
|
||||||
|
|
32
.kitchen.yml
Normal file
32
.kitchen.yml
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
---
|
||||||
|
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
Normal file
38
.rubocop.yml
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
---
|
||||||
|
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
29
.travis.yml
|
@ -1,29 +0,0 @@
|
||||||
---
|
|
||||||
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,51 +4,8 @@ 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
|
||||||
- test: add travis ci
|
- fix: install build-essential for agent
|
||||||
|
|
||||||
## [1.0.0] - 2019-02-06
|
## [1.0.0] - 2019-02-06
|
||||||
|
|
||||||
- first version
|
- first version
|
||||||
|
|
8
Gemfile
Normal file
8
Gemfile
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
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
Normal file
92
Gemfile.lock
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
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,18 +1,13 @@
|
||||||
# Ansible role: Sensu
|
# Ansible role: Sensu
|
||||||
[![Version](https://img.shields.io/badge/latest_version-1.4.0-green.svg)](https://git.yaegashi.fr/nishiki/ansible-role-sensu/releases)
|
[![Version](https://img.shields.io/badge/latest_version-1.0.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.5
|
* Ansible >= 2.7
|
||||||
* OS
|
* Debian Stretch
|
||||||
* Debian Stretch
|
|
||||||
* Ubuntu 18.04
|
|
||||||
* Ubuntu 16.04
|
|
||||||
* Centos 7
|
|
||||||
|
|
||||||
## Role variables
|
## Role variables
|
||||||
### General
|
### General
|
||||||
|
@ -20,8 +15,6 @@ 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`)
|
||||||
|
@ -45,15 +38,9 @@ Notice: for debian9 set `sensu_repository_system` to `ubuntu` and `sensu_reposit
|
||||||
|
|
||||||
```
|
```
|
||||||
region: Europe
|
region: Europe
|
||||||
disk_critical: 90
|
disk:
|
||||||
disk_warning: 75
|
critical: 90
|
||||||
```
|
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
|
||||||
|
@ -73,8 +60,7 @@ Notice: for debian9 set `sensu_repository_system` to `ubuntu` and `sensu_reposit
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: http-binary
|
- name: http-binary
|
||||||
namespace:
|
namespace: default
|
||||||
- default
|
|
||||||
url: http://host.local
|
url: http://host.local
|
||||||
sha512: XXXX
|
sha512: XXXX
|
||||||
filters: []
|
filters: []
|
||||||
|
@ -91,10 +77,7 @@ Notice: for debian9 set `sensu_repository_system` to `ubuntu` and `sensu_reposit
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: load
|
- name: load
|
||||||
namespace:
|
namespace: default
|
||||||
- default
|
|
||||||
labels:
|
|
||||||
criticity: high
|
|
||||||
command: /usr/bin/load -w 2 -c 5
|
command: /usr/bin/load -w 2 -c 5
|
||||||
handlers:
|
handlers:
|
||||||
- mailer
|
- mailer
|
||||||
|
@ -105,23 +88,11 @@ Notice: for debian9 set `sensu_repository_system` to `ubuntu` and `sensu_reposit
|
||||||
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:
|
namespace: default
|
||||||
- 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:
|
||||||
|
@ -130,22 +101,11 @@ Notice: for debian9 set `sensu_repository_system` to `ubuntu` and `sensu_reposit
|
||||||
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:
|
namespace: default
|
||||||
- default
|
|
||||||
action: allow
|
action: allow
|
||||||
expressions:
|
expressions:
|
||||||
runtime_assets: []
|
runtime_assets: []
|
||||||
|
@ -180,75 +140,33 @@ Notice: for debian9 set `sensu_repository_system` to `ubuntu` and `sensu_reposit
|
||||||
* `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
|
||||||
|
|
||||||
### Test with molecule and docker
|
* install `python` and `python-pip`
|
||||||
|
* 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 `python3` and `python3-pip`
|
* install ruby
|
||||||
* install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
|
* install bundler `gem install bundler`
|
||||||
* run `molecule test`
|
* install dependencies `bundle install`
|
||||||
|
* run the tests `kitchen test`
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
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 }}'
|
||||||
|
|
||||||
|
@ -15,17 +19,6 @@ 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
|
||||||
|
@ -37,7 +30,6 @@ 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) }}'
|
||||||
|
|
||||||
|
@ -53,5 +45,3 @@ sensu_handlers: []
|
||||||
sensu_filters: []
|
sensu_filters: []
|
||||||
sensu_users: []
|
sensu_users: []
|
||||||
sensu_cluster_roles: []
|
sensu_cluster_roles: []
|
||||||
sensu_mutators: []
|
|
||||||
sensu_hooks: []
|
|
||||||
|
|
16
files/sensu-agent.service
Normal file
16
files/sensu-agent.service
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
[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.items():
|
for option, value in self.options.iteritems():
|
||||||
if (options[option] or value) and options[option] != value:
|
if 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 },
|
||||||
'namespaces': { 'type': 'list', 'default': ['default'] },
|
'namespace': { 'type': 'str', '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!', 'no_log': True },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
||||||
}
|
}
|
||||||
module = AnsibleModule(argument_spec=fields)
|
module = AnsibleModule(argument_spec=fields)
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -67,11 +67,10 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
for namespace in module.params['namespaces']:
|
|
||||||
asset = SensuAsset(
|
asset = SensuAsset(
|
||||||
api,
|
api,
|
||||||
module.params['name'],
|
module.params['name'],
|
||||||
namespace
|
module.params['namespace']
|
||||||
)
|
)
|
||||||
asset.get_data()
|
asset.get_data()
|
||||||
|
|
||||||
|
|
|
@ -4,42 +4,21 @@ 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, labels):
|
def __init__(self, api, name, namespace):
|
||||||
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
|
||||||
return data
|
self.options = 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):
|
||||||
data = self.get_data()
|
for option, value in self.options.iteritems():
|
||||||
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
|
||||||
|
@ -52,8 +31,7 @@ class SensuCheck:
|
||||||
options.update({
|
options.update({
|
||||||
'metadata': {
|
'metadata': {
|
||||||
'name': self.name,
|
'name': self.name,
|
||||||
'namespace': self.namespace,
|
'namespace': self.namespace
|
||||||
'labels': self.labels
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -71,8 +49,7 @@ class SensuCheck:
|
||||||
def main():
|
def main():
|
||||||
fields = {
|
fields = {
|
||||||
'name': { 'type': 'str', 'required': True },
|
'name': { 'type': 'str', 'required': True },
|
||||||
'namespaces': { 'type': 'list', 'default': ['default'] },
|
'namespace': { 'type': 'str', '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 },
|
||||||
|
@ -80,7 +57,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!', 'no_log': True },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
||||||
'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)
|
||||||
|
@ -104,12 +81,10 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
for namespace in module.params['namespaces']:
|
|
||||||
check = SensuCheck(
|
check = SensuCheck(
|
||||||
api,
|
api,
|
||||||
module.params['name'],
|
module.params['name'],
|
||||||
namespace,
|
module.params['namespace']
|
||||||
module.params['labels']
|
|
||||||
)
|
)
|
||||||
check.get_data()
|
check.get_data()
|
||||||
|
|
||||||
|
|
|
@ -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].items():
|
for rule, value in self.options['rules'][i].iteritems():
|
||||||
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].items():
|
for rule, value in options['rules'][i].iteritems():
|
||||||
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!', 'no_log': True },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
||||||
'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.items():
|
for option, value in self.options.iteritems():
|
||||||
if not option in options:
|
if not option in options:
|
||||||
if value:
|
if value:
|
||||||
return True
|
return True
|
||||||
elif (options[option] or value) and options[option] != value:
|
elif 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 },
|
||||||
'namespaces': { 'type': 'list', 'default': ['default'] },
|
'namespace': { 'type': 'str', '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!', 'no_log': True },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
||||||
'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,11 +74,10 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
for namespace in module.params['namespaces']:
|
|
||||||
filter = SensuFilter(
|
filter = SensuFilter(
|
||||||
api,
|
api,
|
||||||
module.params['name'],
|
module.params['name'],
|
||||||
namespace
|
module.params['namespace']
|
||||||
)
|
)
|
||||||
filter.get_data()
|
filter.get_data()
|
||||||
|
|
||||||
|
|
|
@ -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.items():
|
for option, value in self.options.iteritems():
|
||||||
if not option in options:
|
if not option in options:
|
||||||
if value:
|
if value:
|
||||||
return True
|
return True
|
||||||
elif (options[option] or value) and options[option] != value:
|
elif 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 },
|
||||||
'namespaces': { 'type': 'list', 'default': ['default'] },
|
'namespace': { 'type': 'str', '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!', 'no_log': True },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
||||||
'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,11 +76,10 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
for namespace in module.params['namespaces']:
|
|
||||||
handler = SensuHandler(
|
handler = SensuHandler(
|
||||||
api,
|
api,
|
||||||
module.params['name'],
|
module.params['name'],
|
||||||
namespace
|
module.params['namespace']
|
||||||
)
|
)
|
||||||
handler.get_data()
|
handler.get_data()
|
||||||
|
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
#!/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()
|
|
|
@ -1,94 +0,0 @@
|
||||||
#!/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!', 'no_log': True },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
||||||
'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.items():
|
for option, value in self.options.iteritems():
|
||||||
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, 'no_log': True },
|
'password': { 'type': 'str', 'default': None },
|
||||||
'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!', 'no_log': True },
|
'api_password': { 'type': 'str', 'default': 'P@ssw0rd!' },
|
||||||
'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,26 +5,15 @@ 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.5
|
min_ansible_version: 2.7
|
||||||
|
|
||||||
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': 'Bearer %s' % (r.json()['access_token']) }
|
self.headers = { 'Authorization': 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 not in [200, 201, 204]:
|
elif r.status_code != 200:
|
||||||
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,18 +0,0 @@
|
||||||
---
|
|
||||||
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
|
|
|
@ -1,64 +0,0 @@
|
||||||
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,17 +1,23 @@
|
||||||
---
|
---
|
||||||
- name: install sensu-agent packages
|
- name: install sensu-agent packages
|
||||||
package:
|
apt:
|
||||||
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 }}'
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
---
|
|
||||||
- name: install backend dependencies
|
|
||||||
package:
|
|
||||||
name:
|
|
||||||
- python-requests
|
|
||||||
- python3-requests
|
|
||||||
register: result
|
|
||||||
retries: 3
|
|
||||||
delay: 1
|
|
||||||
until: result is success
|
|
||||||
tags: sensu
|
|
|
@ -1,27 +0,0 @@
|
||||||
---
|
|
||||||
- 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,13 +1,12 @@
|
||||||
---
|
---
|
||||||
- include_tasks: 'backend-dependencies-{{ ansible_os_family|lower }}.yml'
|
|
||||||
|
|
||||||
- name: install sensu-backend packages
|
- name: install sensu-backend packages
|
||||||
package:
|
apt:
|
||||||
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
|
||||||
|
@ -37,22 +36,18 @@
|
||||||
delay: 5
|
delay: 5
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- name: init backend
|
- name: manage users
|
||||||
command:
|
sensugo_user:
|
||||||
cmd: sensu-backend init
|
name: '{{ item.name }}'
|
||||||
creates: /etc/sensu/.backend-init
|
groups: '{{ item.groups }}'
|
||||||
environment:
|
password: '{{ item.password }}'
|
||||||
SENSU_BACKEND_CLUSTER_ADMIN_USERNAME: '{{ sensu_api_user }}'
|
state: '{{ item.state|default("present") }}'
|
||||||
SENSU_BACKEND_CLUSTER_ADMIN_PASSWORD: '{{ sensu_api_password }}'
|
api_url: '{{ sensu_api_url }}'
|
||||||
tags: sensu
|
api_user: '{{ sensu_api_user }}'
|
||||||
|
api_password: '{{ sensu_api_password }}'
|
||||||
- name: hold init
|
loop: '{{ sensu_users }}'
|
||||||
copy:
|
run_once: true
|
||||||
content: ''
|
no_log: true
|
||||||
dest: /etc/sensu/.backend-init
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0600
|
|
||||||
tags: sensu
|
tags: sensu
|
||||||
|
|
||||||
- name: manage cluster roles
|
- name: manage cluster roles
|
||||||
|
@ -64,24 +59,8 @@
|
||||||
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
|
||||||
|
@ -92,15 +71,14 @@
|
||||||
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 }}'
|
||||||
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
namespace: '{{ item.namespace|default("default") }}'
|
||||||
url: '{{ item.url }}'
|
url: '{{ item.url }}'
|
||||||
sha512: '{{ item.sha512 }}'
|
sha512: '{{ item.sha512 }}'
|
||||||
filters: '{{ item.filters|default([]) }}'
|
filters: '{{ item.filters|default([]) }}'
|
||||||
|
@ -108,15 +86,14 @@
|
||||||
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 }}'
|
||||||
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
namespace: '{{ item.namespace|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([]) }}'
|
||||||
|
@ -125,30 +102,14 @@
|
||||||
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 }}'
|
||||||
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
namespace: '{{ item.namespace|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([]) }}'
|
||||||
|
@ -157,31 +118,14 @@
|
||||||
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 }}'
|
||||||
namespaces: '{{ item.namespaces|default(["default"]) }}'
|
namespace: '{{ item.namespace|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 }}'
|
||||||
|
@ -192,7 +136,6 @@
|
||||||
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
|
||||||
|
|
98
tasks/build_agent.yml
Normal file
98
tasks/build_agent.yml
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
---
|
||||||
|
- 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,8 +1,9 @@
|
||||||
---
|
---
|
||||||
- include_tasks: 'repository-{{ ansible_os_family|lower }}.yml'
|
- import_tasks: repository.yml
|
||||||
|
when: not sensu_build
|
||||||
|
|
||||||
- import_tasks: agent.yml
|
- import_tasks: agent.yml
|
||||||
when: sensu_agent|bool
|
when: sensu_agent
|
||||||
|
|
||||||
- import_tasks: backend.yml
|
- import_tasks: backend.yml
|
||||||
when: sensu_backend|bool
|
when: sensu_backend
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
---
|
|
||||||
- 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,6 +1,6 @@
|
||||||
---
|
---
|
||||||
- name: install dependencies packages
|
- name: install dependencies packages
|
||||||
package:
|
apt:
|
||||||
name: '{{ packages }}'
|
name: '{{ packages }}'
|
||||||
vars:
|
vars:
|
||||||
packages:
|
packages:
|
||||||
|
@ -8,7 +8,6 @@
|
||||||
- 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
|
18
test/integration/build/default.yml
Normal file
18
test/integration/build/default.yml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
- 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
|
78
test/integration/build/serverspec/default_spec.rb
Normal file
78
test/integration/build/serverspec/default_spec.rb
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
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,23 +1,20 @@
|
||||||
---
|
---
|
||||||
- name: Converge
|
- hosts: default
|
||||||
hosts: all
|
connection: local
|
||||||
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
|
||||||
supersecret: password
|
hello:
|
||||||
|
warning: 30
|
||||||
|
critical: 50
|
||||||
sensu_namespaces:
|
sensu_namespaces:
|
||||||
- name: production
|
- name: supernamespace
|
||||||
- name: dev
|
|
||||||
sensu_users:
|
sensu_users:
|
||||||
- name: johndoe
|
- name: johndoe
|
||||||
password: secret1234
|
password: secret1234
|
||||||
|
@ -30,44 +27,18 @@
|
||||||
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:
|
||||||
|
@ -76,3 +47,6 @@
|
||||||
- list
|
- list
|
||||||
resources:
|
resources:
|
||||||
- '*'
|
- '*'
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- ansible-role-sensu
|
80
test/integration/default/serverspec/default_spec.rb
Normal file
80
test/integration/default/serverspec/default_spec.rb
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
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
|
2
test/integration/inventory
Normal file
2
test/integration/inventory
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[default]
|
||||||
|
localhost
|
Loading…
Reference in a new issue