Skip to content

Commit

Permalink
test: add scenario with mixed livestatus / http sources
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Oct 18, 2021
1 parent b480ac7 commit 4c884bd
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,7 @@ t/610-scenario-backend_http.t
t/610-scenario-backend_http_readonly.t
t/610-scenario-backend_icinga.t
t/610-scenario-backend_icinga2.t
t/610-scenario-backend_mixed_source.t
t/610-scenario-backend_multi.t
t/610-scenario-backend_naemon.t
t/610-scenario-backend_shinken.t
Expand Down Expand Up @@ -2093,6 +2094,14 @@ t/scenarios/backend_icinga2/t/300-controller_status.t
t/scenarios/backend_icinga2/t/300-controller_tac.t
t/scenarios/backend_icinga2/thruk.conf
t/scenarios/backend_icinga2/thruk_local.conf
t/scenarios/backend_mixed_source/docker-compose.yml
t/scenarios/backend_mixed_source/Makefile
t/scenarios/backend_mixed_source/omd/Dockerfile
t/scenarios/backend_mixed_source/omd/playbook.yml
t/scenarios/backend_mixed_source/omd/test.cfg
t/scenarios/backend_mixed_source/t/301-config-tool.t
t/scenarios/backend_mixed_source/thruk.conf
t/scenarios/backend_mixed_source/thruk_local.conf
t/scenarios/backend_multi/docker-compose.yml
t/scenarios/backend_multi/Makefile
t/scenarios/backend_multi/omd/Dockerfile
Expand Down
1 change: 1 addition & 0 deletions t/610-scenario-backend_mixed_source.t
1 change: 1 addition & 0 deletions t/scenarios/backend_mixed_source/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../_common/Makefile.common
8 changes: 8 additions & 0 deletions t/scenarios/backend_mixed_source/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
site:
build: omd/
ports:
- "127.0.0.3:60080:80"
- "127.0.0.3:60443:443"
- "127.0.0.3:60557:6557"
volumes:
- ../../../:/thruk:ro
5 changes: 5 additions & 0 deletions t/scenarios/backend_mixed_source/omd/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM consol/omd-labs-centos:latest

COPY playbook.yml /root/ansible_dropin/
ENV ANSIBLE_ROLES_PATH /thruk/t/scenarios/_common/ansible/roles
COPY test.cfg /root/
27 changes: 27 additions & 0 deletions t/scenarios/backend_mixed_source/omd/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- hosts: all
roles:
- role: common
- role: thruk_developer
- role: test-config-generator
tasks:
- shell: omd config demo set APACHE_MODE own
- shell: omd config demo set CORE naemon
- shell: omd config demo set LIVESTATUS_TCP on
- copy:
src: /omd/sites/demo/share/doc/naemon/example.cfg
dest: /omd/sites/demo/etc/naemon/conf.d/example.cfg
owner: demo
group: demo
- shell: echo "testkey" > /omd/sites/demo/var/thruk/secret.key
- file:
path: /omd/sites/demo/var/thruk/secret.key
mode: 0600
owner: demo
group: demo
- copy:
src: /root/test.cfg
dest: /omd/sites/demo/etc/naemon/conf.d/test.cfg
owner: demo
group: demo

12 changes: 12 additions & 0 deletions t/scenarios/backend_mixed_source/omd/test.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
define servicegroup {
servicegroup_name Http Check
alias Http Checks
members localhost,Http
}

define hostgroup {
hostgroup_name Everything
alias Just all hosts
members *
}

139 changes: 139 additions & 0 deletions t/scenarios/backend_mixed_source/t/301-config-tool.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
use warnings;
use strict;
use Cpanel::JSON::XS qw/decode_json/;
use Test::More;

BEGIN {
plan tests => 246;

use lib('t');
require TestUtils;
import TestUtils;
}

use_ok 'Thruk::Controller::rest_v1';
TestUtils::set_test_user_token();
my($host,$service) = ('localhost', 'Users');
my($hostgroup,$servicegroup) = ('Everything', 'Http Check');

my $pages = [{
# force reschedule so we get some performance data
url => 'POST /hosts/<name>/cmd/schedule_forced_host_check',
post => { start_time => 'now' },
like => ['Command successfully submitted'],
}, {
url => 'GET /hosts/<name>',
waitfor => 'rta_unit',
}, {
url => 'GET /hosts/<name>',
like => ['"rta_unit" : "ms",', '"rta" : "\d+\.\d+', ''],
}, {
# verify configuration from config tool
url => 'GET /hosts/<name>/config',
like => ['"alias" : "localhost",', '"address" : "127.0.0.1",', '/omd/sites/demo/etc/naemon/conf.d/example.cfg:1'],
}, {
url => 'GET /hostgroups/'.$hostgroup.'/config',
like => ['Just all hosts'],
}, {
url => 'GET /servicegroups/'.$servicegroup.'/config',
like => ['Http Checks'],
}, {
# change a few things
url => 'PATCH /hosts/<name>/config',
post => {address => '127.0.0.2', max_check_attempts => 5, icon_image => undef },
like => ['changed 1 objects successfully.'],
}, {
url => 'GET /hosts/<name>/config',
like => ['"alias" : "localhost",', '"address" : "127.0.0.2",', '/omd/sites/demo/etc/naemon/conf.d/example.cfg:1'],
unlike => ['icon_image'],
}, {
url => 'GET /config/diff',
like => ['/omd/sites/demo/etc/naemon/conf.d/example.cfg', 'max_check_attempts'],
}, {
url => 'POST /config/check',
post => {},
like => ['"failed" : false,', 'Running configuration check'],
}, {
url => 'POST /config/save',
post => {},
like => ['successfully saved changes for 1 site.'],
}, {
url => 'POST /config/reload',
post => {},
like => ['"failed" : false'],
}, {
url => 'GET /hosts/<name>/config',
like => ['"alias" : "localhost",', '"address" : "127.0.0.2",', '/omd/sites/demo/etc/naemon/conf.d/example.cfg:1'],
unlike => ['icon_image'],
}, {
url => 'GET /hosts/<name>',
like => ['"alias" : "localhost",', '"address" : "127.0.0.2",'],
}, {
# try reverting changes
url => 'PATCH /hosts/<name>/config',
post => {address => '127.0.0.1', max_check_attempts => undef, icon_image => "linux40.png" },
like => ['changed 1 objects successfully.'],
}, {
url => 'GET /config/diff',
like => ['/omd/sites/demo/etc/naemon/conf.d/example.cfg', 'linux40.png'],
}, {
url => 'POST /config/revert',
post => {},
like => ['successfully reverted stashed changes for 1 site.'],
}, {
# try deleting things
url => 'DELETE /hosts/<name>/config',
post => {},
like => ['removed 1 objects successfully.'],
}, {
url => 'GET /config/diff',
like => ['/omd/sites/demo/etc/naemon/conf.d/example.cfg', '-\s*alias'],
}, {
url => 'POST /config/revert',
post => {},
like => ['successfully reverted stashed changes for 1 site.'],
}, {
# finally revert host back to start
url => 'PATCH /hosts/<name>/config',
post => {address => '127.0.0.1', max_check_attempts => undef, icon_image => "linux40.png" },
like => ['changed 1 objects successfully.'],
}, {
url => 'POST /config/save',
post => {},
like => ['successfully saved changes for 1 site.'],
}, {
url => 'POST /config/reload',
post => {},
like => ['"failed" : false'],
}, {
url => 'GET /hosts/<name>/config',
like => ['"alias" : "localhost",', '"address" : "127.0.0.1",', '/omd/sites/demo/etc/naemon/conf.d/example.cfg:1', 'linux40.png'],
}, {
url => 'GET /config/files',
like => ['/etc/naemon/conf.d/example.cfg', '/etc/naemon/conf.d/test.cfg'],
}, {
url => 'GET /config/objects',
like => ['/etc/naemon/conf.d/example.cfg', '/etc/naemon/conf.d/test.cfg'],
}, {
url => 'GET /config/fullobjects',
like => ['/etc/naemon/conf.d/example.cfg', '/etc/naemon/conf.d/test.cfg', ':TEMPLATES'],
}, {
# create new host
url => 'POST /config/objects',
post => {':TYPE' => 'host', ':FILE' => '301-test.cfg', 'name' => '301-test'},
like => ['created 1 objects successfully.', '301-test.cfg'],
}, {
url => 'POST /config/revert',
post => {},
like => ['successfully reverted stashed changes for 1 site.'],
},
];

for my $test (@{$pages}) {
my($method, $url) = split(/\s+/mx, $test->{'url'}, 2);
$url =~ s%/hosts?/<name>%/hosts/$host%gmx;
$test->{'url'} = '/thruk/r'.$url;
$test->{'method'} = $method;
$test->{'content_type'} = 'application/json; charset=utf-8';
my $page = TestUtils::test_page(%{$test});
}
1 change: 1 addition & 0 deletions t/scenarios/backend_mixed_source/thruk.conf
16 changes: 16 additions & 0 deletions t/scenarios/backend_mixed_source/thruk_local.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Component Thruk::Backend>
<peer>
name = naemon
id = abcd
type = livestatus
<options>
peer = 127.0.0.3:60557
peer = http://127.0.0.3:60080/demo
auth = testkey
</options>
</peer>
</Component>

#use_lmd_core=1
#lmd_core_bin=lmd
#lmd_core_config=t/scenarios/backend_mixed_source/lmd.ini

0 comments on commit 4c884bd

Please sign in to comment.