|
19 | 19 | import pytest |
20 | 20 | import sys |
21 | 21 | import tempfile |
| 22 | +from scalyr_agent.builtin_monitors.windows_event_log_monitor import NewJsonApi |
22 | 23 |
|
23 | | -if sys.platform == "Windows": |
| 24 | +if sys.platform == "win32": |
24 | 25 | import scalyr_agent.builtin_monitors.windows_event_log_monitor |
25 | 26 | from scalyr_agent.builtin_monitors.windows_event_log_monitor import ( |
26 | 27 | WindowEventLogMonitor, |
|
37 | 38 | def _get_parameter_msg_fixture_path(): |
38 | 39 | # TODO Document how the test dll is created |
39 | 40 | return os.path.join( |
40 | | - os.path.dirname(os.path.dirname(__file__)), |
| 41 | + os.path.dirname(os.path.dirname(os.path.dirname(__file__))), |
41 | 42 | "fixtures", |
42 | 43 | "parametermsgfixture.dll", |
43 | 44 | ) |
44 | 45 |
|
45 | 46 |
|
46 | 47 | @pytest.mark.windows_platform |
47 | 48 | class WindowsEventLogMonitorTest(ScalyrTestCase): |
48 | | - @skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform") |
| 49 | + @skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform") |
49 | 50 | def test_emit_warning_on_maximum_records_per_source_config_option_new_api(self): |
50 | 51 | monitor_config = { |
51 | 52 | "module": "windows_event_log_monitor", |
@@ -105,7 +106,7 @@ def test_emit_warning_on_maximum_records_per_source_config_option_new_api(self): |
105 | 106 | "affect when using new evt API." |
106 | 107 | ) |
107 | 108 |
|
108 | | - @skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform") |
| 109 | + @skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform") |
109 | 110 | def test_newjsonapi_backwards_compatible(self): |
110 | 111 | monitor_config = { |
111 | 112 | "module": "windows_event_log_monitor", |
@@ -133,7 +134,7 @@ def test_newjsonapi_backwards_compatible(self): |
133 | 134 | ) |
134 | 135 | ) |
135 | 136 |
|
136 | | - @skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform") |
| 137 | + @skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform") |
137 | 138 | def test_convert_json_array_to_object(self): |
138 | 139 | self.assertEqual( |
139 | 140 | scalyr_agent.builtin_monitors.windows_event_log_monitor._convert_json_array_to_object( |
@@ -195,7 +196,7 @@ def test_convert_json_array_to_object(self): |
195 | 196 | {"n": {"a": 1}, "n2": {"b": 2}, "2": {"c": 3, "@Name": "n"}}, |
196 | 197 | ) |
197 | 198 |
|
198 | | - @skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform") |
| 199 | + @skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform") |
199 | 200 | def test_strip_xmltodict_prefixes(self): |
200 | 201 | self.assertEqual( |
201 | 202 | scalyr_agent.builtin_monitors.windows_event_log_monitor._strip_xmltodict_prefixes( |
@@ -239,23 +240,24 @@ def test_strip_xmltodict_prefixes(self): |
239 | 240 | [{"a": "a", "Text": "t"}], |
240 | 241 | ) |
241 | 242 |
|
242 | | - @skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform") |
| 243 | + @skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform") |
243 | 244 | @mock.patch( |
244 | 245 | "scalyr_agent.builtin_monitors.windows_event_log_monitor._DLL.dllpath", |
245 | 246 | return_value=_get_parameter_msg_fixture_path(), |
246 | 247 | ) |
247 | 248 | def test_replace_param_placeholders(self, *args): |
248 | 249 | # pylint: disable=no-member |
249 | | - monitor_config = { |
250 | | - "module": "windows_event_log_monitor", |
251 | | - "sources": "Application, Security, System", |
252 | | - "event_types": "All", |
253 | | - "json": True, |
| 250 | + json_api_config = { |
| 251 | + "dll_handle_cache_size": 100, |
| 252 | + "dll_handle_cache_ttl": 100, |
| 253 | + "placeholder_param_cache_size": 100, |
| 254 | + "placeholder_param_cache_ttl": 100, |
| 255 | + "placeholder_render": True |
254 | 256 | } |
255 | 257 | scalyr_agent.builtin_monitors.windows_event_log_monitor.windll = mock.Mock() |
256 | 258 | mock_logger = mock.Mock() |
257 | 259 |
|
258 | | - monitor = WindowEventLogMonitor(monitor_config, mock_logger) |
| 260 | + json_api = NewJsonApi(json_api_config, mock_logger, None) |
259 | 261 | test_events = [ |
260 | 262 | { |
261 | 263 | "Event": { |
@@ -283,43 +285,44 @@ def test_replace_param_placeholders(self, *args): |
283 | 285 | }, |
284 | 286 | ] |
285 | 287 |
|
286 | | - result = monitor._replace_param_placeholders(test_events[0]) |
| 288 | + result = json_api._replace_param_placeholders(test_events[0]) |
287 | 289 | self.assertEqual(result["Event"]["EventData"]["Data"], "blarg") |
288 | 290 |
|
289 | | - result = monitor._replace_param_placeholders(test_events[1]) |
| 291 | + result = json_api._replace_param_placeholders(test_events[1]) |
290 | 292 | self.assertEqual(result["Event"]["EventData"]["Data"]["One"], "honk") |
291 | 293 | self.assertEqual(result["Event"]["EventData"]["Data"]["Two"]["Text"], "rawr") |
292 | 294 | self.assertEqual(result["Event"]["EventData"]["Data"]["Three"]["Text"], "Nice") |
293 | 295 |
|
294 | | - @skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform") |
| 296 | + @skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform") |
295 | 297 | @mock.patch( |
296 | 298 | "scalyr_agent.builtin_monitors.windows_event_log_monitor._DLL.dllpath", |
297 | 299 | return_value=_get_parameter_msg_fixture_path(), |
298 | 300 | ) |
299 | 301 | def test_param_placeholder_value_resolution(self, *args): |
300 | 302 | # pylint: disable=no-member |
301 | | - monitor_config = { |
302 | | - "module": "windows_event_log_monitor", |
303 | | - "sources": "Application, Security, System", |
304 | | - "event_types": "All", |
305 | | - "json": True, |
| 303 | + json_api_config = { |
| 304 | + "dll_handle_cache_size": 100, |
| 305 | + "dll_handle_cache_ttl": 100, |
| 306 | + "placeholder_param_cache_size": 100, |
| 307 | + "placeholder_param_cache_ttl": 100, |
| 308 | + "placeholder_render": True |
306 | 309 | } |
307 | 310 | scalyr_agent.builtin_monitors.windows_event_log_monitor.windll = mock.Mock() |
308 | 311 | mock_logger = mock.Mock() |
309 | 312 |
|
310 | | - monitor = WindowEventLogMonitor(monitor_config, mock_logger) |
311 | | - value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%392") |
| 313 | + json_api = NewJsonApi(json_api_config, mock_logger, None) |
| 314 | + value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%392") |
312 | 315 | self.assertEqual(value, "blarg") |
313 | | - value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%553") |
| 316 | + value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%553") |
314 | 317 | self.assertEqual(value, "honk") |
315 | | - value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%990") |
| 318 | + value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%990") |
316 | 319 | self.assertEqual(value, "rawr") |
317 | | - value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%69") |
| 320 | + value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%69") |
318 | 321 | self.assertEqual(value, "Nice") |
319 | | - value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%1111") |
| 322 | + value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%1111") |
320 | 323 | self.assertEqual(value, "all your base are belong to us") |
321 | 324 |
|
322 | | - @skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform") |
| 325 | + @skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform") |
323 | 326 | def test_parameter_msg_file_location_lookup(self): |
324 | 327 | msgDLL = _get_parameter_msg_fixture_path() |
325 | 328 | channel = "Application" |
|
0 commit comments