Ejemplo n.º 1
0
 /**
  * Функция вывода нужной AJAX функции
  * @param null $tpl
  */
 function display($tpl = null)
 {
     $model = $this->getModel();
     switch (JRequest::getVar('ajaxtype')) {
         case Template:
             $this->msg = $this->get('ZabbixTemplate');
             //Получаем список шаблонов
             break;
         case zabbiximport:
             $this->msg = $this->get('ZabbixImport');
             //Загрузка данных из LD
             break;
         case massadd:
             try {
                 $api = new ZabbixApi('https://dc-zabbix.dc.mrsk-cp.net/api_jsonrpc.php', 'API', 'Y#46?&otXt&v');
                 //$api = new ZabbixApi('http://10.71.6.46/api_jsonrpc.php', 'API', 'V!PVw8N!uh1u');
                 $db = JFactory::getDBO();
                 // Подключаемся к базе.
                 $query = "SELECT  #__neq_zabbix.* FROM #__neq_zabbix";
                 //Определяем запрос
                 $db->setQuery($query);
                 //Выполняем запрос
                 $rList = $db->loadObjectList();
                 $i = 0;
                 foreach ($rList as $row) {
                     $group = $model->group($row->host, 1);
                     //Получаем название группы оборудования
                     $obj = $api->hostgroupGet(array('output' => 'extend', 'filter' => array('name' => $group)));
                     $groupid = $obj['0']->groupid;
                     $to = $model->group($row->host, 0);
                     echo $row->host . '       ' . $to . '  ';
                     if ($groupid == null) {
                         echo "Группа не определена для объекта <br>";
                     } else {
                         echo $group . '     ';
                     }
                     $interfaces = array('type' => '1', 'main' => '1', 'useip' => '1', 'ip' => $row->ip, 'dns' => '', 'port' => '10050');
                     $group = array('groupid' => '5');
                     $inventory = array('type' => $to, 'vendor' => $row->vendor, 'model' => $row->inv_name, 'poc_1_name' => $row->contact, 'poc_1_phone_a' => $row->contact_number, 'notes' => $row->description, 'location' => $row->location);
                     $templates = array('1' => array('templateid' => '13125'));
                     $host = array('host' => $row->host, 'name' => $row->name, 'interfaces' => $interfaces, 'groups' => array('1' => array('groupid' => $groupid)), 'templates' => $templates, "inventory" => $inventory);
                     try {
                         $result = $api->hostCreate($host);
                         if ($result) {
                             $i++;
                             echo '   Хост добавлен  ' . $i . '<br>';
                         } else {
                             echo $result . '<br>';
                         }
                     } catch (Exception $e) {
                         echo $e->getMessage() . '<br>';
                     }
                 }
             } catch (Exception $e) {
                 echo $e->getMessage();
             }
             break;
     }
     parent::display($tpl);
 }
Ejemplo n.º 2
0
    $groupid = isset($_GET["groupid"]) ? $_GET["groupid"] : 0;
    if ($groupid > 0) {
        //根据分组id查询分组下的机器
        $hosts = $zabbixApi->hostGet(array("output" => "extend", "monitored_hosts" => true, "groupids" => array($groupid), "sortfield" => array("host"), "sortorder" => array("ASC")));
        $new_list = array();
        foreach ($hosts as $each_host) {
            //$new_list[ip2long($each_host->host)]=$each_host;
            $new_list[] = $each_host;
        }
        ksort($new_list);
        foreach ($new_list as &$each_host_new) {
            $each_host_new->target = 'rightFrame';
            $each_host_new->groupids = $groupid;
            $each_host_new->url = 'graph.php?hostid=' . $each_host_new->hostid;
        }
        echo json_encode(array_values($new_list));
    } else {
        //查询所有的分组列表
        $groups = $zabbixApi->hostgroupGet(array("output" => "extend", "monitored_hosts" => true, "sortfield" => "name"));
        foreach ($groups as &$each) {
            $each->id = $each->groupid;
            $each->isParent = true;
            $each->target = 'rightFrame';
            $each->url = 'graph.php?group_class=' . $each->groupid;
            //查询下面有多少机器
            $hosts = $zabbixApi->hostGet(array("output" => "extend", "monitored_hosts" => true, "groupids" => array($each->groupid)));
            $each->name = $each->name . '(' . count($hosts) . ')';
        }
        echo json_encode($groups);
    }
}
Ejemplo n.º 3
0
echo date("d F Y", time());
?>
</div>
    <div id="time"><?php 
echo date("H:i", time());
?>
</div>
</div>
<!-- END GET RENDER DATE -->

<!-- We could use the Zabbix HostGroup name here, but would not work in a nice way when using a dozen of hostgroups, yet! So we hardcoded it here. --> 
<div id="sheetname">Your Group</div>

<?php 
// get hostgroupid with hosts
$groupids = $api->hostgroupGet(array('output' => 'extend', 'selectHosts' => 'extend', 'select_acknowledges' => 'extend', 'only_true' => '1'));
// get all hosts from each groupid
foreach ($groupids as $groupid) {
    $groupname = $groupid->name;
    $hosts = $groupid->hosts;
    if ($hosts) {
        $count = "0";
        //	echo "<div class=\"groupbox\">"; // Again, we dont want to use the groupfunction yet
        //      echo "<div class=\"title\">" . $groupname . "</div>";
        // print all host IDs
        foreach ($hosts as $host) {
            // Check if host is not disabled, we don't want them!
            $flaghost = $host->flags;
            if ($flaghost == "0" && $count == "0") {
                echo "<div class=\"groupbox js-masonry\" data-masonry-options='{ \"itemSelector\": \".hostbox\" }'\">";
                // echo "<div class=\"title\">" . $groupname . "</div>";