Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add object and feature for PerfdataWriter #68

Merged
merged 9 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Collection to setup and manage components of the Icinga software stack.
* [Feature InfluxDB2](doc/features/feature-influxdb2.md)
* [Feature mainlog](doc/features/feature-mainlog.md)
* [Feature notification](doc/features/feature-notification.md)
* [Feature perfdata](doc/features/feature-perfdata.md)



Expand Down
42 changes: 42 additions & 0 deletions doc/features/feature-perfdata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## PerfdataWriter

To enable the feature perfdata use the following block in the variable `icinga2_features`.

**INFO** For detailed information and instructions see the Icinga 2 Docs. [Feature PerfdataWriter](https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#perfdatabwriter)

```
icinga2_features:
- name: perfdata
host_perfdata_path: "/var/spool/icinga2/perfdata/host-perfdata"
service_perfdata_path: "/var/spool/icinga2/perfdata/service-perfdata"
host_format_template: "DATATYPE::HOSTPERFDATA"
service_format_template: "DATATYPE::SERVICEPERFDATA"
rotation_interval = 15s
```

### Feature variables

* `host_perfdata_path: string`
* Path to the host performance data file. Defaults to SpoolDir + “/perfdata/host-perfdata”.

* `service_perfdata_path: string`
* Path to the service performance data file. Defaults to SpoolDir + “/perfdata/service-perfdata”.

* `host_temp_path: string`
* Path to the temporary host file. Defaults to SpoolDir + “/tmp/host-perfdata”.

* `service_temp_path: string`
* Path to the temporary service file. Defaults to SpoolDir + “/tmp/service-perfdata”.

* `host_format_template: string`
* Host Format template for the performance data file. Defaults to a template that’s suitable for use with PNP4Nagios.

* `service_format_template: string`
* Service Format template for the performance data file. Defaults to a template that’s suitable for use with PNP4Nagios.

* `rotation_interval: string`
* Rotation interval for the files specified in {host,service}_perfdata_path. Defaults to 30s.

* `enable_ha: boolean`
* Enable the high availability functionality. Only valid in a cluster setup. Defaults to false.

3 changes: 3 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
vars:
icinga2_confd: false
icinga2_features:
- name: perfdata
host_perfdata_path: "/var/spool/icinga2/perfdata/host-perfdata"
service_perfdata_path: "/var/spool/icinga2/perfdata/service-perfdata"
- name: gelf
host: localhost
port: 12201
Expand Down
13 changes: 13 additions & 0 deletions molecule/default/tests/integration/test_icinga2.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,16 @@ def test_icinga2_feature_gelf(host):
if host.system_info.distribution == 'debian':
assert i2_file.user == "nagios"
assert i2_file.group == "nagios"

def test_icinga2_feature_perfdata(host):
i2_file = host.file("/etc/icinga2/features-available/perfdata.conf")
i2_link = host.file("/etc/icinga2/features-enabled/perfdata.conf")
assert i2_file.exists
assert i2_file.contains('object PerfdataWriter "perfdata" {')
assert i2_link.linked_to == "/etc/icinga2/features-available/perfdata.conf"
if host.system_info.distribution == 'centos':
assert i2_file.user == "icinga"
assert i2_file.group == "icinga"
if host.system_info.distribution == 'debian':
assert i2_file.user == "nagios"
assert i2_file.group == "nagios"
34 changes: 34 additions & 0 deletions plugins/modules/icinga2_perfdatawriter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/python


from ansible.module_utils.basic import AnsibleModule

def main():
module = AnsibleModule(
supports_check_mode=True,
argument_spec = dict(
state = dict(default='present', choices=['present', 'absent']),
name = dict(required=True),
order = dict(default=10, type='int'),
file = dict(default='features-available/perfdata.conf', type='str'),
host_perfdata_path = dict(type='str'),
service_perfdata_path = dict(type='str'),
host_temp_path = dict(type='str'),
service_temp_path = dict(type='str'),
host_format_template = dict(type='str'),
service_format_template = dict(type='str'),
rotation_interval = dict(type='str'),
enable_ha = dict(type='bool'),
)
)

args = module.params
name = args.pop('name')
order = args.pop('order')
state = args.pop('state')
file = args.pop('file')

module.exit_json(changed=False, args=args, name=name, order=str(order), state=state, file=file)

if __name__ == '__main__':
main()
12 changes: 12 additions & 0 deletions roles/icinga2/tasks/features/perfdata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

- name: feature perfdata PerfdataWriter object
icinga2_object:
name: perfdata
type: PerfdataWriter
file: features-available/perfdata.conf
args: "{{ icinga2_dict_features.perfdata }}"
register: result

- set_fact:
icinga2_local_objects: "{{ icinga2_local_objects|default([]) + [result.dest] }}"
1 change: 1 addition & 0 deletions roles/icinga2/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ icinga2_object_types:
- NotificationCommand
- NotificationComponent
- OpenTsdbWriter
- PerfdataWriter
- ScheduledDowntime
- Service
- ServiceGroup
Expand Down