bundles/icinga2: rework config generation - use one file per host instead of one per bundle
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit
This commit is contained in:
parent
5aa9f50c79
commit
d35770c122
5 changed files with 82 additions and 101 deletions
|
@ -1,4 +1,4 @@
|
|||
% for monitored_node in sorted(monitored_nodes):
|
||||
% for monitored_node in sorted(repo.nodes):
|
||||
<%
|
||||
auto_updates_enabled = (
|
||||
monitored_node.has_any_bundle(['apt', 'c3voc-addons'])
|
||||
|
@ -6,7 +6,7 @@
|
|||
monitored_node.has_bundle('pacman')
|
||||
and monitored_node.metadata.get('pacman/unattended-upgrades/is_enabled', False)
|
||||
)
|
||||
)
|
||||
) and not monitored_node.metadata.get('icinga_options/exclude_from_monitoring', False)
|
||||
%>\
|
||||
% if auto_updates_enabled:
|
||||
object ScheduledDowntime "unattended_upgrades" {
|
||||
|
|
|
@ -1,35 +1,3 @@
|
|||
% for monitored_node in sorted(monitored_nodes):
|
||||
object Host "${monitored_node.name}" {
|
||||
import "generic-host"
|
||||
|
||||
address = "${monitored_node.metadata.get('icinga_options/hostname', monitored_node.hostname)}"
|
||||
|
||||
# used for determining service groups
|
||||
vars.bw_groups = [ "${'", "'.join(sorted({group.name for group in monitored_node.groups}))}" ]
|
||||
vars.location = "${monitored_node.metadata.get('location', 'unknown')}"
|
||||
vars.os = "${monitored_node.os}"
|
||||
|
||||
# used for status page
|
||||
vars.pretty_name = "${monitored_node.metadata.get('icinga_options/pretty_name', monitored_node.name)}"
|
||||
|
||||
vars.period = "${sla_info[monitored_node.metadata.get('sla', '24x7')]}"
|
||||
vars.sla = "${monitored_node.metadata.get('sla', '24x7')}"
|
||||
|
||||
vars.notification.sms = ${str(monitored_node.metadata.get('icinga_options/vars.notification.sms', True)).lower()}
|
||||
vars.notification.mail = true
|
||||
}
|
||||
% for depends_on_host in sorted(monitored_node.metadata.get('icinga_options/also_affected_by', set())):
|
||||
object Dependency "${monitored_node.name}_depends_on_${depends_on_host}" {
|
||||
parent_host_name = "${depends_on_host}"
|
||||
child_host_name = "${monitored_node.name}"
|
||||
states = [ Up ]
|
||||
disable_checks = true
|
||||
disable_notifications = true
|
||||
ignore_soft_states = true
|
||||
}
|
||||
% endfor
|
||||
% endfor
|
||||
|
||||
apply Dependency "disable-service-checks-on-host-down" to Service {
|
||||
disable_checks = true
|
||||
ignore_soft_states = true
|
||||
|
|
56
bundles/icinga2/files/icinga2/hosts_template.conf
Normal file
56
bundles/icinga2/files/icinga2/hosts_template.conf
Normal file
|
@ -0,0 +1,56 @@
|
|||
object Host "${rnode.name}" {
|
||||
import "generic-host"
|
||||
|
||||
address = "${rnode.metadata.get('icinga_options/hostname', rnode.hostname)}"
|
||||
|
||||
# used for determining service groups
|
||||
vars.bw_groups = [ "${'", "'.join(sorted({group.name for group in rnode.groups}))}" ]
|
||||
vars.location = "${rnode.metadata.get('location', 'unknown')}"
|
||||
vars.os = "${rnode.os}"
|
||||
|
||||
# used for status page
|
||||
vars.pretty_name = "${rnode.metadata.get('icinga_options/pretty_name', rnode.name)}"
|
||||
|
||||
vars.period = "${sla_info[rnode.metadata.get('sla', '24x7')]}"
|
||||
vars.sla = "${rnode.metadata.get('sla', '24x7')}"
|
||||
|
||||
vars.notification.sms = ${str(rnode.metadata.get('icinga_options/vars.notification.sms', True)).lower()}
|
||||
vars.notification.mail = true
|
||||
}
|
||||
|
||||
% for depends_on_host in sorted(rnode.metadata.get('icinga_options/also_affected_by', set())):
|
||||
object Dependency "${rnode.name}_depends_on_${depends_on_host}" {
|
||||
parent_host_name = "${depends_on_host}"
|
||||
child_host_name = "${rnode.name}"
|
||||
states = [ Up ]
|
||||
disable_checks = true
|
||||
disable_notifications = true
|
||||
ignore_soft_states = true
|
||||
}
|
||||
% endfor
|
||||
|
||||
% for bundle, bconfig in sorted(rnode.metadata.get('icinga2_api', {}).items()):
|
||||
% for service, config in sorted(bconfig.get('services', {}).items()):
|
||||
object Service "${service}" {
|
||||
import "generic-service"
|
||||
host_name = "${rnode.name}"
|
||||
% if 'check_command' not in config:
|
||||
check_command = "sshmon"
|
||||
% endif
|
||||
% for k, v in sorted(config.items()):
|
||||
% if k not in {'import', 'command_on_monitored_host'} and not k.startswith('vars.notification'):
|
||||
% if isinstance(v, bool) or isinstance(v, int) or k.endswith('_interval'):
|
||||
${k} = ${str(v).lower()}
|
||||
% elif isinstance(v, list):
|
||||
${k} = [${", ".join(['"' + i + '"' for i in v])}]
|
||||
% else:
|
||||
${k} = "${v}"
|
||||
% endif
|
||||
% endif
|
||||
% endfor
|
||||
vars.bundle = "${bundle}"
|
||||
vars.notification.sms = ${str((config.get('vars.notification.sms', False) and rnode.metadata.get('icinga_options/vars.notification.sms', True))).lower()}
|
||||
vars.notification.mail = ${str(config.get('vars.notification.mail', False)).lower()}
|
||||
}
|
||||
% endfor
|
||||
% endfor
|
|
@ -1,22 +0,0 @@
|
|||
% for node_data, icingaconf in sorted(bundle_metadata.items()):
|
||||
% for service, config in sorted(icingaconf.items()):
|
||||
object Service "${service}" {
|
||||
import "generic-service"
|
||||
host_name = "${node_data.name}"
|
||||
% for k, v in sorted(config.items()):
|
||||
% if k not in {'import', 'command_on_monitored_host'} and not k.startswith('vars.notification'):
|
||||
% if isinstance(v, bool) or isinstance(v, int) or k in ["check_interval", "retry_interval"]:
|
||||
${k} = ${str(v).lower()}
|
||||
% elif isinstance(v, list):
|
||||
${k} = [${", ".join(['"' + i + '"' for i in v])}]
|
||||
% else:
|
||||
${k} = "${v}"
|
||||
% endif
|
||||
% endif
|
||||
% endfor
|
||||
vars.bundle = "${bundle_name}"
|
||||
vars.notification.sms = ${str(config.get('vars.notification.sms', False)).lower()}
|
||||
vars.notification.mail = ${str(config.get('vars.notification.mail', False)).lower()}
|
||||
}
|
||||
% endfor
|
||||
% endfor
|
Loading…
Add table
Add a link
Reference in a new issue