feat: add multiple namespaces for the checks, filters, handlers or assets

This commit is contained in:
Adrien Waksberg 2019-02-15 20:09:49 +01:00
parent 4a5a1aad1a
commit a1ca0159db
9 changed files with 104 additions and 79 deletions

View file

@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
Which is based on [Keep A Changelog](http://keepachangelog.com/)
## [Unreleased]
- feat: add multiple namespaces for the checks, filters, handlers or assets
- fix: install python-requests for backend
- fix: install build-essential for agent
- test: add travis ci

View file

@ -61,7 +61,8 @@ Install and configure sensu-go backend and agent
```
- name: http-binary
namespace: default
namespace:
- default
url: http://host.local
sha512: XXXX
filters: []
@ -78,7 +79,8 @@ Install and configure sensu-go backend and agent
```
- name: load
namespace: default
namespace:
- default
command: /usr/bin/load -w 2 -c 5
handlers:
- mailer
@ -93,7 +95,8 @@ Install and configure sensu-go backend and agent
```
- name: mailer
namespace: default
namespace:
- default
type: pipe
command: /usr/local/bin/sensu-email-handler -t sensu@host.local
filters:
@ -106,7 +109,8 @@ Install and configure sensu-go backend and agent
```
- name: max_occurences
namespace: default
namespace:
- default
action: allow
expressions:
runtime_assets: []

View file

@ -43,7 +43,7 @@ class SensuAsset:
def main():
fields = {
'name': { 'type': 'str', 'required': True },
'namespace': { 'type': 'str', 'default': 'default' },
'namespaces': { 'type': 'list', 'default': ['default'] },
'url': { 'type': 'str', 'required': True },
'sha512': { 'type': 'str', 'required': True },
'filters': { 'type': 'list', 'default': [] },
@ -67,10 +67,11 @@ def main():
)
api.auth()
for namespace in module.params['namespaces']:
asset = SensuAsset(
api,
module.params['name'],
module.params['namespace']
namespace
)
asset.get_data()

View file

@ -49,7 +49,7 @@ class SensuCheck:
def main():
fields = {
'name': { 'type': 'str', 'required': True },
'namespace': { 'type': 'str', 'default': 'default' },
'namespaces': { 'type': 'list', 'default': ['default'] },
'command': { 'type': 'str', 'required': True },
'handlers': { 'type': 'list', 'default': [] },
'subscriptions': { 'type': 'list', 'required': True },
@ -81,10 +81,11 @@ def main():
)
api.auth()
for namespace in module.params['namespaces']:
check = SensuCheck(
api,
module.params['name'],
module.params['namespace']
namespace
)
check.get_data()

View file

@ -49,7 +49,7 @@ class SensuFilter:
def main():
fields = {
'name': { 'type': 'str', 'required': True },
'namespace': { 'type': 'str', 'default': 'default' },
'namespaces': { 'type': 'list', 'default': ['default'] },
'action': { 'type': 'str', 'default': 'allow', 'choices': ['allow', 'deny'] },
'expressions': { 'type': 'list', 'required': True },
'runtime_assets': { 'type': 'list', 'default': [] },
@ -74,10 +74,11 @@ def main():
)
api.auth()
for namespace in module.params['namespaces']:
filter = SensuFilter(
api,
module.params['name'],
module.params['namespace']
namespace
)
filter.get_data()

View file

@ -49,7 +49,7 @@ class SensuHandler:
def main():
fields = {
'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'] },
'command': { 'type': 'str', 'required': True },
'filters': { 'type': 'list', 'default': [] },
@ -76,10 +76,11 @@ def main():
)
api.auth()
for namespace in module.params['namespaces']:
handler = SensuHandler(
api,
module.params['name'],
module.params['namespace']
namespace
)
handler.get_data()

View file

@ -78,7 +78,7 @@
- name: manage assets
sensugo_asset:
name: '{{ item.name }}'
namespace: '{{ item.namespace|default("default") }}'
namespaces: '{{ item.namespaces|default(["default"]) }}'
url: '{{ item.url }}'
sha512: '{{ item.sha512 }}'
filters: '{{ item.filters|default([]) }}'
@ -93,7 +93,7 @@
- name: manage filters
sensugo_filter:
name: '{{ item.name }}'
namespace: '{{ item.namespace|default("default") }}'
namespaces: '{{ item.namespaces|default(["default"]) }}'
action: '{{ item.action|default("allow") }}'
expressions: '{{ item.expressions }}'
runtime_assets: '{{ item.runtime_assets|default([]) }}'
@ -109,7 +109,7 @@
- name: manage handlers
sensugo_handler:
name: '{{ item.name }}'
namespace: '{{ item.namespace|default("default") }}'
namespaces: '{{ item.namespaces|default(["default"]) }}'
type: '{{ item.type|default("pipe") }}'
command: '{{ item.command }}'
filters: '{{ item.filters|default([]) }}'
@ -125,7 +125,7 @@
- name: manage checks
sensugo_check:
name: '{{ item.name }}'
namespace: '{{ item.namespace|default("default") }}'
namespaces: '{{ item.namespaces|default(["default"]) }}'
command: '{{ item.command }}'
handlers: '{{ item.handlers|default([]) }}'
subscriptions: '{{ item.subscriptions }}'

View file

@ -14,7 +14,8 @@
warning: 30
critical: 50
sensu_namespaces:
- name: supernamespace
- name: production
- name: dev
sensu_users:
- name: johndoe
password: secret1234
@ -27,18 +28,30 @@
sha512: >
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce
47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
namespaces:
- production
- dev
sensu_handlers:
- name: mail
command: echo test | mail -s coucou
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
rules:

View file

@ -46,7 +46,8 @@ end
describe command('sensuctl namespace list') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match 'supernamespace' }
its(:stdout) { should match 'production' }
its(:stdout) { should match 'dev' }
end
describe command('sensuctl user list') do
@ -54,27 +55,29 @@ describe command('sensuctl user list') do
its(:stdout) { should match(/johndoe.*\s+devops,users\s+.*true/) }
end
describe command('sensuctl asset list') do
%w[production dev].each do |namespace|
describe command("sensuctl asset list --namespace #{namespace}") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/superasset.*\s+.*test.sh\s+cf83e13/) }
end
describe command('sensuctl handler list') do
describe command("sensuctl handler list --namespace #{namespace}") 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
describe command("sensuctl check list --namespace #{namespace}") 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
describe command("sensuctl filter list --namespace #{namespace}") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/state_changed.*\s+allow\s+event\.check\.occurrences == 1/) }
end
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