-
Type:
Incident report
-
Resolution: Won't fix
-
Priority:
Critical
-
None
-
Affects Version/s: 1.8.2
-
Component/s: API (A)
-
None
-
Environment:Using PHP
I have code that creates a user and should create a media record for it as well. It returns without error, but doesn't create the media.
I'm using the zabbix php API class made by Andrew Farley, you can find it here: http://andrewfarley.com/php/zabbix-1-8-api-php-class-v1-0
Here's the function:
function zabbix_bridge_create_zabbix_user($edit, $account, $category)
{ var_dump($edit, $account, $category); // This logs into Zabbix, and returns false if it fails ZabbixAPI::login('http://zabbix.yomama.com/','admin','zabbix') or die('Unable to login: '.print_r(ZabbixAPI::getLastError(),true)); //create the user $zabbixuserid = ZabbixAPI::fetch_string('user', 'create', array( 'email' => $edit['mail'], 'alias'=>$edit['name'], 'passwd'=>$edit['pass'], 'number_of_hosts'=>0)) //number_of_hosts is added because of a bug in API 1.2 or die('Unable to create zabbix user: '.print_r(ZabbixAPI::getLastError(),true)); echo "Zabbix user created: ".$zabbixuserid."\n"; //add the email address to it's media $medias = ZabbixAPI::fetch_array('user', 'addMedia', array( 'userid' => $zabbixuserid, 'medias' => array('mediatypeid' => 1, 'sendto' => $edit['mail'], 'active' => 0, 'severity' => 63, 'period' => '1-7,00:00-23:59;'))) or die('Unable to add media to user: '.print_r(ZabbixAPI::getLastError(),true)); echo "Media added to zabbix user:\n".var_dump($medias)."\n"; }