-
Problem report
-
Resolution: Fixed
-
Trivial
-
6.0.0alpha4
-
Sprint 80 (Sep 2021), Sprint 81 (Oct 2021)
-
0.3
Problem description: in the current audit log implementation there are some script execution errors that are logged into audit log and some that are not. From the end user point of view it doesn't matter what type of error was obtained from the server, it should be written to audit log.
Steps to reproduce:
- Create a webhook script using the following API:
{ "jsonrpc": "2.0", "method": "script.create", "params": { "name": "Webhook script TEST", "command": "try {\n var request = new HttpRequest(),\n response,\n data;\n\n request.addHeader('Content-Type: application/json');\n\n response = request.post('https://localhost/post', value);\n\n try {\n response = JSON.parse(response);\n }\n catch (error) {\n response = null;\n }\n\n if (request.getStatus() !== 200 || !('data' in response)) {\n throw 'Unexpected response.';\n }\n\n data = JSON.stringify(response.data);\n\n Zabbix.Log(3, '[Webhook Script] response data: ' + data);\n\n return data;\n}\ncatch (error) {\n Zabbix.Log(3, '[Webhook Script] script execution failed: ' + error);\n throw 'Execution failed: ' + error + '.';\n}", "type": 5, "timeout": "40s", "scope": 2, "parameters": [ { "name": "token", "value": "ecca1daf21e2eb9518ee970cb32bef4d" }, { "name": "host", "value": "{HOST.HOST}" }, { "name": "v", "value": "2.2" } ] }, "auth": "ecca1daf21e2eb9518ee970cb32bef4d", "id": 1 }
- Start zabbix server
- Navigate to Monitoring => Hosts
- Attempt to execute the created script for Zabbix server - the following error is returned:
"cannot execute script: Execution failed: Error: cannot get URL: Couldn't connect to server.."
- Check zabbix server log and acknowledge that the same error is observed there
4083430:20210928:122746.652 [Webhook Script] script execution failed: Error: cannot get URL: Couldn't connect to server. 4083430:20210928:122746.653 [Z3005] query failed: [0] PGRES_FATAL_ERROR:ERROR: syntax error at or near "t" LINE 1: ...: Execution failed: Error: cannot get URL: Couldn't connect ... ^ [insert into auditlog (auditid,userid,username,clock,action,ip,resourceid,resourcename,resourcetype,recordsetid,details) values ('cku3vmgnx0002sm7p1l2a7py4',1,'Admin',1632821266,'7','::1',10084,'Zabbix server',25,'cku3vmgnx0002sm7p1l2a7py4','{"script.execute_on":["add","0"],"script.hostid":["add","10084"],"script.error":["add","cannot execute script: Execution failed: Error: cannot get URL: Couldn't connect to server.."]}')]
- Check audit log
Result:
The is no script execution record in audit log.
Expected:
1 - Failed script execution attempt should be recorded.
2 - The error message shouldn't have 2 dots in the end