| 1 |
# Test code for win_eventlog_entry |
| 2 |
|
| 3 |
# (c) 2017, Andrew Saraceni <[email protected]> |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
- name: Add entry to fake log |
| 7 |
win_eventlog_entry: |
| 8 |
log: FakeLogName |
| 9 |
source: "{{ win_test_log_source.source }}" |
| 10 |
event_id: 12345 |
| 11 |
message: This is a test log entry message |
| 12 |
register: add_entry_to_fake_log |
| 13 |
failed_when: add_entry_to_fake_log.changed != false or add_entry_to_fake_log.msg != "Log FakeLogName does not exist and cannot be written to" |
| 14 |
|
| 15 |
|
| 16 |
- name: Add entry from fake source |
| 17 |
win_eventlog_entry: |
| 18 |
log: "{{ win_test_log_source.log }}" |
| 19 |
source: FakeSourceName |
| 20 |
event_id: 12345 |
| 21 |
message: This is a test log entry message |
| 22 |
register: add_entry_from_fake_source |
| 23 |
failed_when: add_entry_from_fake_source.changed != false or add_entry_from_fake_source.msg != "Source FakeSourceName does not exist" |
| 24 |
|
| 25 |
|
| 26 |
- name: Add entry with invalid event_id |
| 27 |
win_eventlog_entry: |
| 28 |
log: "{{ win_test_log_source.log }}" |
| 29 |
source: "{{ win_test_log_source.source }}" |
| 30 |
event_id: 67000 |
| 31 |
message: This is a test log entry message |
| 32 |
register: add_entry_with_invalid_event_id |
| 33 |
failed_when: add_entry_with_invalid_event_id.changed != false or add_entry_with_invalid_event_id.msg != "Event ID must be between 0 and 65535" |
| 34 |
|
| 35 |
|
| 36 |
- name: Add entry from other log source |
| 37 |
win_eventlog_entry: |
| 38 |
log: "{{ win_test_log_source.log }}" |
| 39 |
source: "{{ win_test_log_source_extra.source }}" |
| 40 |
event_id: 12345 |
| 41 |
message: This is a test log entry message |
| 42 |
register: add_entry_from_other_log_source |
| 43 |
failed_when: add_entry_from_other_log_source.changed != false or add_entry_from_other_log_source.msg != "Source {{ win_test_log_source_extra.source }} does not belong to log {{ win_test_log_source.log }} and cannot be written to" |
| 44 |
|
| 45 |
|
| 46 |
- name: Add entry |
| 47 |
win_eventlog_entry: &wele |
| 48 |
log: "{{ win_test_log_source.log }}" |
| 49 |
source: "{{ win_test_log_source.source }}" |
| 50 |
event_id: 12345 |
| 51 |
message: This is a test log entry message |
| 52 |
register: add_entry |
| 53 |
|
| 54 |
- name: Test add_entry |
| 55 |
assert: |
| 56 |
that: |
| 57 |
- add_entry.changed == true |
| 58 |
- add_entry.msg == "Entry added to log {{ win_test_log_source.log }} from source {{ win_test_log_source.source }}" |
| 59 |
|
| 60 |
- name: Test add_entry count (normal mode) |
| 61 |
ansible.windows.win_shell: (Get-EventLog -LogName "{{ win_test_log_source.log }}").Count |
| 62 |
register: add_entry_count |
| 63 |
failed_when: add_entry_count.stdout_lines[0] != "1" |
| 64 |
when: not in_check_mode |
| 65 |
|
| 66 |
- name: Test add_entry result (normal mode) |
| 67 |
test_win_eventlog_entry: |
| 68 |
log: "{{ win_test_log_source.log }}" |
| 69 |
register: add_entry_result |
| 70 |
when: not in_check_mode |
| 71 |
|
| 72 |
- name: Test add_entry_result (normal mode) |
| 73 |
assert: |
| 74 |
that: |
| 75 |
- add_entry_result.source == win_test_log_source.source |
| 76 |
- add_entry_result.event_id == 12345 |
| 77 |
- add_entry_result.message == "This is a test log entry message" |
| 78 |
when: not in_check_mode |
| 79 |
|
| 80 |
|
| 81 |
- name: Add entry (again) |
| 82 |
win_eventlog_entry: *wele |
| 83 |
register: add_entry_again |
| 84 |
|
| 85 |
- name: Test add_entry_again (normal mode) |
| 86 |
assert: |
| 87 |
that: |
| 88 |
- add_entry_again.changed == true |
| 89 |
- add_entry_again.msg == "Entry added to log {{ win_test_log_source.log }} from source {{ win_test_log_source.source }}" |
| 90 |
when: not in_check_mode |
| 91 |
|
| 92 |
- name: Test add_entry_again count (normal mode) |
| 93 |
ansible.windows.win_shell: (Get-EventLog -LogName "{{ win_test_log_source.log }}").Count |
| 94 |
register: add_entry_again_count |
| 95 |
failed_when: add_entry_again_count.stdout_lines[0] != "2" |
| 96 |
when: not in_check_mode |
| 97 |
|
| 98 |
|
| 99 |
- name: Add entry all options |
| 100 |
win_eventlog_entry: &wele_ao |
| 101 |
<<: *wele |
| 102 |
event_id: 500 |
| 103 |
message: This is a test error message |
| 104 |
entry_type: Error |
| 105 |
category: 5 |
| 106 |
raw_data: 10,20 |
| 107 |
register: add_entry_all_options |
| 108 |
|
| 109 |
- name: Test add_entry_all_options |
| 110 |
assert: |
| 111 |
that: |
| 112 |
- add_entry_all_options.changed == true |
| 113 |
- add_entry_all_options.msg == "Entry added to log {{ win_test_log_source.log }} from source {{ win_test_log_source.source }}" |
| 114 |
|
| 115 |
- name: Test add_entry_all_options count (normal mode) |
| 116 |
ansible.windows.win_shell: (Get-EventLog -LogName "{{ win_test_log_source.log }}").Count |
| 117 |
register: add_entry_all_options_count |
| 118 |
failed_when: add_entry_all_options_count.stdout_lines[0] != "3" |
| 119 |
when: not in_check_mode |
| 120 |
|
| 121 |
- name: Test add_entry_all_options result (normal mode) |
| 122 |
test_win_eventlog_entry: |
| 123 |
log: "{{ win_test_log_source.log }}" |
| 124 |
register: add_entry_all_options_result |
| 125 |
when: not in_check_mode |
| 126 |
|
| 127 |
- name: Test add_entry_all_options_result (normal mode) |
| 128 |
assert: |
| 129 |
that: |
| 130 |
- add_entry_all_options_result.source == win_test_log_source.source |
| 131 |
- add_entry_all_options_result.event_id == 500 |
| 132 |
- add_entry_all_options_result.message == "This is a test error message" |
| 133 |
- add_entry_all_options_result.entry_type == "Error" |
| 134 |
- add_entry_all_options_result.category == 5 |
| 135 |
- add_entry_all_options_result.raw_data == "10,20" |
| 136 |
when: not in_check_mode |
| 137 |
|
| 138 |
|
| 139 |
- name: Add entry all options (again) |
| 140 |
win_eventlog_entry: *wele_ao |
| 141 |
register: add_entry_all_options_again |
| 142 |
|
| 143 |
- name: Test add_entry_all_options_again (normal mode) |
| 144 |
assert: |
| 145 |
that: |
| 146 |
- add_entry_all_options_again.changed == true |
| 147 |
- add_entry_all_options_again.msg == "Entry added to log {{ win_test_log_source.log }} from source {{ win_test_log_source.source }}" |
| 148 |
when: not in_check_mode |
| 149 |
|
| 150 |
- name: Test add_entry_all_options_again count (normal mode) |
| 151 |
ansible.windows.win_shell: (Get-EventLog -LogName "{{ win_test_log_source.log }}").Count |
| 152 |
register: add_entry_all_options_again_count |
| 153 |
failed_when: add_entry_all_options_again_count.stdout_lines[0] != "4" |
| 154 |
when: not in_check_mode |
| 155 |
|
| 156 |
|
| 157 |
- name: Clear event log entries |
| 158 |
ansible.windows.win_shell: Clear-EventLog -LogName "{{ win_test_log_source.log }}" |
| 159 |
when: not in_check_mode |