| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
"""Splunk Data Inputs Monitor resource module.""" |
| 4 |
|
| 5 |
# Copyright 2022 Red Hat |
| 6 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
|
| 8 |
DOCUMENTATION = """ |
| 9 |
--- |
| 10 |
module: splunk_data_inputs_monitor |
| 11 |
short_description: Splunk Data Inputs of type Monitor resource module |
| 12 |
description: |
| 13 |
- Module to add/modify or delete, File and Directory Monitor Data Inputs in Splunk. |
| 14 |
- Tested against Splunk Enterprise Server 8.2.3 |
| 15 |
version_added: "2.1.0" |
| 16 |
options: |
| 17 |
config: |
| 18 |
description: |
| 19 |
- Configure file and directory monitoring on the system |
| 20 |
type: list |
| 21 |
elements: dict |
| 22 |
suboptions: |
| 23 |
name: |
| 24 |
description: |
| 25 |
- The file or directory path to monitor on the system. |
| 26 |
required: true |
| 27 |
type: str |
| 28 |
blacklist: |
| 29 |
description: |
| 30 |
- Specify a regular expression for a file path. The file path that matches this regular expression is not indexed. |
| 31 |
type: str |
| 32 |
check_index: |
| 33 |
description: |
| 34 |
- If set to C(true), the index value is checked to ensure that it is the name of a valid index. |
| 35 |
- This parameter is not returned back by Splunk while obtaining object information. |
| 36 |
It is therefore left out while performing idempotency checks |
| 37 |
type: bool |
| 38 |
check_path: |
| 39 |
description: |
| 40 |
- If set to C(true), the name value is checked to ensure that it exists. |
| 41 |
- This parameter is not returned back by Splunk while obtaining object information. |
| 42 |
It is therefore left out while performing idempotency checks |
| 43 |
type: bool |
| 44 |
crc_salt: |
| 45 |
description: |
| 46 |
- A string that modifies the file tracking identity for files in this input. |
| 47 |
The magic value <SOURCE> invokes special behavior (see admin documentation). |
| 48 |
type: str |
| 49 |
disabled: |
| 50 |
description: |
| 51 |
- Indicates if input monitoring is disabled. |
| 52 |
type: bool |
| 53 |
default: false |
| 54 |
follow_tail: |
| 55 |
description: |
| 56 |
- If set to C(true), files that are seen for the first time is read from the end. |
| 57 |
type: bool |
| 58 |
host: |
| 59 |
description: |
| 60 |
- The value to populate in the host field for events from this data input. |
| 61 |
type: str |
| 62 |
default: "$decideOnStartup" |
| 63 |
host_regex: |
| 64 |
description: |
| 65 |
- Specify a regular expression for a file path. If the path for a file |
| 66 |
matches this regular expression, the captured value is used to populate |
| 67 |
the host field for events from this data input. The regular expression |
| 68 |
must have one capture group. |
| 69 |
type: str |
| 70 |
host_segment: |
| 71 |
description: |
| 72 |
- Use the specified slash-separate segment of the filepath as the host field value. |
| 73 |
type: int |
| 74 |
ignore_older_than: |
| 75 |
description: |
| 76 |
- Specify a time value. If the modification time of a file being monitored |
| 77 |
falls outside of this rolling time window, the file is no longer being monitored. |
| 78 |
- This parameter is not returned back by Splunk while obtaining object information. |
| 79 |
It is therefore left out while performing idempotency checks |
| 80 |
type: str |
| 81 |
index: |
| 82 |
description: |
| 83 |
- Which index events from this input should be stored in. Defaults to default. |
| 84 |
type: str |
| 85 |
default: "default" |
| 86 |
recursive: |
| 87 |
description: |
| 88 |
- Setting this to False prevents monitoring of any subdirectories encountered within this data input. |
| 89 |
type: bool |
| 90 |
rename_source: |
| 91 |
description: |
| 92 |
- The value to populate in the source field for events from this data input. |
| 93 |
The same source should not be used for multiple data inputs. |
| 94 |
- This parameter is not returned back by Splunk while obtaining object information. |
| 95 |
It is therefore left out while performing idempotency checks |
| 96 |
type: str |
| 97 |
sourcetype: |
| 98 |
description: |
| 99 |
- The value to populate in the sourcetype field for incoming events. |
| 100 |
type: str |
| 101 |
time_before_close: |
| 102 |
description: |
| 103 |
- When Splunk software reaches the end of a file that is being read, the |
| 104 |
file is kept open for a minimum of the number of seconds specified in |
| 105 |
this value. After this period has elapsed, the file is checked again for |
| 106 |
more data. |
| 107 |
- This parameter is not returned back by Splunk while obtaining object information. |
| 108 |
It is therefore left out while performing idempotency checks |
| 109 |
type: int |
| 110 |
whitelist: |
| 111 |
description: |
| 112 |
- Specify a regular expression for a file path. Only file paths that match this regular expression are indexed. |
| 113 |
type: str |
| 114 |
|
| 115 |
running_config: |
| 116 |
description: |
| 117 |
- The module, by default, will connect to the remote device and retrieve the current |
| 118 |
running-config to use as a base for comparing against the contents of source. |
| 119 |
There are times when it is not desirable to have the task get the current running-config |
| 120 |
for every task in a playbook. The I(running_config) argument allows the implementer |
| 121 |
to pass in the configuration to use as the base config for comparison. This |
| 122 |
value of this option should be the output received from device by executing |
| 123 |
command. |
| 124 |
type: str |
| 125 |
state: |
| 126 |
description: |
| 127 |
- The state the configuration should be left in |
| 128 |
type: str |
| 129 |
choices: |
| 130 |
- merged |
| 131 |
- replaced |
| 132 |
- deleted |
| 133 |
- gathered |
| 134 |
default: merged |
| 135 |
|
| 136 |
author: Ansible Security Automation Team (@pranav-bhatt) <https://github.com/ansible-security> |
| 137 |
""" |
| 138 |
|
| 139 |
EXAMPLES = """ |
| 140 |
|
| 141 |
# Using gathered |
| 142 |
# -------------- |
| 143 |
|
| 144 |
- name: Gather config for specified Data inputs monitors |
| 145 |
splunk.es.splunk_data_inputs_monitor: |
| 146 |
config: |
| 147 |
- name: "/var/log" |
| 148 |
- name: "/var" |
| 149 |
state: gathered |
| 150 |
|
| 151 |
# RUN output: |
| 152 |
# ----------- |
| 153 |
|
| 154 |
# "gathered": [ |
| 155 |
# { |
| 156 |
# "blacklist": "//var/log/[a-z0-9]/gm", |
| 157 |
# "crc_salt": "<SOURCE>", |
| 158 |
# "disabled": false, |
| 159 |
# "host": "$decideOnStartup", |
| 160 |
# "host_regex": "/(test_host)/gm", |
| 161 |
# "host_segment": 3, |
| 162 |
# "index": "default", |
| 163 |
# "name": "/var/log", |
| 164 |
# "recursive": true, |
| 165 |
# "sourcetype": "test_source", |
| 166 |
# "whitelist": "//var/log/[0-9]/gm" |
| 167 |
# } |
| 168 |
# ] |
| 169 |
# |
| 170 |
|
| 171 |
# Using merged |
| 172 |
# ------------ |
| 173 |
|
| 174 |
- name: Update Data inputs monitors config |
| 175 |
splunk.es.splunk_data_inputs_monitor: |
| 176 |
config: |
| 177 |
- name: "/var/log" |
| 178 |
blacklist: "//var/log/[a-z]/gm" |
| 179 |
check_index: true |
| 180 |
check_path: true |
| 181 |
crc_salt: <SOURCE> |
| 182 |
rename_source: "test" |
| 183 |
whitelist: "//var/log/[0-9]/gm" |
| 184 |
state: merged |
| 185 |
|
| 186 |
# RUN output: |
| 187 |
# ----------- |
| 188 |
|
| 189 |
# "after": [ |
| 190 |
# { |
| 191 |
# "blacklist": "//var/log/[a-z]/gm", |
| 192 |
# "crc_salt": "<SOURCE>", |
| 193 |
# "disabled": false, |
| 194 |
# "host": "$decideOnStartup", |
| 195 |
# "host_regex": "/(test_host)/gm", |
| 196 |
# "host_segment": 3, |
| 197 |
# "index": "default", |
| 198 |
# "name": "/var/log", |
| 199 |
# "recursive": true, |
| 200 |
# "sourcetype": "test_source", |
| 201 |
# "whitelist": "//var/log/[0-9]/gm" |
| 202 |
# } |
| 203 |
# ], |
| 204 |
# "before": [ |
| 205 |
# { |
| 206 |
# "blacklist": "//var/log/[a-z0-9]/gm", |
| 207 |
# "crc_salt": "<SOURCE>", |
| 208 |
# "disabled": false, |
| 209 |
# "host": "$decideOnStartup", |
| 210 |
# "host_regex": "/(test_host)/gm", |
| 211 |
# "host_segment": 3, |
| 212 |
# "index": "default", |
| 213 |
# "name": "/var/log", |
| 214 |
# "recursive": true, |
| 215 |
# "sourcetype": "test_source", |
| 216 |
# "whitelist": "//var/log/[0-9]/gm" |
| 217 |
# } |
| 218 |
# ], |
| 219 |
|
| 220 |
# Using replaced |
| 221 |
# -------------- |
| 222 |
|
| 223 |
- name: To Replace Data inputs monitors config |
| 224 |
splunk.es.splunk_data_inputs_monitor: |
| 225 |
config: |
| 226 |
- name: "/var/log" |
| 227 |
blacklist: "//var/log/[a-z0-9]/gm" |
| 228 |
crc_salt: <SOURCE> |
| 229 |
index: default |
| 230 |
state: replaced |
| 231 |
|
| 232 |
# RUN output: |
| 233 |
# ----------- |
| 234 |
|
| 235 |
# "after": [ |
| 236 |
# { |
| 237 |
# "blacklist": "//var/log/[a-z0-9]/gm", |
| 238 |
# "crc_salt": "<SOURCE>", |
| 239 |
# "disabled": false, |
| 240 |
# "host": "$decideOnStartup", |
| 241 |
# "index": "default", |
| 242 |
# "name": "/var/log" |
| 243 |
# } |
| 244 |
# ], |
| 245 |
# "before": [ |
| 246 |
# { |
| 247 |
# "blacklist": "//var/log/[a-z0-9]/gm", |
| 248 |
# "crc_salt": "<SOURCE>", |
| 249 |
# "disabled": false, |
| 250 |
# "host": "$decideOnStartup", |
| 251 |
# "host_regex": "/(test_host)/gm", |
| 252 |
# "host_segment": 3, |
| 253 |
# "index": "default", |
| 254 |
# "name": "/var/log", |
| 255 |
# "recursive": true, |
| 256 |
# "sourcetype": "test_source", |
| 257 |
# "whitelist": "//var/log/[0-9]/gm" |
| 258 |
# } |
| 259 |
# ], |
| 260 |
|
| 261 |
# Using deleted |
| 262 |
# ----------- |
| 263 |
- name: To Delete Data inpur monitor config |
| 264 |
splunk.es.splunk_data_inputs_monitor: |
| 265 |
config: |
| 266 |
- name: "/var/log" |
| 267 |
state: deleted |
| 268 |
|
| 269 |
# RUN output: |
| 270 |
# ----------- |
| 271 |
# |
| 272 |
# "after": [], |
| 273 |
# "before": [ |
| 274 |
# { |
| 275 |
# "blacklist": "//var/log/[a-z0-9]/gm", |
| 276 |
# "crc_salt": "<SOURCE>", |
| 277 |
# "disabled": false, |
| 278 |
# "host": "$decideOnStartup", |
| 279 |
# "index": "default", |
| 280 |
# "name": "/var/log" |
| 281 |
# } |
| 282 |
# ], |
| 283 |
""" |
| 284 |
|
| 285 |
RETURN = """ |
| 286 |
before: |
| 287 |
description: The configuration as structured data prior to module invocation. |
| 288 |
returned: always |
| 289 |
type: list |
| 290 |
sample: The configuration returned will always be in the same format of the parameters above. |
| 291 |
after: |
| 292 |
description: The configuration as structured data after module completion. |
| 293 |
returned: when changed |
| 294 |
type: list |
| 295 |
sample: The configuration returned will always be in the same format of the parameters above. |
| 296 |
""" |