Last active
June 25, 2019 21:24
-
-
Save dnsmichi/bbf85c7a83ccd454afa9 to your computer and use it in GitHub Desktop.
Using icinga2 2.2 features with apply for in dictionary and attribute assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cat 7560.conf | |
object Host "7560-server" { | |
import "test-generic-host" | |
address = "127.0.0.1" | |
check_command = "hostalive" | |
vars.interfaces["eth0"] = { | |
//vars.interfaces.eth0 = { | |
"2dcoord" = "3,5" | |
port = 1 | |
vlan = "internal" | |
address = "127.0.0.2" | |
qos = "enabled" | |
} | |
vars.interfaces.eth1 = { | |
port = 2 | |
vlan = "mgmt" | |
address = "127.0.1.2" | |
} | |
vars.interfaces.eth2 = { | |
port = 3 | |
vlan = "remote" | |
address = "127.0.2.2" | |
} | |
} | |
apply Service "if-" for (if_name => config in host.vars.interfaces) { | |
import "test-generic-service" | |
check_command = "ping4" | |
vars.qos = "disabled" | |
vars += config | |
display_name = "if-" + if_name + "-" + vars.vlan | |
notes = "Interface check for Port " + string(vars.port) + " in VLAN " + vars.vlan + " on Address " + vars.address + " QoS " + vars.qos | |
notes_url = "http://foreman.company.com/hosts/" + host.name | |
action_url = "http://snmp.checker.company.com/" + host.name + "if-" + if_name | |
assign where match("7560-*", host.name) && typeof(host.vars.interfaces) == typeof({}) | |
} | |
# icinga2 object list --name 'if-*' | |
Object 7560-server!if-eth0' of type 'Service': | |
* __name = "7560-server!if-eth0" | |
* action_url = "http://snmp.checker.company.com/7560-serverif-eth0" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 37:3-37:79 | |
* check_command = "ping4" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 28:3-28:25 | |
* check_interval = 300 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 7:3-7:21 | |
* display_name = "if-eth0-internal" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 33:3-33:50 | |
* host_name = "7560-server" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 26:1-26:67 | |
* max_check_attempts = 3 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 6:3-6:24 | |
* name = "if-eth0" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 26:1-26:67 | |
* notes = "Interface check for Port 1 in VLAN internal on Address 127.0.0.2 QoS enabled" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 35:3-35:136 | |
* notes_url = "http://foreman.company.com/hosts/7560-server" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 36:3-36:61 | |
* retry_interval = 60 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 8:3-8:21 | |
* templates = [ "test-generic-service" ] | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 26:1-26:67 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 5:1-9:1 | |
* type = "Service" | |
* vars | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 31:3-31:16 | |
* 2dcoord = "3,5" | |
* address = "127.0.0.2" | |
* port = 1 | |
* qos = "enabled" | |
* vlan = "internal" | |
Object 7560-server!if-eth1' of type 'Service': | |
* __name = "7560-server!if-eth1" | |
* action_url = "http://snmp.checker.company.com/7560-serverif-eth1" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 37:3-37:79 | |
* check_command = "ping4" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 28:3-28:25 | |
* check_interval = 300 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 7:3-7:21 | |
* display_name = "if-eth1-mgmt" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 33:3-33:50 | |
* host_name = "7560-server" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 26:1-26:67 | |
* max_check_attempts = 3 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 6:3-6:24 | |
* name = "if-eth1" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 26:1-26:67 | |
* notes = "Interface check for Port 2 in VLAN mgmt on Address 127.0.1.2 QoS disabled" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 35:3-35:136 | |
* notes_url = "http://foreman.company.com/hosts/7560-server" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 36:3-36:61 | |
* retry_interval = 60 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 8:3-8:21 | |
* templates = [ "test-generic-service" ] | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 26:1-26:67 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 5:1-9:1 | |
* type = "Service" | |
* vars | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 31:3-31:16 | |
* address = "127.0.1.2" | |
* port = 2 | |
* qos = "disabled" | |
* vlan = "mgmt" | |
Object 7560-server!if-eth2' of type 'Service': | |
* __name = "7560-server!if-eth2" | |
* action_url = "http://snmp.checker.company.com/7560-serverif-eth2" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 37:3-37:79 | |
* check_command = "ping4" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 28:3-28:25 | |
* check_interval = 300 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 7:3-7:21 | |
* display_name = "if-eth2-remote" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 33:3-33:50 | |
* host_name = "7560-server" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 26:1-26:67 | |
* max_check_attempts = 3 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 6:3-6:24 | |
* name = "if-eth2" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 26:1-26:67 | |
* notes = "Interface check for Port 3 in VLAN remote on Address 127.0.2.2 QoS disabled" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 35:3-35:136 | |
* notes_url = "http://foreman.company.com/hosts/7560-server" | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 36:3-36:61 | |
* retry_interval = 60 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 8:3-8:21 | |
* templates = [ "test-generic-service" ] | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 26:1-26:67 | |
% = modified in '/etc/icinga2/conf.d/tests/templates.conf', lines 5:1-9:1 | |
* type = "Service" | |
* vars | |
% = modified in '/etc/icinga2/conf.d/7560.conf', lines 31:3-31:16 | |
* address = "127.0.2.2" | |
* port = 3 | |
* qos = "disabled" | |
* vlan = "remote" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment