Skip to content

Commit c64a077

Browse files
committed
Add object and feature for CompatLogger
1 parent 278cb43 commit c64a077

File tree

7 files changed

+179
-0
lines changed

7 files changed

+179
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- Add object :code:`CompatLogger` and feature :code:`compatlog`.

doc/role-icinga2/features.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Current supported features:
1111

1212
* [Feature API](features/feature-api.md)
1313
* [Feature Command](features/feature-command.md)
14+
* [Feature CompatLog](features/feature-compatlog.md)
1415
* [Feature ElasticSearch](features/feature-elasticsearch.md)
1516
* [Feature GelfWriter](features/feature-gelf.md)
1617
* [Feature Graphite](features/feature-graphite.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## CompatLog
2+
3+
To enable the feature compatlog use the following block in the variable `icinga2_features`.
4+
5+
**INFO** For detailed information and instructions see the Icinga 2 Docs. [Feature CompatLog](https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#compatlogger)
6+
7+
```
8+
icinga2_features:
9+
- name: compatlog
10+
state: present
11+
log_dir: "LogDir + /compat"
12+
rotation_method: "monthly"
13+
```
14+
15+
### Feature variables
16+
17+
* `state: string`
18+
* Enable or disable feature. Options: present, absent
19+
* `log_dir: string`
20+
* Set the log directory.
21+
* `rotation_method: string`
22+
* Set the log rotation interval. Options: hourly, daily, weekly, monthly

doc/role-icinga2/objects.md

+12
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,18 @@ icinga2_objects:
535535
set_if: $http_ssl$
536536
```
537537
538+
#### CompatLogger
539+
540+
```yaml
541+
icinga2_objects:
542+
[...]
543+
- name: mycompatlogger
544+
type: CompatLogger
545+
file: "local.d/complog.conf"
546+
log_dir: "LogDir + /custom_complog"
547+
rotation_method: "hourly"
548+
```
549+
538550
#### Dependency
539551
540552
```
+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
from ansible.module_utils.basic import AnsibleModule
2+
3+
DOCUMENTATION = '''
4+
name: icinga2_compatlogger
5+
short_description: Creates information for CompatLogger object.
6+
description:
7+
- Returns information used to create a CompatLogger object.
8+
version_added: 0.4.0
9+
author:
10+
- Matthias Döhler <[email protected]>
11+
options:
12+
name:
13+
description:
14+
- The name of the CompatLogger object.
15+
required: true
16+
type: str
17+
state:
18+
description:
19+
- The state of the CompatLogger object.
20+
required: false
21+
default: present
22+
choices: [ "present", "absent" ]
23+
type: str
24+
order:
25+
description:
26+
- Value to determine internal precedence.
27+
required: false
28+
default: 10
29+
type: int
30+
file:
31+
description:
32+
- Path to the file in which the object will be defined.
33+
required: true
34+
default: "features-available/compatlog.conf"
35+
type: str
36+
log_dir:
37+
description:
38+
- Path to the compat log directory.
39+
required: false
40+
type: str
41+
rotation_method:
42+
description:
43+
- Specifies when to rotate log files.
44+
required: false
45+
choices: [ "hourly", "daily", "weekly", "monthly" ]
46+
type: str
47+
'''
48+
49+
EXAMPLES = '''
50+
icinga.icinga.icinga2_compatlogger:
51+
name: "mycompatlogger"
52+
log_dir: "LogDir + /compat"
53+
rotation_method: "monthly"
54+
'''
55+
56+
RETURN = '''
57+
args:
58+
description: Arguments used to create the CompatLogger object.
59+
returned: success
60+
type: dict
61+
contains:
62+
log_dir:
63+
description: The specified log directory.
64+
returned: success
65+
type: str
66+
sample: "LogDir + /compat"
67+
rotation_method:
68+
description: The specified rotation method.
69+
returned: success
70+
type: str
71+
sample: "MONTHLY"
72+
file:
73+
description: Path to the file that will contain the object.
74+
returned: success
75+
type: str
76+
sample: features-available/compatlog.conf
77+
name:
78+
description: The name of the CompatLogger object.
79+
returned: success
80+
type: str
81+
sample: mycompatlogger
82+
order:
83+
description: The order value of this object. Used internally when combining multiple templates / objects.
84+
returned: success
85+
type: int
86+
sample: 10
87+
state:
88+
description: The chosen state for the object.
89+
returned: success
90+
type: str
91+
sample: present
92+
'''
93+
94+
def main():
95+
module = AnsibleModule(
96+
supports_check_mode=True,
97+
argument_spec=dict(
98+
state=dict(default='present', choices=['present', 'absent']),
99+
name=dict(required=True),
100+
order=dict(default=10, type='int'),
101+
file=dict(default='features-available/compatlog.conf', type='str'),
102+
log_dir=dict(type='str'),
103+
rotation_method=dict(type='str', choices=['hourly', 'daily', 'weekly', 'monthly']),
104+
)
105+
)
106+
107+
args = module.params
108+
name = args.pop('name')
109+
order = args.pop('order')
110+
state = args.pop('state')
111+
file = args.pop('file')
112+
113+
# Capslock if rotation_method is set
114+
if args.get('rotation_method', None):
115+
args.update({'rotation_method': args.get('rotation_method').upper()})
116+
117+
module.exit_json(
118+
changed=False,
119+
args=args,
120+
name=name,
121+
order=str(order),
122+
state=state,
123+
file=file,
124+
)
125+
126+
127+
if __name__ == '__main__':
128+
main()
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
3+
- name: Feature compatlog CompatLogger object
4+
icinga.icinga.icinga2_object:
5+
name: compatlog
6+
type: CompatLogger
7+
file: features-available/compatlog.conf
8+
args: "{{ icinga2_dict_features.compatlog }}"
9+
register: result
10+
11+
- set_fact:
12+
icinga2_local_objects: "{{ icinga2_local_objects|default([]) + [result.dest] }}"

roles/icinga2/vars/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ icinga2_object_types:
7777
- ApiUser
7878
- CheckCommand
7979
- CheckerComponent
80+
- CompatLogger
8081
- Dependency
8182
- ElasticsearchWriter
8283
- Endpoint

0 commit comments

Comments
 (0)