feat: add multiple namespaces for the checks, filters, handlers or assets
This commit is contained in:
parent
4a5a1aad1a
commit
a1ca0159db
9 changed files with 104 additions and 79 deletions
|
@ -4,6 +4,7 @@ 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]
|
||||||
|
- 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
|
- fix: install build-essential for agent
|
||||||
- test: add travis ci
|
- test: add travis ci
|
||||||
|
|
12
README.md
12
README.md
|
@ -61,7 +61,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: []
|
||||||
|
@ -78,7 +79,8 @@ Install and configure sensu-go backend and agent
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: load
|
- name: load
|
||||||
namespace: default
|
namespace:
|
||||||
|
- default
|
||||||
command: /usr/bin/load -w 2 -c 5
|
command: /usr/bin/load -w 2 -c 5
|
||||||
handlers:
|
handlers:
|
||||||
- mailer
|
- mailer
|
||||||
|
@ -93,7 +95,8 @@ Install and configure sensu-go backend and agent
|
||||||
|
|
||||||
```
|
```
|
||||||
- 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:
|
||||||
|
@ -106,7 +109,8 @@ Install and configure sensu-go backend and agent
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: max_occurences
|
- name: max_occurences
|
||||||
namespace: default
|
namespace:
|
||||||
|
- default
|
||||||
action: allow
|
action: allow
|
||||||
expressions:
|
expressions:
|
||||||
runtime_assets: []
|
runtime_assets: []
|
||||||
|
|
|
@ -43,7 +43,7 @@ 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': [] },
|
||||||
|
@ -67,10 +67,11 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
|
for namespace in module.params['namespaces']:
|
||||||
asset = SensuAsset(
|
asset = SensuAsset(
|
||||||
api,
|
api,
|
||||||
module.params['name'],
|
module.params['name'],
|
||||||
module.params['namespace']
|
namespace
|
||||||
)
|
)
|
||||||
asset.get_data()
|
asset.get_data()
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ 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'] },
|
||||||
'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 },
|
||||||
|
@ -81,10 +81,11 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
|
for namespace in module.params['namespaces']:
|
||||||
check = SensuCheck(
|
check = SensuCheck(
|
||||||
api,
|
api,
|
||||||
module.params['name'],
|
module.params['name'],
|
||||||
module.params['namespace']
|
namespace
|
||||||
)
|
)
|
||||||
check.get_data()
|
check.get_data()
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ 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': [] },
|
||||||
|
@ -74,10 +74,11 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
|
for namespace in module.params['namespaces']:
|
||||||
filter = SensuFilter(
|
filter = SensuFilter(
|
||||||
api,
|
api,
|
||||||
module.params['name'],
|
module.params['name'],
|
||||||
module.params['namespace']
|
namespace
|
||||||
)
|
)
|
||||||
filter.get_data()
|
filter.get_data()
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ 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': [] },
|
||||||
|
@ -76,10 +76,11 @@ def main():
|
||||||
)
|
)
|
||||||
api.auth()
|
api.auth()
|
||||||
|
|
||||||
|
for namespace in module.params['namespaces']:
|
||||||
handler = SensuHandler(
|
handler = SensuHandler(
|
||||||
api,
|
api,
|
||||||
module.params['name'],
|
module.params['name'],
|
||||||
module.params['namespace']
|
namespace
|
||||||
)
|
)
|
||||||
handler.get_data()
|
handler.get_data()
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
- 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([]) }}'
|
||||||
|
@ -93,7 +93,7 @@
|
||||||
- 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([]) }}'
|
||||||
|
@ -109,7 +109,7 @@
|
||||||
- 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([]) }}'
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
- 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"]) }}'
|
||||||
command: '{{ item.command }}'
|
command: '{{ item.command }}'
|
||||||
handlers: '{{ item.handlers|default([]) }}'
|
handlers: '{{ item.handlers|default([]) }}'
|
||||||
subscriptions: '{{ item.subscriptions }}'
|
subscriptions: '{{ item.subscriptions }}'
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
warning: 30
|
warning: 30
|
||||||
critical: 50
|
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 +28,30 @@
|
||||||
sha512: >
|
sha512: >
|
||||||
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce
|
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce
|
||||||
47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
||||||
|
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_checks:
|
sensu_checks:
|
||||||
- name: ping
|
- name: ping
|
||||||
command: ping -c 1 127.0.0.1
|
command: ping -c 1 127.0.0.1
|
||||||
subscriptions:
|
subscriptions:
|
||||||
- linux
|
- linux
|
||||||
|
namespaces:
|
||||||
|
- production
|
||||||
|
- dev
|
||||||
sensu_cluster_roles:
|
sensu_cluster_roles:
|
||||||
- name: superview
|
- name: superview
|
||||||
rules:
|
rules:
|
||||||
|
|
|
@ -46,7 +46,8 @@ end
|
||||||
|
|
||||||
describe command('sensuctl namespace list') do
|
describe command('sensuctl namespace list') do
|
||||||
its(:exit_status) { should eq 0 }
|
its(:exit_status) { should eq 0 }
|
||||||
its(:stdout) { should match 'supernamespace' }
|
its(:stdout) { should match 'production' }
|
||||||
|
its(:stdout) { should match 'dev' }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe command('sensuctl user list') do
|
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/) }
|
its(:stdout) { should match(/johndoe.*\s+devops,users\s+.*true/) }
|
||||||
end
|
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(:exit_status) { should eq 0 }
|
||||||
its(:stdout) { should match(/superasset.*\s+.*test.sh\s+cf83e13/) }
|
its(:stdout) { should match(/superasset.*\s+.*test.sh\s+cf83e13/) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe command('sensuctl handler list') do
|
describe command("sensuctl handler list --namespace #{namespace}") do
|
||||||
its(:exit_status) { should eq 0 }
|
its(:exit_status) { should eq 0 }
|
||||||
its(:stdout) { should match(/mail.*\s+pipe\s+.*echo test \| mail -s coucou\s+/) }
|
its(:stdout) { should match(/mail.*\s+pipe\s+.*echo test \| mail -s coucou\s+/) }
|
||||||
end
|
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(:exit_status) { should eq 0 }
|
||||||
its(:stdout) { should match(/state_changed.*\s+allow\s+event\.check\.occurrences == 1/) }
|
its(:stdout) { should match(/state_changed.*\s+allow\s+event\.check\.occurrences == 1/) }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe command('sensuctl cluster-role list') do
|
describe command('sensuctl cluster-role list') do
|
||||||
its(:exit_status) { should eq 0 }
|
its(:exit_status) { should eq 0 }
|
||||||
its(:stdout) { should match(/view.*\s+1/) }
|
its(:stdout) { should match(/view.*\s+1/) }
|
||||||
end
|
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
|
|
||||||
|
|
Loading…
Reference in a new issue