Compare commits
2 commits
master
...
build-sens
Author | SHA1 | Date | |
---|---|---|---|
5024bfa3ea | |||
130854c97e |
8 changed files with 224 additions and 0 deletions
|
@ -25,3 +25,8 @@ platforms:
|
|||
|
||||
suites:
|
||||
- name: default
|
||||
- name: build
|
||||
provisioner:
|
||||
extra_vars:
|
||||
sensu_build: yes
|
||||
sensu_build_go_version: 1.11
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
sensu_agent: yes
|
||||
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_release: '{{ ansible_distribution_release }}'
|
||||
|
||||
|
|
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
|
|
@ -12,8 +12,12 @@
|
|||
retries: 3
|
||||
delay: 1
|
||||
until: result is success
|
||||
when: not sensu_build
|
||||
tags: sensu
|
||||
|
||||
- import_tasks: build_agent.yml
|
||||
when: sensu_build
|
||||
|
||||
- name: copy agent configuration file
|
||||
copy:
|
||||
content: '{{ sensu_agent_full_config|to_nice_yaml }}'
|
||||
|
|
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,5 +1,6 @@
|
|||
---
|
||||
- import_tasks: repository.yml
|
||||
when: not sensu_build
|
||||
|
||||
- import_tasks: agent.yml
|
||||
when: sensu_agent
|
||||
|
|
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
|
Loading…
Reference in a new issue