[ZBXNEXT-2163] Argument support for script media type Created: 2014 Feb 18 Updated: 2018 Jan 17 Resolved: 2015 Dec 14 |
|
Status: | Closed |
Project: | ZABBIX FEATURE REQUESTS |
Component/s: | Frontend (F), Server (S) |
Affects Version/s: | 2.2.1 |
Fix Version/s: | 3.0.0alpha3 |
Type: | Change Request | Priority: | Minor |
Reporter: | Ryan Armstrong | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 1 |
Labels: | alertscript, mediatypes | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Issue Links: |
|
Description |
When defining a new custom Script Media Type, command arguments cannot be passed in the 'Script name' field. A 'file not found' error is generated in the Actions audit log as the Zabbix server attempts to validate the file path of the script, including the arguments as a part of the path. The use case for us would be to generate tickets in our ticket system of varying priorities using a single script. Eg. we would have two media types, 'P1 Incident' and 'P2 Incident' using the same script with different command arguments ('script.pl --priority 1', 'script.pl --priority 2'). We identified a potential fix around line 92 of 'alerter.c' in source for 2.2.1. Before calling 'access (cmd, X_OK)' to validate the command path, call 'cmd=basename(cmd)' to strip out the command args. Specification: https://www.zabbix.org/wiki/Docs/specs/ZBXNEXT-2163 |
Comments |
Comment by richlv [ 2014 Feb 18 ] |
as per the documentation, 3 parameters are passed to the script. that includes message subject & body, where you can use various variables (or just hardcode strings). https://www.zabbix.com/documentation/2.2/manual/config/notifications/media/script |
Comment by Ryan Armstrong [ 2014 Feb 18 ] |
Thanks for your reply richlv. Yes I'm aware of the three default parameters passed to the alert script. As you state, we can hard code this into the body of the alert and have our script strip them out, but we will have a large number of users who should not have to ensure the syntactical integrity of their alert message bodies. With what I consider a small change, we could then define a script as 'my_script.pl --priority 3 --assignee Wintel' and prevent these extra variables being required in the message body. This way they are managed and provisioned to end users by the Zabbix app team here. As a workaround, we are currently creating 'wrapper' scripts which require only the three default arguments but call our incident script with the additional required parameters. Pretty messy! |
Comment by Andris Zeila [ 2015 Sep 03 ] |
Specifications at https://www.zabbix.org/wiki/Docs/specs/ZBXNEXT-2163 |
Comment by Andris Zeila [ 2015 Sep 04 ] |
(1) [S] Database patch created in development branch svn://svn.zabbix.com/branches/dev/ZBXNEXT-2163 r55410, r55412 <dimir> The spec says A database patch must be added to set exec_params field to {ALERT.SENDTO}\n{ALERT.SUBJECT}\n{ALERT.MESSAGE}\n for the existing Script media types. however this part seems to be missing. REOPENED wiper RESOLVED in r55662 <dimir> Please review my changes in r55671. wiper Thanks, CLOSED |
Comment by Andris Zeila [ 2015 Sep 07 ] |
(2) [S] Server side support for alert macros and custom parameters for script media type. <dimir> Compilation errors: [...] discoverer.c:263:35: note: in expansion of macro ‘MACRO_TYPE_COMMON’ &item.snmpv3_contextname, MACRO_TYPE_COMMON, NULL, 0); ^ ../../../include/zbxserver.h:53:5: note: expected ‘char **’ but argument is of type ‘int’ int substitute_simple_macros(zbx_uint64_t *actionid, const DB_EVENT *event, DB_EVENT *r_event, zbx_uint64_t *userid, ^ discoverer.c:263:54: warning: passing argument 11 of ‘substitute_simple_macros’ makes integer from pointer without a cast &item.snmpv3_contextname, MACRO_TYPE_COMMON, NULL, 0); ^ In file included from discoverer.c:27:0: ../../../include/zbxserver.h:53:5: note: expected ‘int’ but argument is of type ‘void *’ int substitute_simple_macros(zbx_uint64_t *actionid, const DB_EVENT *event, DB_EVENT *r_event, zbx_uint64_t *userid, ^ discoverer.c:262:7: error: too few arguments to function ‘substitute_simple_macros’ substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ^ In file included from discoverer.c:27:0: ../../../include/zbxserver.h:53:5: note: declared here int substitute_simple_macros(zbx_uint64_t *actionid, const DB_EVENT *event, DB_EVENT *r_event, zbx_uint64_t *userid, ^ make[3]: *** [discoverer.o] Error 1 make[2]: *** [install-recursive] Error 1 make[1]: *** [install-recursive] Error 1 make: *** [install-recursive] Error 1 REOPENED wiper RESOLVED in r55638 <dimir> Looks good. Please review my small change in r55650. wiper Thanks, CLOSED |
Comment by Andris Zeila [ 2015 Sep 07 ] |
(3) [F] Custom parameter support for Script media type in frontend. iivs RESOLVED in svn://svn.zabbix.com/branches/dev/ZBXNEXT-2163 r55715, r55724, r55732 oleg.egorov CLOSED |
Comment by Volker Fröhlich [ 2015 Sep 23 ] |
ZBXNEXT-2047 appears related to me. Couldn't you make a new kind of macro that holds them all and pass that as an argument? |
Comment by Ivo Kurzemnieks [ 2015 Sep 24 ] |
(4) Removed translation strings:
Added translation strings:
oleg.egorov CLOSED <richlv> looks like there was one more translation string change :
iivs Sorry, forgot to mention this change. RESOLVED <richlv> thanks, CLOSED |
Comment by Ryan Armstrong [ 2015 Sep 24 ] |
I really like the new specification defined here, but I'm concerned it doesn't actually address the issue I've described. The root issue is that if I want to pass arguments to my script, completely unrelated to zabbix (maybe a verbose switch or a log file path, e.g. `script.pl -v --log=/some/log [recipient] [subject] [body]`), then the action will fail with "file not found". Can I use the new spec to solve this problem by simply pass a command argument as a new "script parameter"?? E.g.: param 1: -v |
Comment by richlv [ 2015 Sep 24 ] |
yes, passing such extra parameters is explicitly supported. but please do test the development branch and provide feedback here or on irc |
Comment by Ryan Armstrong [ 2015 Sep 24 ] |
Thanks richlv, unfortunately I can't access SVN behind the firewall at work to test, but I'll take a look ASAP. |
Comment by Oleg Egorov (Inactive) [ 2015 Sep 29 ] |
(5) [F] Description validation issue: [ { "mediatypeid": "1", "description": "SMS" }, { "mediatypeid": "2" } ] SQL statement execution has failed \"UPDATE media_type SET description='SMS' WHERE mediatypeid='1'\". Other issue for mediatype.create [ { "description": "E-mail2", "type": 0, "smtp_server": "[email protected]", "smtp_helo": "company.com", "smtp_email": "[email protected]" }, { "description": "E-mail2", "type": 0, "smtp_server": "[email protected]", "smtp_helo": "company.com", "smtp_email": "[email protected]" } ] SQL statement execution has failed \"INSERT INTO media_type (description,type,smtp_server,smtp_helo,smtp_email,mediatypeid) VALUES ('E-mail2','0','[email protected]','company.com','[email protected]','6')\". iivs RESOLVED in r55900 oleg.egorov In DB mediatype.update [ { "mediatypeid": "3", "description": "SMS2" }, { "mediatypeid": "9", "description": "SMS2" } ] Result: SQL statement execution has failed \"UPDATE media_type SET description='SMS2' WHERE mediatypeid='9'\". iivs RESOLVED in r55920 oleg.egorov CLOSED |
Comment by Oleg Egorov (Inactive) [ 2015 Sep 30 ] |
(6) [F] Update with empty script parameters Undefined index: exec_params [zabbix.php:21 → require_once() → ZBase->run() → ZBase->processRequest() → CController->run() → CControllerMediatypeUpdate->doAction() → CController->getInput() in include\classes\mvc\CController.php:197] implode(): Invalid arguments passed [zabbix.php:21 → require_once() → ZBase->run() → ZBase->processRequest() → CController->run() → CControllerMediatypeUpdate->doAction() → implode() in app\controllers\CControllerMediatypeUpdate.php:100] Field "exec_path" is missing a value for media type "E-mail". iivs RESOLVED in r55903 oleg.egorov CLOSED |
Comment by Oleg Egorov (Inactive) [ 2015 Sep 30 ] |
(7) [F] Based on documentation: https://www.zabbix.org/wiki/Docs/specs/ZBXNEXT-2163
Now missed newline after last parameter. Discussed addition changes:
iivs Added newline to the last parameter RESOLVED in r55903 iivs Discussed with sasha and wiper and decided to add exec_params validation in API to check the last new line feed. RESOLVED in r55927 oleg.egorov CLOSED |
Comment by Oleg Egorov (Inactive) [ 2015 Oct 01 ] |
(8) [F] Please review my minor coding style improvement r55875 iivs Thanks. Similar minor coding style fix provided in r55893. Trunk conflicts resolved in r55894. Please, review. oleg.egorov CLOSED |
Comment by Ryan Armstrong [ 2015 Oct 02 ] |
Will this be released in v2.x or only in v3? |
Comment by dimir [ 2015 Oct 02 ] |
3.0 only. |
Comment by dimir [ 2015 Oct 05 ] |
Server side successfully tested. |
Comment by Oleg Egorov (Inactive) [ 2015 Oct 06 ] |
Frontend side successfully tested. |
Comment by Ivo Kurzemnieks [ 2015 Oct 06 ] |
Implemented in pre-3.0.0alpha3 (trunk) r55951 |
Comment by Ivo Kurzemnieks [ 2015 Oct 06 ] |
(9) Documentation API documentation updated: martins-v Reviewed, with a small word order change. Also updated:
Please review. iivs Thanks! Looks good to me. wiper Agreed |
Comment by Kjetil Mæland [ 2016 Mar 07 ] |
"Add command-line parameters to the script. I have a request, why not enable the trigger macros to expand here as well? As now this adds some flexiblity. But having the possibilty to pass Today we send the messages a json, and the script parses that json to extract the needed values. However So being able to put every needed part in as a seperate parameter would be nice. |
Comment by richlv [ 2016 Apr 15 ] |
for the record, other macro/variable support tracked in |
Comment by richlv [ 2016 Apr 15 ] |
this made creating alertscript notably more complicated - ZBXNEXT-3243 asks to supply a few params by default |
Comment by Glebs Ivanovskis (Inactive) [ 2017 Sep 07 ] |
Related bug: |