Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
rewrite libraries to lwrp
Browse files Browse the repository at this point in the history
  • Loading branch information
bugoff committed Sep 2, 2020
1 parent 82333d9 commit bd73f5a
Show file tree
Hide file tree
Showing 88 changed files with 1,791 additions and 5,448 deletions.
54 changes: 39 additions & 15 deletions .kitchen.dokken.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ provisioner:
disable_conf_d: false

platforms:
- name: ubuntu-1404
driver:
image: ubuntu:14.04
pid_one_command: /sbin/init
intermediate_instructions:
- RUN /usr/bin/apt-get update -qq
- RUN /usr/bin/apt-get install -y net-tools apt-transport-https initscripts procps lsb-release curl gnupg
attributes:
icinga2-test-mysql-instance:
service_manager: sysvinit

- name: ubuntu-1604
driver:
image: ubuntu:16.04
Expand All @@ -51,6 +40,13 @@ platforms:
intermediate_instructions:
- RUN /usr/bin/apt-get update -qq

- name: ubuntu-2004
driver:
image: dokken/ubuntu-20.04
pid_one_command: /bin/systemd
intermediate_instructions:
- RUN /usr/bin/apt-get update -qq

- name: debian-8
driver:
image: debian:8.9
Expand All @@ -67,6 +63,14 @@ platforms:
- RUN /usr/bin/apt-get update -qq
- RUN /usr/bin/apt-get install -y net-tools apt-transport-https initscripts procps lsb-release curl gnupg

- name: debian-10
driver:
image: dokken/debian-10
pid_one_command: /bin/systemd
intermediate_instructions:
- RUN /usr/bin/apt-get update -qq
- RUN /usr/bin/apt-get install -y net-tools apt-transport-https initscripts procps lsb-release curl gnupg

- name: centos-6
driver:
image: centos:6.9
Expand Down Expand Up @@ -103,19 +107,39 @@ platforms:
- RUN yum install -y net-tools initscripts which

suites:
- name: chef12server
- name: chef13server
driver:
chef_version: 13
verifier:
inspec_tests:
- test/smoke/server
run_list:
- recipe[icinga2::default]
- recipe[icinga2-test::default]

- name: chef14server
driver:
chef_version: 12.21.4
chef_version: 14
verifier:
inspec_tests:
- test/smoke/server
run_list:
- recipe[icinga2::default]
- recipe[icinga2-test::default]

- name: chef13server
- name: chef15server
driver:
chef_version: 15
verifier:
inspec_tests:
- test/smoke/server
run_list:
- recipe[icinga2::default]
- recipe[icinga2-test::default]

- name: chef16server
driver:
chef_version: 13.3.42
chef_version: 16
verifier:
inspec_tests:
- test/smoke/server
Expand Down
36 changes: 29 additions & 7 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,57 @@ provisioner:
platforms:
- name: centos-6.8
- name: centos-7.2
- name: ubuntu-14.04
run_list:
- recipe[apt::default]
- name: ubuntu-16.04
run_list:
- recipe[apt::default]
- name: ubuntu-18.04
run_list:
- recipe[apt::default]
- name: ubuntu-20.04
run_list:
- recipe[apt::default]
- name: debian-8.5
run_list:
- recipe[apt::default]
- name: debian-9.5
run_list:
- recipe[apt::default]
- name: debian-10
run_list:
- recipe[apt::default]


suites:
- name: chef12server
- name: chef13server
driver:
require_chef_omnibus: 12.21.4
require_chef_omnibus: 13.3.42
verifier:
inspec_tests:
- test/smoke/server
run_list:
- recipe[icinga2::default]
- recipe[icinga2-test::default]
- name: chef13server
- name: chef14server
driver:
require_chef_omnibus: 13.3.42
require_chef_omnibus: 14
verifier:
inspec_tests:
- test/smoke/server
run_list:
- recipe[icinga2::default]
- recipe[icinga2-test::default]
- name: chef15server
driver:
require_chef_omnibus: 15
verifier:
inspec_tests:
- test/smoke/server
run_list:
- recipe[icinga2::default]
- recipe[icinga2-test::default]
- name: chef16server
driver:
require_chef_omnibus: 16
verifier:
inspec_tests:
- test/smoke/server
Expand Down
40 changes: 31 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ services: docker

env:
matrix:
- INSTANCE=chef12server-ubuntu-1404
- INSTANCE=chef12server-ubuntu-1604
- INSTANCE=chef12server-ubuntu-1804
- INSTANCE=chef12server-debian-8
- INSTANCE=chef12server-debian-9
- INSTANCE=chef12server-centos-6
- INSTANCE=chef12server-centos-7
- INSTANCE=chef12server-fedora-26
- INSTANCE=chef12server-amazon
- INSTANCE=chef13server-ubuntu-1404
- INSTANCE=chef13server-ubuntu-1604
- INSTANCE=chef13server-ubuntu-1804
Expand All @@ -41,6 +32,37 @@ env:
- INSTANCE=chef13server-centos-7
- INSTANCE=chef13server-fedora-26
- INSTANCE=chef13server-amazon
- INSTANCE=chef14server-ubuntu-1404
- INSTANCE=chef14server-ubuntu-1604
- INSTANCE=chef14server-ubuntu-1804
- INSTANCE=chef14server-debian-8
- INSTANCE=chef14server-debian-9
- INSTANCE=chef14server-centos-6
- INSTANCE=chef14server-centos-7
- INSTANCE=chef14server-fedora-26
- INSTANCE=chef14server-amazon
- INSTANCE=chef15server-ubuntu-1404
- INSTANCE=chef15server-ubuntu-1604
- INSTANCE=chef15server-ubuntu-1804
- INSTANCE=chef15server-ubuntu-2004
- INSTANCE=chef15server-debian-8
- INSTANCE=chef15server-debian-9
- INSTANCE=chef15server-debian-10
- INSTANCE=chef15server-centos-6
- INSTANCE=chef15server-centos-7
- INSTANCE=chef15server-fedora-26
- INSTANCE=chef15server-amazon
- INSTANCE=chef16server-ubuntu-1404
- INSTANCE=chef16server-ubuntu-1604
- INSTANCE=chef16server-ubuntu-1804
- INSTANCE=chef16server-ubuntu-2004
- INSTANCE=chef16server-debian-8
- INSTANCE=chef16server-debian-9
- INSTANCE=chef16server-debian-10
- INSTANCE=chef16server-centos-6
- INSTANCE=chef16server-centos-7
- INSTANCE=chef16server-fedora-26
- INSTANCE=chef16server-amazon

script:
- KITCHEN_LOCAL_YAML=.kitchen.dokken.yml /opt/chefdk/embedded/bin/kitchen verify ${INSTANCE}
Expand Down
20 changes: 10 additions & 10 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

default['icinga2']['version'] = value_for_platform(
%w(centos redhat fedora amazon) => { 'default' => '2.10.1-1' },
%w(debian ubuntu raspbian) => { 'default' => '2.10.1-1' },
%w(debian ubuntu raspbian) => { 'default' => '2.12.0-1' },
%w(windows) => { 'default' => '2.10.1' }
)
default['icinga2']['ignore_version'] = false
Expand Down Expand Up @@ -52,8 +52,8 @@
default['icinga2']['features_enabled_dir'] = ::File.join(node['icinga2']['conf_dir'], 'features-enabled')
default['icinga2']['features_available_dir'] = ::File.join(node['icinga2']['conf_dir'], 'features-available')

default['icinga2']['cluster_attribute'] = nil
default['icinga2']['application_attribute'] = nil
default['icinga2']['cluster_attribute'] = '' # used to be nil
default['icinga2']['application_attribute'] = '' # used to be nil
default['icinga2']['enable_cluster_hostgroup'] = true
default['icinga2']['enable_application_hostgroup'] = true
default['icinga2']['enable_role_hostgroup'] = false
Expand Down Expand Up @@ -147,8 +147,8 @@
default['icinga2']['object']['global-templates'] = false
default['icinga2']['object']['host']['import'] = 'generic-host'
default['icinga2']['object']['host']['max_check_attempts'] = 3
default['icinga2']['object']['host']['check_period'] = nil
default['icinga2']['object']['host']['notification_period'] = nil
default['icinga2']['object']['host']['check_period'] = '' # used to be nil
default['icinga2']['object']['host']['notification_period'] = '' # used to be nil
default['icinga2']['object']['host']['check_interval'] = '1m'
default['icinga2']['object']['host']['retry_interval'] = '30s'
default['icinga2']['object']['host']['enable_notifications'] = true
Expand All @@ -157,9 +157,9 @@
default['icinga2']['object']['host']['enable_event_handler'] = true
default['icinga2']['object']['host']['enable_flapping'] = true
default['icinga2']['object']['host']['enable_perfdata'] = true
default['icinga2']['object']['host']['event_command'] = nil
default['icinga2']['object']['host']['flapping_threshold'] = nil
default['icinga2']['object']['host']['volatile'] = nil
default['icinga2']['object']['host']['event_command'] = '' # used to be nil
default['icinga2']['object']['host']['flapping_threshold'] = '' # used to be nil
default['icinga2']['object']['host']['volatile'] = '' # used to be nil
default['icinga2']['object']['host']['check_command'] = 'hostalive'
default['icinga2']['object']['host']['zone'] = nil
default['icinga2']['object']['host']['command_endpoint'] = nil
default['icinga2']['object']['host']['zone'] = '' # used to be nil
default['icinga2']['object']['host']['command_endpoint'] = '' # used to be nil
91 changes: 91 additions & 0 deletions libraries/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@


def create_hostgroups(env_resources)
env_hostgroups = []

# environment hostgroups
env_hostgroups += env_resources['clusters'] if new_resource.enable_cluster_hostgroup && env_resources.key?('clusters') && env_resources['clusters'].is_a?(Array)

env_hostgroups += env_resources['applications'] if new_resource.enable_application_hostgroup && env_resources.key?('applications') && env_resources['applications'].is_a?(Array)

env_hostgroups += env_resources['roles'] if new_resource.enable_role_hostgroup && env_resources.key?('roles') && env_resources['roles'].is_a?(Array)

env_hostgroups.uniq!

hostgroup_template = icinga2_envhostgroup new_resource.environment do
groups env_hostgroups
zone new_resource.zone
end

hostgroup_template.updated?
end

def create_endpoints(env_resources)
nodes = env_resources['nodes']
env_endpoints = nodes.map { |n| n[1]['fqdn'] }

endpoint_template = icinga2_envendpoint new_resource.environment do
endpoints env_endpoints
port new_resource.endpoint_port
log_duration new_resource.endpoint_log_duration
zone new_resource.zone
end

endpoint_template.updated?
end

def create_zones(env_resources)
nodes = env_resources['nodes']
env_zones = nodes.map { |n| n[1]['fqdn'] }

zone_template = icinga2_envzone new_resource.environment do
zones env_zones
parent new_resource.zone_parent
zone new_resource.zone
end

zone_template.updated?
end

def create_pki_tickets(env_resources)
env = new_resource.environment
salt = new_resource.pki_ticket_salt
nodes = env_resources['nodes']
all_fqdns = nodes.map { |n| n[1]['fqdn'] }
tickets = {}

begin
databag_item = data_bag_item('icinga2', "#{env}-pki-tickets")
tickets = databag_item['tickets']

if tickets['salt'] != salt
uncreated_tickets_fqdns = all_fqdns
else
tickets_fqdns = tickets.map { |k, _v| k }
uncreated_tickets_fqdns = all_fqdns - tickets_fqdns
end
rescue
uncreated_tickets_fqdns = all_fqdns
end

unless uncreated_tickets_fqdns.empty?
uncreated_tickets_fqdns.each do |f|
ruby_block "Create PKI-Ticket #{f}" do
block do
ticket_bash = Mixlib::ShellOut.new("icinga2 pki ticket --cn #{f} --salt #{salt}")
ticket_bash.run_command
tickets[f] = ticket_bash.stdout.chomp
databag_item = Chef::DataBagItem.new
databag_item.data_bag('icinga2')
databag_item.raw_data = {
'id' => "#{env}-pki-tickets",
'tickets' => tickets,
'salt' => salt,
}
databag_item.save
end
action :create
end
end
end
end
Loading

0 comments on commit bd73f5a

Please sign in to comment.