echo "-получаем api-key\n";
$res=$zab->Auth($login, $password);
$triggerid=$options["t"];
$txt=$options["s"];
$users_id_for_sms=array();
echo "-действия по триггеру\n";
$res=$zab->Execute("action.get", ["triggerids"=>$triggerid,"output"=>'extend','selectOperations'=>'extend','selectRecoveryOperations'=>'extend','selectFilter'=>'extend']);
ParseRes($res);
echo "-получаем хост\n";
$hosts=$zab->Execute("host.get", ["triggerids"=>$triggerid]);
foreach ($hosts->result as $host) {
$hostid=$host->hostid;
$hostname=$host->name;
echo "--действия по хосту $hostid $hostname\n";
$res=$zab->Execute("action.get", ["hostids"=>$hostid,"output"=>'extend','selectOperations'=>'extend','selectRecoveryOperations'=>'extend','selectFilter'=>'extend']);
ParseRes($res);
$hostsg=$zab->Execute("hostgroup.get", ["hostids"=>$hostid]);
foreach ($hostsg->result as $hostg) {
$groupid=$hostg->groupid;
echo "--- действия по группе хоста $groupid\n";
$res=$zab->Execute("action.get", ["groupids"=>$groupid,"output"=>'extend','selectOperations'=>'extend','selectRecoveryOperations'=>'extend','selectFilter'=>'extend']);
ParseRes($res);
}
};
echo "- пользователи ZABBIX\n";
var_dump($users_id_for_sms);
$sms=array();
foreach ($users_id_for_sms as $userid) {
$res=$zab->Execute("user.get", ["userids"=>$userid,"output"=>'extend','status'=>0,"selectMedias"=>"extend"]);
foreach ($res->result as $usersinfo) {
foreach ($usersinfo->medias as $md) {
if ($md->mediatypeid==5){
$sms[]=$md->sendto;
};
};
}
}
var_dump($sms);
function ParseRes($res){
global $zab,$users_id_for_sms;
if (count($res->result)!=0){
foreach ($res->result as $oper) {
foreach ($oper->operations as $vl) {
echo "---получаю пользователей группы\n";
foreach ($vl->opmessage_grp as $usergroups) {
$usrgrpid= $usergroups->usrgrpid;
echo "----$usrgrpid\n";
$res=$zab->Execute("user.get", ["usrgrpids"=>$usrgrpid,"output"=>'extend','status'=>0]);
foreach ($res->result as $user) {
$users_id_for_sms[]=$user->userid;
};
// $res=$zab->Execute("user.get", ["usrgrpids"=>15,"output"=>'extend','status'=>0]);
// foreach ($res->result as $user) {
// $users_id_for_sms[]=$user->userid;
// };
};
echo "---добавляю просто пользователей\n";
//var_dump($vl->opmessage_usr);
foreach ($vl->opmessage_usr as $userslist) {
$users_id_for_sms[]= $userslist->userid;
};
};
}
};
};