[ZBX-3419] API 1.8.4 usermacro:massAdd fails with Wrong macro Created: 2011 Jan 14  Updated: 2017 May 30  Resolved: 2012 Aug 24

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 1.8.4
Fix Version/s: None

Type: Incident report Priority: Major
Reporter: Alain Ganuchaud (Inactive) Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: api, macros
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Debian GNU/Linux 5.0.6 - Zabbix 1.8.4 - ZabbixAPI.class.php V1



 Description   

Hello,

I updated zabbix with 1.8.4, I am using php scripts to do various things through APIs using zabbix-1-8-api-php-class-v1-0 from Andrew Farley. I can't get working one of them which creates macros at host level.

API complains that macro begins with { ??

Thanks for help
Alain

Below is the php code ...........

ZabbixAPI::query('usermacro','massAdd',array('host s'=>array('hostid'=>"$hid"),'macros'=>array('macro '=>"{\$ALERTLOGPATH}",'value'=>"/usr/lib/oracle/xe/app/oracle/admin/XE/bdump/alert_XE.log")))
or die('Unable to update: '.print_r(ZabbixAPI::getLastError(),true));

Below is the Debug Output .............

CURL URL: https://server/api_jsonrpc.php
<br>CURL Options: Array
(
[19913] => 1
[13] => 30
[78] => 5
[81] =>
[64] =>
[52] => 1
[74] => 1
[10023] => Array
(
[0] => Content-Type: application/json-rpc
[1] => User-Agent: ZabbixAPI v1.0 - http://andrewfarley.com/zabbix_php_api
)

[10036] => POST
[10015] => {"auth":"b1a6055e545c63fa7bcf6b6d97051396","method ":"usermacro.massAdd","id":1,"params":{"hosts":

{"h ostid":"10050"}

,"macros":{"macro":"{$ALERTLOGPATH} ","value":"eeeeeeeee"}},"jsonrpc":"2.0"}
[10102] => gzip
)
Got response from API: ({"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"[ CUserMacro::massAdd ] [

{]: Wrong macro"}

,"id":1})
Response decoded: (Array
(
[jsonrpc] => 2.0
[error] => Array
(
[code] => -32602
[message] => Invalid params.
[data] => [ CUserMacro::massAdd ] [{]: Wrong macro
)

[id] => 1
)



 Comments   
Comment by hamid sfandiari [ 2011 Apr 24 ]

i'm trying with the following :
$ss='{$ALE01}';
$macr =ZabbixAPI::fetch_array('usermacro','massAdd',array(

'macros'=>array(
'macro'=>$ss,
'value'=>'E.logi'),

'hosts'=>array('hostid'=>'10558')
))

but i've got :
Got response from API: ({"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"[ CUserMacro::massAdd ] [

{]: Wrong macro"}

,"id":1})
Response decoded: (Array
(
[jsonrpc] => 2.0
[error] => Array
(
[code] => -32602
[message] => Invalid params.
[data] => [ CUserMacro::massAdd ] [{]: Wrong macro

same as Alain

any body have any idea?

Comment by richlv [ 2011 Apr 24 ]

you could try doublequoting the actual macro;

alain seems to have an extra trailing space in the macro : "{$ALERTLOGPATH} "

Comment by Joe Black [ 2012 Aug 03 ]

Stuck with this for a few hours... you have to pass an array of macros:
'macros'=>array(array(
'macro'=>$ss,
'value'=>'E.logi')),

Comment by Alexey Fukalov [ 2012 Aug 24 ]

In 2.0 version massAdd method was removed.
You can create new macro for host using params like:
[
{
"hostid": "10093",
"macro": "{$ALERTLOGPATH}",
"value": "eeeeeeeee"
}
]

Generated at Sat Dec 13 21:52:15 EET 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.