Alexei Vladishev
Any better way to do this and include in future version not to expand macro in the email? I know we could store password in the userparameters instead but it isn't acceptable by some company policies.
Appricate if someone could create a post about this. https://support.zabbix.com/projects/...issues/ZBXNEXT
Zabbix Server Version: 3.2
Macro is expanded when the email alert is sent. This affect SQL item creations.
The discovery has a macro in the key and it gets created as item and it'll still be a unexpanded macro in the host items. But when the email is sent out, the macro is expanded in the "({HOST.NAME1}:{ITEM.KEY1})".
Template App MS SQL 2012 2014 and 2016:
Item portotype name: SQL: Jobs Status {#INSTANCE} - {#JOBNAME}
Item portotype key: sql_jobs_status[{#INSTANCE},{$ZABBIX_USER},{$_ZABBIX_PWD},{#JOBID}]
Host -> Items:
Discovery name: Database jobs discovery: SQL:
Discovered item name: Jobs Status DB001\INSTANCE2 - Test Clean Up
Discovered key name: sql_jobs_status[DB001\INSTANCE2,{$ZABBIX_USER},{$_ZABBIX_PWD},2B12 345-2C59-421B-A67B-1234567F1F]
Macro that's setup:
{$ZABBIX_USER} => zabbix_user
{$_ZABBIX_PWD} => zabbix_password
Email alert ouput:
Item values:
1. SQL JOB - DB001\INSTANCE3 - JobName - "DB001\INSTANCE3_TestDatabase" (DB001:zabbix_password): Successful (1)
Note: I'm not a progammer but had to find a way to hide the password. Hoping other developers find a better way of hiding the macro in email.
Here is what I did to hide the macro...
Edit : ./src/libs/zbxserver/expression.c
836 if (SUCCEED == ret)
837 {
838 key = zbx_strdup(NULL, dc_item.key_orig);
839 /* Find macro starting '{$_' and replace its value with another macro '{$_HIDE_VALUE}'*/
840 if (request == 108)
841 {
842 if (strstr((key = zbx_strdup(NULL, dc_item.key_orig)), "{$_")!= NULL )
843 {
844 result = DBselect( "select value from globalmacro where macro = '{$_HIDE_VALUE}'");
845 if (NULL != (row = DBfetch(result)))
846 {
847 key = zbx_strdup(key, row[0]);
848 /* zabbix_log(LOG_LEVEL_WARNING, "key chagned from query = %s", key); */
849 substitute_key_macros(&key, NULL, &dc_item, NULL, MACRO_TYPE_ITEM_KEY, NULL, 0);
850 }
851 }
852 }
853 else
854 {
855 substitute_key_macros(&key, NULL, &dc_item, NULL, MACRO_TYPE_ITEM_KEY,
856 NULL, 0);
857 }
Then create the following macro's in Administarion -> General -> Macros:
{$ZABBIX_USER} => zabbix_user
{$_ZABBIX_PWD} => zabbix_password
{$_HIDE_VALUE} => value_removed
Now everytime a macro is processed and if it starts with "$_" then the sql query "select value from globalmacro where macro = '{$_HIDE_VALUE}'" is used to replace the password.
Email output:
Item values:
1. SQL JOB - DB001\INSTANCE3 - JobName - "DB001\INSTANCE3_TestDatabase" (DB001:value_removed): Successful (1)
Any better way to do this and include in future version not to expand macro in the email? I know we could store password in the userparameters instead but it isn't acceptable by some company policies.
Appricate if someone could create a post about this. https://support.zabbix.com/projects/...issues/ZBXNEXT
Zabbix Server Version: 3.2
Macro is expanded when the email alert is sent. This affect SQL item creations.
The discovery has a macro in the key and it gets created as item and it'll still be a unexpanded macro in the host items. But when the email is sent out, the macro is expanded in the "({HOST.NAME1}:{ITEM.KEY1})".
Template App MS SQL 2012 2014 and 2016:
Item portotype name: SQL: Jobs Status {#INSTANCE} - {#JOBNAME}
Item portotype key: sql_jobs_status[{#INSTANCE},{$ZABBIX_USER},{$_ZABBIX_PWD},{#JOBID}]
Host -> Items:
Discovery name: Database jobs discovery: SQL:
Discovered item name: Jobs Status DB001\INSTANCE2 - Test Clean Up
Discovered key name: sql_jobs_status[DB001\INSTANCE2,{$ZABBIX_USER},{$_ZABBIX_PWD},2B12 345-2C59-421B-A67B-1234567F1F]
Macro that's setup:
{$ZABBIX_USER} => zabbix_user
{$_ZABBIX_PWD} => zabbix_password
Email alert ouput:
Item values:
1. SQL JOB - DB001\INSTANCE3 - JobName - "DB001\INSTANCE3_TestDatabase" (DB001:zabbix_password): Successful (1)
Note: I'm not a progammer but had to find a way to hide the password. Hoping other developers find a better way of hiding the macro in email.
Here is what I did to hide the macro...
Edit : ./src/libs/zbxserver/expression.c
836 if (SUCCEED == ret)
837 {
838 key = zbx_strdup(NULL, dc_item.key_orig);
839 /* Find macro starting '{$_' and replace its value with another macro '{$_HIDE_VALUE}'*/
840 if (request == 108)
841 {
842 if (strstr((key = zbx_strdup(NULL, dc_item.key_orig)), "{$_")!= NULL )
843 {
844 result = DBselect( "select value from globalmacro where macro = '{$_HIDE_VALUE}'");
845 if (NULL != (row = DBfetch(result)))
846 {
847 key = zbx_strdup(key, row[0]);
848 /* zabbix_log(LOG_LEVEL_WARNING, "key chagned from query = %s", key); */
849 substitute_key_macros(&key, NULL, &dc_item, NULL, MACRO_TYPE_ITEM_KEY, NULL, 0);
850 }
851 }
852 }
853 else
854 {
855 substitute_key_macros(&key, NULL, &dc_item, NULL, MACRO_TYPE_ITEM_KEY,
856 NULL, 0);
857 }
Then create the following macro's in Administarion -> General -> Macros:
{$ZABBIX_USER} => zabbix_user
{$_ZABBIX_PWD} => zabbix_password
{$_HIDE_VALUE} => value_removed
Now everytime a macro is processed and if it starts with "$_" then the sql query "select value from globalmacro where macro = '{$_HIDE_VALUE}'" is used to replace the password.
Email output:
Item values:
1. SQL JOB - DB001\INSTANCE3 - JobName - "DB001\INSTANCE3_TestDatabase" (DB001:value_removed): Successful (1)