Beispiel #1
0
function calculate_availability($triggerid, $period_start, $period_end)
{
    $start_value = TRIGGER_VALUE_FALSE;
    if ($period_start > 0 && $period_start <= time()) {
        $sql = 'SELECT e.eventid,e.value' . ' FROM events e' . ' WHERE e.objectid=' . zbx_dbstr($triggerid) . ' AND e.source=' . EVENT_SOURCE_TRIGGERS . ' AND e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.clock<' . zbx_dbstr($period_start) . ' ORDER BY e.eventid DESC';
        if ($row = DBfetch(DBselect($sql, 1))) {
            $start_value = $row['value'];
            $min = $period_start;
        }
    }
    $sql = 'SELECT COUNT(e.eventid) AS cnt,MIN(e.clock) AS min_clock,MAX(e.clock) AS max_clock' . ' FROM events e' . ' WHERE e.objectid=' . zbx_dbstr($triggerid) . ' AND e.source=' . EVENT_SOURCE_TRIGGERS . ' AND e.object=' . EVENT_OBJECT_TRIGGER;
    if ($period_start != 0) {
        $sql .= ' AND clock>=' . zbx_dbstr($period_start);
    }
    if ($period_end != 0) {
        $sql .= ' AND clock<=' . zbx_dbstr($period_end);
    }
    $db_events = DBfetch(DBselect($sql));
    if ($db_events['cnt'] > 0) {
        if (!isset($min)) {
            $min = $db_events['min_clock'];
        }
        $max = $db_events['max_clock'];
    } else {
        if ($period_start == 0 && $period_end == 0) {
            $max = time();
            $min = $max - SEC_PER_DAY;
        } else {
            $ret['true_time'] = 0;
            $ret['false_time'] = 0;
            $ret['true'] = TRIGGER_VALUE_TRUE == $start_value ? 100 : 0;
            $ret['false'] = TRIGGER_VALUE_FALSE == $start_value ? 100 : 0;
            return $ret;
        }
    }
    $state = $start_value;
    $true_time = 0;
    $false_time = 0;
    $time = $min;
    if ($period_start == 0 && $period_end == 0) {
        $max = time();
    }
    if ($period_end == 0) {
        $period_end = $max;
    }
    $rows = 0;
    $db_events = DBselect('SELECT e.eventid,e.clock,e.value' . ' FROM events e' . ' WHERE e.objectid=' . zbx_dbstr($triggerid) . ' AND e.source=' . EVENT_SOURCE_TRIGGERS . ' AND e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.clock BETWEEN ' . $min . ' AND ' . $max . ' ORDER BY e.eventid');
    while ($row = DBfetch($db_events)) {
        $clock = $row['clock'];
        $value = $row['value'];
        $diff = $clock - $time;
        $time = $clock;
        if ($state == 0) {
            $false_time += $diff;
            $state = $value;
        } elseif ($state == 1) {
            $true_time += $diff;
            $state = $value;
        }
        $rows++;
    }
    if ($rows == 0) {
        $trigger = get_trigger_by_triggerid($triggerid);
        $state = $trigger['value'];
    }
    if ($state == TRIGGER_VALUE_FALSE) {
        $false_time = $false_time + $period_end - $time;
    } elseif ($state == TRIGGER_VALUE_TRUE) {
        $true_time = $true_time + $period_end - $time;
    }
    $total_time = $true_time + $false_time;
    if ($total_time == 0) {
        $ret['true_time'] = 0;
        $ret['false_time'] = 0;
        $ret['true'] = 0;
        $ret['false'] = 0;
    } else {
        $ret['true_time'] = $true_time;
        $ret['false_time'] = $false_time;
        $ret['true'] = 100 * $true_time / $total_time;
        $ret['false'] = 100 * $false_time / $total_time;
    }
    return $ret;
}
Beispiel #2
0
function drawMapLinkLabels(&$im, $map, $mapInfo, $resolveMacros = true)
{
    global $colors;
    $links = $map['links'];
    $selements = $map['selements'];
    foreach ($links as $link) {
        if (empty($link['label'])) {
            continue;
        }
        $selement1 = $selements[$link['selementid1']];
        list($x1, $y1) = get_icon_center_by_selement($selement1, $mapInfo[$link['selementid1']], $map);
        $selement2 = $selements[$link['selementid2']];
        list($x2, $y2) = get_icon_center_by_selement($selement2, $mapInfo[$link['selementid2']], $map);
        if (isset($selement1['elementsubtype']) && $selement1['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
            if ($selement1['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
                $w = $selement1['width'];
                $h = $selement1['height'];
            } else {
                $w = $map['width'];
                $h = $map['height'];
            }
            list($x1, $y1) = calculateMapAreaLinkCoord($x1, $y1, $w, $h, $x2, $y2);
        }
        if (isset($selement2['elementsubtype']) && $selement2['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
            if ($selement2['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
                $w = $selement2['width'];
                $h = $selement2['height'];
            } else {
                $w = $map['width'];
                $h = $map['height'];
            }
            list($x2, $y2) = calculateMapAreaLinkCoord($x2, $y2, $w, $h, $x1, $y1);
        }
        $drawtype = $link['drawtype'];
        $color = convertColor($im, $link['color']);
        $linktriggers = $link['linktriggers'];
        order_result($linktriggers, 'triggerid');
        if (!empty($linktriggers)) {
            $max_severity = 0;
            $triggers = array();
            foreach ($linktriggers as $link_trigger) {
                if ($link_trigger['triggerid'] == 0) {
                    continue;
                }
                $id = $link_trigger['linktriggerid'];
                $triggers[$id] = zbx_array_merge($link_trigger, get_trigger_by_triggerid($link_trigger['triggerid']));
                if ($triggers[$id]['status'] == TRIGGER_STATUS_ENABLED && $triggers[$id]['value'] == TRIGGER_VALUE_TRUE) {
                    if ($triggers[$id]['priority'] >= $max_severity) {
                        $drawtype = $triggers[$id]['drawtype'];
                        $color = convertColor($im, $triggers[$id]['color']);
                        $max_severity = $triggers[$id]['priority'];
                    }
                }
            }
        }
        $label = $link['label'];
        $label = str_replace("\r", '', $label);
        $strings = explode("\n", $label);
        $box_width = 0;
        $box_height = 0;
        foreach ($strings as $snum => $str) {
            $strings[$snum] = $resolveMacros ? CMacrosResolverHelper::resolveMapLabelMacros($str) : $str;
        }
        foreach ($strings as $str) {
            $dims = imageTextSize(8, 0, $str);
            $box_width = $box_width > $dims['width'] ? $box_width : $dims['width'];
            $box_height += $dims['height'] + 2;
        }
        $boxX_left = round(($x1 + $x2) / 2 - $box_width / 2 - 6);
        $boxX_right = round(($x1 + $x2) / 2 + $box_width / 2 + 6);
        $boxY_top = round(($y1 + $y2) / 2 - $box_height / 2 - 4);
        $boxY_bottom = round(($y1 + $y2) / 2 + $box_height / 2 + 2);
        switch ($drawtype) {
            case MAP_LINK_DRAWTYPE_DASHED_LINE:
            case MAP_LINK_DRAWTYPE_DOT:
                dashedRectangle($im, $boxX_left, $boxY_top, $boxX_right, $boxY_bottom, $color);
                break;
            case MAP_LINK_DRAWTYPE_BOLD_LINE:
                imagerectangle($im, $boxX_left - 1, $boxY_top - 1, $boxX_right + 1, $boxY_bottom + 1, $color);
                // break; is not ne
            // break; is not ne
            case MAP_LINK_DRAWTYPE_LINE:
            default:
                imagerectangle($im, $boxX_left, $boxY_top, $boxX_right, $boxY_bottom, $color);
        }
        imagefilledrectangle($im, $boxX_left + 1, $boxY_top + 1, $boxX_right - 1, $boxY_bottom - 1, $colors['White']);
        $increasey = 4;
        foreach ($strings as $str) {
            $dims = imageTextSize(8, 0, $str);
            $labelx = ($x1 + $x2) / 2 - $dims['width'] / 2;
            $labely = $boxY_top + $increasey;
            imagetext($im, 8, 0, $labelx, $labely + $dims['height'], $colors['Black'], $str);
            $increasey += $dims['height'] + 2;
        }
    }
}
Beispiel #3
0
function insert_trigger_form()
{
    global $USER_DETAILS;
    $frmTrig = new CFormTable(S_TRIGGER, "triggers.php");
    $frmTrig->SetHelp("config_triggers.php");
    if ($_REQUEST['hostid'] > 0) {
        $frmTrig->addVar("hostid", $_REQUEST['hostid']);
    }
    $dep_el = array();
    $dependencies = get_request("dependencies", array());
    $limited = null;
    if (isset($_REQUEST["triggerid"])) {
        $frmTrig->addVar("triggerid", $_REQUEST["triggerid"]);
        $trigger = get_trigger_by_triggerid($_REQUEST["triggerid"]);
        $frmTrig->SetTitle(S_TRIGGER . ' "' . htmlspecialchars($trigger["description"]) . '"');
        $limited = $trigger['templateid'] ? 'yes' : null;
    }
    $expression = get_request("expression", "");
    $description = get_request("description", "");
    $type = get_request('type', 0);
    $priority = get_request("priority", 0);
    $status = get_request("status", 0);
    $comments = get_request("comments", "");
    $url = get_request("url", "");
    if (isset($_REQUEST["triggerid"]) && !isset($_REQUEST["form_refresh"]) || isset($limited)) {
        $description = $trigger["description"];
        $expression = explode_exp($trigger["expression"], 0);
        if (!isset($limited) || !isset($_REQUEST["form_refresh"])) {
            $type = $trigger['type'];
            $priority = $trigger["priority"];
            $status = $trigger["status"];
            $comments = $trigger["comments"];
            $url = $trigger["url"];
            $trigs = DBselect('SELECT t.triggerid,t.description,t.expression ' . ' FROM triggers t,trigger_depends d ' . ' WHERE t.triggerid=d.triggerid_up ' . ' AND d.triggerid_down=' . $_REQUEST['triggerid']);
            while ($trig = DBfetch($trigs)) {
                if (uint_in_array($trig["triggerid"], $dependencies)) {
                    continue;
                }
                array_push($dependencies, $trig["triggerid"]);
            }
        }
    }
    $frmTrig->addRow(S_NAME, new CTextBox("description", $description, 90, $limited));
    $frmTrig->addRow(S_EXPRESSION, array(new CTextBox("expression", $expression, 75, $limited), $limited ? null : new CButton('insert', S_INSERT, "return PopUp('popup_trexpr.php?dstfrm=" . $frmTrig->GetName() . "&dstfld1=expression&srctbl=expression" . "&srcfld1=expression&expression=' + escape(getSelectedText(this.form.elements['expression'])),700,200);")));
    /* dependencies */
    foreach ($dependencies as $val) {
        array_push($dep_el, array(new CCheckBox("rem_dependence[]", 'no', null, strval($val)), expand_trigger_description($val)), BR());
        $frmTrig->addVar("dependencies[]", strval($val));
    }
    if (count($dep_el) == 0) {
        array_push($dep_el, S_NO_DEPENDENCES_DEFINED);
    } else {
        array_push($dep_el, new CButton('del_dependence', 'delete selected'));
    }
    $frmTrig->addRow(S_THE_TRIGGER_DEPENDS_ON, $dep_el);
    /* end dependencies */
    /* new dependence */
    //		$frmTrig->addVar('new_dependence','0');
    //		$txtCondVal = new CTextBox('trigger','',75,'yes');
    $btnSelect = new CButton('btn1', S_ADD, "return PopUp('popup.php?dstfrm=" . $frmTrig->GetName() . "&dstfld1=new_dependence[]&srctbl=triggers&multiselect=1&dstact=add_dependence&objname=triggers&srcfld1=1" . "',750,450);", 'T');
    $frmTrig->addRow(S_NEW_DEPENDENCY, $btnSelect, 'new');
    /* end new dependence */
    $type_select = new CComboBox('type');
    $type_select->additem(TRIGGER_MULT_EVENT_DISABLED, S_NORMAL, $type == TRIGGER_MULT_EVENT_ENABLED ? 'no' : 'yes');
    $type_select->additem(TRIGGER_MULT_EVENT_ENABLED, S_NORMAL . SPACE . '+' . SPACE . S_MULTIPLE_TRUE_EVENTS, $type == TRIGGER_MULT_EVENT_ENABLED ? 'yes' : 'no');
    $frmTrig->addRow(S_EVENT_GENERATION, $type_select);
    $cmbPrior = new CComboBox("priority", $priority);
    for ($i = 0; $i <= 5; $i++) {
        $cmbPrior->addItem($i, get_severity_description($i));
    }
    $frmTrig->addRow(S_SEVERITY, $cmbPrior);
    $frmTrig->addRow(S_COMMENTS, new CTextArea("comments", $comments, 90, 7));
    $frmTrig->addRow(S_URL, new CTextBox("url", $url, 90));
    $frmTrig->addRow(S_DISABLED, new CCheckBox("status", $status));
    $frmTrig->addItemToBottomRow(new CButton("save", S_SAVE));
    if (isset($_REQUEST["triggerid"])) {
        $frmTrig->addItemToBottomRow(SPACE);
        $frmTrig->addItemToBottomRow(new CButton("clone", S_CLONE));
        $frmTrig->addItemToBottomRow(SPACE);
        if (!$limited) {
            $frmTrig->addItemToBottomRow(new CButtonDelete("Delete trigger?", url_param("form") . url_param('groupid') . url_param("hostid") . url_param("triggerid")));
        }
    }
    $frmTrig->addItemToBottomRow(SPACE);
    $frmTrig->addItemToBottomRow(new CButtonCancel(url_param('groupid') . url_param("hostid")));
    $frmTrig->Show();
}
Beispiel #4
0
function calculate_availability($triggerid, $period_start, $period_end)
{
    $start_value = -1;
    if ($period_start > 0 && $period_start < time()) {
        $sql = 'SELECT eventid, value ' . ' FROM events ' . ' WHERE objectid=' . $triggerid . ' AND object=' . EVENT_OBJECT_TRIGGER . ' AND clock<' . $period_start . ' ORDER BY eventid DESC';
        if ($row = DBfetch(DBselect($sql, 1))) {
            $start_value = $row['value'];
            $min = $period_start;
        }
    }
    //SDI('ST: '.$start_value);
    $sql = 'SELECT COUNT(*) as cnt, MIN(clock) as minn, MAX(clock) as maxx ' . ' FROM events ' . ' WHERE objectid=' . $triggerid . ' AND object=' . EVENT_OBJECT_TRIGGER;
    if ($period_start != 0) {
        $sql .= ' AND clock>=' . $period_start;
    }
    if ($period_end != 0) {
        $sql .= ' AND clock<=' . $period_end;
    }
    //SDI($sql);
    $row = DBfetch(DBselect($sql));
    if ($row['cnt'] > 0) {
        if (!isset($min)) {
            $min = $row['minn'];
        }
        $max = $row['maxx'];
    } else {
        if ($period_start == 0 && $period_end == 0) {
            $max = time();
            $min = $max - 24 * 3600;
        } else {
            $ret['true_time'] = 0;
            $ret['false_time'] = 0;
            $ret['unknown_time'] = 0;
            $ret['true'] = TRIGGER_VALUE_TRUE == $start_value ? 100 : 0;
            $ret['false'] = TRIGGER_VALUE_FALSE == $start_value ? 100 : 0;
            $ret['unknown'] = TRIGGER_VALUE_UNKNOWN == $start_value ? 100 : 0;
            return $ret;
        }
    }
    $result = DBselect('SELECT eventid,clock,value ' . ' FROM events ' . ' WHERE objectid=' . $triggerid . ' AND object=' . EVENT_OBJECT_TRIGGER . ' AND clock>=' . $min . ' AND clock<=' . $max . ' ORDER BY eventid ASC');
    $state = $start_value;
    //-1;
    $true_time = 0;
    $false_time = 0;
    $unknown_time = 0;
    $time = $min;
    if ($period_start == 0 && $period_end == 0) {
        $max = time();
    }
    $rows = 0;
    while ($row = DBfetch($result)) {
        $clock = $row['clock'];
        $value = $row['value'];
        $diff = $clock - $time;
        $time = $clock;
        if ($state == -1) {
            $state = $value;
            if ($state == 0) {
                $false_time += $diff;
            }
            if ($state == 1) {
                $true_time += $diff;
            }
            if ($state == 2) {
                $unknown_time += $diff;
            }
        } else {
            if ($state == 0) {
                $false_time += $diff;
                $state = $value;
            } else {
                if ($state == 1) {
                    $true_time += $diff;
                    $state = $value;
                } else {
                    if ($state == 2) {
                        $unknown_time += $diff;
                        $state = $value;
                    }
                }
            }
        }
        $rows++;
    }
    if ($rows == 0) {
        $trigger = get_trigger_by_triggerid($triggerid);
        $state = $trigger['value'];
    }
    if ($state == 0) {
        $false_time = $false_time + $max - $time;
    } else {
        if ($state == 1) {
            $true_time = $true_time + $max - $time;
        } else {
            if ($state == 3) {
                $unknown_time = $unknown_time + $max - $time;
            }
        }
    }
    $total_time = $true_time + $false_time + $unknown_time;
    if ($total_time == 0) {
        $ret['true_time'] = 0;
        $ret['false_time'] = 0;
        $ret['unknown_time'] = 0;
        $ret['true'] = 0;
        $ret['false'] = 0;
        $ret['unknown'] = 100;
    } else {
        $ret['true_time'] = $true_time;
        $ret['false_time'] = $false_time;
        $ret['unknown_time'] = $unknown_time;
        $ret['true'] = 100 * $true_time / $total_time;
        $ret['false'] = 100 * $false_time / $total_time;
        $ret['unknown'] = 100 * $unknown_time / $total_time;
    }
    return $ret;
}
Beispiel #5
0
     unset($_REQUEST['triggerid']);
     $_REQUEST['form'] = 'clone';
 } else {
     if (isset($_REQUEST['save'])) {
         show_messages();
         if (!check_right_on_trigger_by_expression(PERM_READ_WRITE, $_REQUEST['expression'])) {
             if (isset($_REQUEST['triggerid'])) {
                 show_messages(false, null, S_CANNOT_UPDATE_TRIGGER);
             } else {
                 show_messages(false, null, S_CANNOT_ADD_TRIGGER);
             }
         } else {
             $status = isset($_REQUEST['status']) ? TRIGGER_STATUS_DISABLED : TRIGGER_STATUS_ENABLED;
             $deps = get_request('dependencies', array());
             if (isset($_REQUEST['triggerid'])) {
                 $triggerData = get_trigger_by_triggerid($_REQUEST['triggerid']);
                 if ($triggerData['templateid']) {
                     $_REQUEST['description'] = $triggerData['description'];
                     $_REQUEST['expression'] = explode_exp($triggerData['expression'], 0);
                 }
                 $current_deps = get_trigger_dependencies_by_triggerid($_REQUEST['triggerid']);
                 sort($deps);
                 sort($current_deps);
                 if ($deps == $current_deps) {
                     $deps = null;
                 }
                 $type = get_request('type');
                 $priority = get_request('priority');
                 $comments = get_request('comments');
                 $url = get_request('url');
                 if ($triggerData['type'] == $_REQUEST['type']) {
Beispiel #6
0
function drawMapLinkLabels(&$im, &$map, &$map_info)
{
    global $colors;
    $links = $map['links'];
    $selements = $map['selements'];
    foreach ($links as $lnum => $link) {
        if (empty($link)) {
            continue;
        }
        if (empty($link['label'])) {
            continue;
        }
        $selement = $selements[$link['selementid1']];
        list($x1, $y1) = get_icon_center_by_selement($selement, $map_info[$link['selementid1']]);
        $selement = $selements[$link['selementid2']];
        list($x2, $y2) = get_icon_center_by_selement($selement, $map_info[$link['selementid2']]);
        $drawtype = $link['drawtype'];
        $color = convertColor($im, $link['color']);
        $linktriggers = $link['linktriggers'];
        order_result($linktriggers, 'triggerid');
        if (!empty($linktriggers)) {
            $max_severity = 0;
            $options = array();
            $options['nopermissions'] = 1;
            $options['extendoutput'] = 1;
            $options['triggerids'] = array();
            $triggers = array();
            foreach ($linktriggers as $lt_num => $link_trigger) {
                if ($link_trigger['triggerid'] == 0) {
                    continue;
                }
                $id = $link_trigger['linktriggerid'];
                $triggers[$id] = zbx_array_merge($link_trigger, get_trigger_by_triggerid($link_trigger['triggerid']));
                if ($triggers[$id]['status'] == TRIGGER_STATUS_ENABLED && $triggers[$id]['value'] == TRIGGER_VALUE_TRUE) {
                    if ($triggers[$id]['priority'] >= $max_severity) {
                        $drawtype = $triggers[$id]['drawtype'];
                        $color = convertColor($im, $triggers[$id]['color']);
                        $max_severity = $triggers[$id]['priority'];
                    }
                }
            }
        }
        $label = $link['label'];
        $label = str_replace("\r", '', $label);
        $strings = explode("\n", $label);
        $box_width = 0;
        $box_height = 0;
        foreach ($strings as $snum => $str) {
            $strings[$snum] = resolveMapLabelMacros($str);
        }
        foreach ($strings as $snum => $str) {
            $dims = imageTextSize(8, 0, $str);
            $box_width = $box_width > $dims['width'] ? $box_width : $dims['width'];
            $box_height += $dims['height'] + 2;
        }
        $boxX_left = round(($x1 + $x2) / 2 - $box_width / 2 - 6);
        $boxX_right = round(($x1 + $x2) / 2 + $box_width / 2 + 6);
        $boxY_top = round(($y1 + $y2) / 2 - $box_height / 2 - 4);
        $boxY_bottom = round(($y1 + $y2) / 2 + $box_height / 2 + 2);
        switch ($drawtype) {
            case MAP_LINK_DRAWTYPE_DASHED_LINE:
            case MAP_LINK_DRAWTYPE_DOT:
                dashedrectangle($im, $boxX_left, $boxY_top, $boxX_right, $boxY_bottom, $color);
                break;
            case MAP_LINK_DRAWTYPE_BOLD_LINE:
                imagerectangle($im, $boxX_left - 1, $boxY_top - 1, $boxX_right + 1, $boxY_bottom + 1, $color);
            case MAP_LINK_DRAWTYPE_LINE:
            default:
                imagerectangle($im, $boxX_left, $boxY_top, $boxX_right, $boxY_bottom, $color);
        }
        imagefilledrectangle($im, $boxX_left + 1, $boxY_top + 1, $boxX_right - 1, $boxY_bottom - 1, $colors['White']);
        $increasey = 4;
        foreach ($strings as $snum => $str) {
            $dims = imageTextSize(8, 0, $str);
            $labelx = ($x1 + $x2) / 2 - $dims['width'] / 2;
            $labely = $boxY_top + $increasey;
            imagetext($im, 8, 0, $labelx, $labely + $dims['height'], $colors['Black'], $str);
            $increasey += $dims['height'] + 2;
        }
    }
}
Beispiel #7
0
function insert_trigger_form()
{
    $frmTrig = new CFormTable(S_TRIGGER, 'triggers.php');
    $frmTrig->setHelp('config_triggers.php');
    //		if(isset($_REQUEST['hostid'])){
    //			$frmTrig->addVar('hostid',$_REQUEST['hostid']);
    //		}
    $dep_el = array();
    $dependencies = get_request('dependencies', array());
    $limited = null;
    if (isset($_REQUEST['triggerid'])) {
        $frmTrig->addVar('triggerid', $_REQUEST['triggerid']);
        $trigger = get_trigger_by_triggerid($_REQUEST['triggerid']);
        $caption = array();
        $trigid = $_REQUEST['triggerid'];
        do {
            $sql = 'SELECT t.triggerid, t.templateid, h.host' . ' FROM triggers t, functions f, items i, hosts h' . ' WHERE t.triggerid=' . $trigid . ' AND h.hostid=i.hostid' . ' AND i.itemid=f.itemid' . ' AND f.triggerid=t.triggerid';
            $trig = DBfetch(DBselect($sql));
            if ($_REQUEST['triggerid'] != $trigid) {
                $caption[] = ' : ';
                $caption[] = new CLink($trig['host'], 'triggers.php?form=update&triggerid=' . $trig['triggerid'], 'highlight underline');
            }
            $trigid = $trig['templateid'];
        } while ($trigid != 0);
        $caption[] = S_TRIGGER . ' "';
        $caption = array_reverse($caption);
        $caption[] = htmlspecialchars($trigger['description']);
        $caption[] = '"';
        $frmTrig->setTitle($caption);
        $limited = $trigger['templateid'] ? 'yes' : null;
    }
    $expression = get_request('expression', '');
    $description = get_request('description', '');
    $type = get_request('type', 0);
    $priority = get_request('priority', 0);
    $status = get_request('status', 0);
    $comments = get_request('comments', '');
    $url = get_request('url', '');
    $expr_temp = get_request('expr_temp', '');
    $input_method = get_request('input_method', IM_ESTABLISHED);
    if (isset($_REQUEST['triggerid']) && !isset($_REQUEST['form_refresh']) || isset($limited)) {
        $description = $trigger['description'];
        $expression = explode_exp($trigger['expression'], 0);
        if (!isset($limited) || !isset($_REQUEST['form_refresh'])) {
            $type = $trigger['type'];
            $priority = $trigger['priority'];
            $status = $trigger['status'];
            $comments = $trigger['comments'];
            $url = $trigger['url'];
            $trigs = DBselect('SELECT t.triggerid,t.description,t.expression ' . ' FROM triggers t,trigger_depends d ' . ' WHERE t.triggerid=d.triggerid_up ' . ' AND d.triggerid_down=' . $_REQUEST['triggerid']);
            while ($trig = DBfetch($trigs)) {
                if (uint_in_array($trig['triggerid'], $dependencies)) {
                    continue;
                }
                array_push($dependencies, $trig['triggerid']);
            }
        }
    }
    $frmTrig->addRow(S_NAME, new CTextBox('description', $description, 90, $limited));
    if ($input_method == IM_TREE) {
        $alz = analyze_expression($expression);
        if ($alz !== false) {
            list($outline, $eHTMLTree) = $alz;
            if (isset($_REQUEST['expr_action']) && $eHTMLTree != null) {
                $new_expr = remake_expression($expression, $_REQUEST['expr_target_single'], $_REQUEST['expr_action'], $expr_temp);
                if ($new_expr !== false) {
                    $expression = $new_expr;
                    $alz = analyze_expression($expression);
                    if ($alz !== false) {
                        list($outline, $eHTMLTree) = $alz;
                    } else {
                        show_messages(false, '', S_EXPRESSION_SYNTAX_ERROR);
                    }
                    $expr_temp = '';
                } else {
                    show_messages(false, '', S_EXPRESSION_SYNTAX_ERROR);
                }
            }
            $frmTrig->addVar('expression', $expression);
            $exprfname = 'expr_temp';
            $exprtxt = new CTextBox($exprfname, $expr_temp, 65, 'yes');
            $macrobtn = new CButton('insert_macro', S_INSERT_MACRO, 'return call_ins_macro_menu(event);');
            //disabling button, if this trigger is templated
            if ($limited == 'yes') {
                $macrobtn->setAttribute('disabled', 'disabled');
            }
            $exprparam = "this.form.elements['{$exprfname}'].value";
        } else {
            show_messages(false, '', S_EXPRESSION_SYNTAX_ERROR);
            $input_method = IM_ESTABLISHED;
        }
    }
    if ($input_method != IM_TREE) {
        $exprfname = 'expression';
        $exprtxt = new CTextBox($exprfname, $expression, 75, $limited);
        $exprparam = "getSelectedText(this.form.elements['{$exprfname}'])";
    }
    $add_expr_button = new CButton('insert', $input_method == IM_TREE ? S_EDIT : S_ADD, "return PopUp('popup_trexpr.php?dstfrm=" . $frmTrig->getName() . "&dstfld1={$exprfname}&srctbl=expression" . "&srcfld1=expression&expression=' + escape({$exprparam}),1000,700);");
    //disabling button, if this trigger is templated
    if ($limited == 'yes') {
        $add_expr_button->setAttribute('disabled', 'disabled');
    }
    $row = array($exprtxt, $add_expr_button);
    if (isset($macrobtn)) {
        array_push($row, $macrobtn);
    }
    if ($input_method == IM_TREE) {
        array_push($row, BR());
        if (empty($outline)) {
            $tmpbtn = new CButton('add_expression', S_ADD, "");
            if ($limited == 'yes') {
                $tmpbtn->setAttribute('disabled', 'disabled');
            }
            array_push($row, $tmpbtn);
        } else {
            $tmpbtn = new CButton('and_expression', S_AND_BIG, "");
            if ($limited == 'yes') {
                $tmpbtn->setAttribute('disabled', 'disabled');
            }
            array_push($row, $tmpbtn);
            $tmpbtn = new CButton('or_expression', S_OR_BIG, "");
            if ($limited == 'yes') {
                $tmpbtn->setAttribute('disabled', 'disabled');
            }
            array_push($row, $tmpbtn);
            $tmpbtn = new CButton('replace_expression', S_REPLACE, "");
            if ($limited == 'yes') {
                $tmpbtn->setAttribute('disabled', 'disabled');
            }
            array_push($row, $tmpbtn);
        }
    }
    $frmTrig->addVar('input_method', $input_method);
    $frmTrig->addVar('toggle_input_method', '');
    $exprtitle = array(S_EXPRESSION);
    if ($input_method != IM_FORCED) {
        $btn_im = new CSpan(S_TOGGLE_INPUT_METHOD, 'link');
        $btn_im->setAttribute('onclick', 'javascript: ' . "document.getElementById('toggle_input_method').value=1;" . "document.getElementById('input_method').value=" . ($input_method == IM_TREE ? IM_ESTABLISHED : IM_TREE) . ';' . "document.forms['" . $frmTrig->getName() . "'].submit();");
        $exprtitle[] = array(SPACE, '(', $btn_im, ')');
    }
    $frmTrig->addRow($exprtitle, $row);
    if ($input_method == IM_TREE) {
        $exp_table = new CTable();
        $exp_table->setClass('tableinfo');
        $exp_table->setAttribute('id', 'exp_list');
        $exp_table->setOddRowClass('even_row');
        $exp_table->setEvenRowClass('even_row');
        $exp_table->setHeader(array($limited == 'yes' ? null : S_TARGET, S_EXPRESSION, S_EXPRESSION_PART_ERROR, $limited == 'yes' ? null : S_DELETE));
        $allowedTesting = true;
        if ($eHTMLTree != null) {
            foreach ($eHTMLTree as $i => $e) {
                if ($limited != 'yes') {
                    $del_url = new CSpan(S_DELETE, 'link');
                    $del_url->setAttribute('onclick', 'javascript: if(confirm("' . S_DELETE_EXPRESSION_Q . '")) {' . ' delete_expression(\'' . $e['id'] . '\');' . ' document.forms["config_triggers.php"].submit(); ' . '}');
                    $tgt_chk = new CCheckbox('expr_target_single', $i == 0 ? 'yes' : 'no', 'check_target(this);', $e['id']);
                } else {
                    $tgt_chk = null;
                }
                if (!isset($e['expression']['levelErrors'])) {
                    $errorImg = new CImg('images/general/ok_icon.png', 'expression_no_errors');
                    $errorImg->setHint(S_EXPRESSION_PART_NO_ERROR, '', '', false);
                } else {
                    $allowedTesting = false;
                    $errorImg = new CImg('images/general/error_icon.png', 'expression_errors');
                    $errorTexts = array();
                    if (is_array($e['expression']['levelErrors'])) {
                        foreach ($e['expression']['levelErrors'] as $expVal => $errTxt) {
                            if (count($errorTexts) > 0) {
                                array_push($errorTexts, BR());
                            }
                            array_push($errorTexts, $expVal, ':', $errTxt);
                        }
                    }
                    $errorImg->setHint($errorTexts, '', 'left', false);
                }
                //if it is a templated trigger
                if ($limited == 'yes') {
                    //make all links inside inactive
                    for ($i = 0; $i < count($e['list']); $i++) {
                        if (gettype($e['list'][$i]) == 'object' && get_class($e['list'][$i]) == 'CSpan' && $e['list'][$i]->getAttribute('class') == 'link') {
                            $e['list'][$i]->setClass('');
                            $e['list'][$i]->setAttribute('onclick', '');
                        }
                    }
                }
                $errorCell = new CCol($errorImg, 'center');
                $row = new CRow(array($tgt_chk, $e['list'], $errorCell, isset($del_url) ? $del_url : null));
                $exp_table->addRow($row);
            }
        } else {
            $allowedTesting = false;
            $outline = '';
        }
        $frmTrig->addVar('remove_expression', '');
        $btn_test = new CButton('test_expression', S_TEST, "openWinCentered(" . "'tr_testexpr.php?expression=' + encodeURIComponent(this.form.elements['expression'].value)" . ",'ExpressionTest'" . ",850,400" . ",'titlebar=no, resizable=yes, scrollbars=yes');" . "return false;");
        if (!isset($allowedTesting) || !$allowedTesting) {
            $btn_test->setAttribute('disabled', 'disabled');
        }
        if (empty($outline)) {
            $btn_test->setAttribute('disabled', 'yes');
        }
        //SDI($outline);
        $wrapOutline = new CSpan(array($outline));
        $wrapOutline->addStyle('white-space: pre;');
        $frmTrig->addRow(SPACE, array($wrapOutline, BR(), BR(), $exp_table, $btn_test));
    }
    // dependencies
    foreach ($dependencies as $val) {
        array_push($dep_el, array(new CCheckBox('rem_dependence[' . $val . ']', 'no', null, strval($val)), expand_trigger_description($val)), BR());
        $frmTrig->addVar('dependencies[]', strval($val));
    }
    if (count($dep_el) == 0) {
        array_push($dep_el, S_NO_DEPENDENCES_DEFINED);
    } else {
        array_push($dep_el, new CButton('del_dependence', S_DELETE_SELECTED));
    }
    $frmTrig->addRow(S_THE_TRIGGER_DEPENDS_ON, $dep_el);
    /* end dependencies */
    /* new dependency */
    //		$frmTrig->addVar('new_dependence','0');
    //		$txtCondVal = new CTextBox('trigger','',75,'yes');
    $btnSelect = new CButton('btn1', S_ADD, "return PopUp('popup.php?srctbl=triggers" . '&srcfld1=triggerid' . '&reference=deptrigger' . '&multiselect=1' . "',1000,700);", 'T');
    $frmTrig->addRow(S_NEW_DEPENDENCY, $btnSelect, 'new');
    // end new dependency
    $type_select = new CComboBox('type');
    $type_select->additem(TRIGGER_MULT_EVENT_DISABLED, S_NORMAL, $type == TRIGGER_MULT_EVENT_ENABLED ? 'no' : 'yes');
    $type_select->additem(TRIGGER_MULT_EVENT_ENABLED, S_NORMAL . SPACE . '+' . SPACE . S_MULTIPLE_PROBLEM_EVENTS, $type == TRIGGER_MULT_EVENT_ENABLED ? 'yes' : 'no');
    $frmTrig->addRow(S_EVENT_GENERATION, $type_select);
    $cmbPrior = new CComboBox('priority', $priority);
    for ($i = 0; $i <= 5; $i++) {
        $cmbPrior->addItem($i, get_severity_description($i));
    }
    $frmTrig->addRow(S_SEVERITY, $cmbPrior);
    $frmTrig->addRow(S_COMMENTS, new CTextArea("comments", $comments, 90, 7));
    $frmTrig->addRow(S_URL, new CTextBox("url", $url, 90));
    $frmTrig->addRow(S_DISABLED, new CCheckBox("status", $status));
    $frmTrig->addItemToBottomRow(new CButton("save", S_SAVE));
    if (isset($_REQUEST["triggerid"])) {
        $frmTrig->addItemToBottomRow(SPACE);
        $frmTrig->addItemToBottomRow(new CButton("clone", S_CLONE));
        $frmTrig->addItemToBottomRow(SPACE);
        if (!$limited) {
            $frmTrig->addItemToBottomRow(new CButtonDelete(S_DELETE_TRIGGER_Q, url_param("form") . url_param('groupid') . url_param("hostid") . url_param("triggerid")));
        }
    }
    $frmTrig->addItemToBottomRow(SPACE);
    $frmTrig->addItemToBottomRow(new CButtonCancel(url_param('groupid') . url_param("hostid")));
    $jsmenu = new CPUMenu(null, 170);
    $jsmenu->InsertJavaScript();
    $script = "function addPopupValues(list){\n\t\t\t\t\t\tif(!isset('object', list)) return false;\n\n\t\t\t\t\t\tif(list.object == 'deptrigger'){\n\t\t\t\t\t\t\tfor(var i=0; i < list.values.length; i++){\n\t\t\t\t\t\t\t\tcreate_var('" . $frmTrig->getName() . "', 'new_dependence['+i+']', list.values[i], false);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tcreate_var('" . $frmTrig->getName() . "','add_dependence', 1, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t}";
    insert_js($script);
    return $frmTrig;
}
Beispiel #8
0
        imagestring($im, 2, 2, $y + 2, $y, $black);
    }
    imagestring($im, 2, 1, 1, "Y X:", $black);
}
// Draw connectors
$links = DBselect('select * from sysmaps_links where sysmapid=' . $_REQUEST['sysmapid']);
while ($link = DBfetch($links)) {
    list($x1, $y1) = get_icon_center_by_selementid($link["selementid1"]);
    list($x2, $y2) = get_icon_center_by_selementid($link["selementid2"]);
    $drawtype = $link["drawtype"];
    $color = convertColor($im, $link["color"]);
    $triggers = get_link_triggers($link['linkid']);
    if (!empty($triggers)) {
        $max_severity = 0;
        foreach ($triggers as $id => $link_trigger) {
            $triggers[$id] = array_merge($link_trigger, get_trigger_by_triggerid($link_trigger["triggerid"]));
            if ($triggers[$id]["status"] == TRIGGER_STATUS_ENABLED && $triggers[$id]["value"] == TRIGGER_VALUE_TRUE) {
                if ($triggers[$id]['severity'] >= $max_severity) {
                    $drawtype = $triggers[$id]['drawtype'];
                    $color = convertColor($im, $triggers[$id]['color']);
                    $max_severity = $triggers[$id]['severity'];
                }
            }
        }
    }
    MyDrawLine($im, $x1, $y1, $x2, $y2, $color, $drawtype);
}
// Draw elements
$icons = array();
$db_elements = DBselect('select * from sysmaps_elements where sysmapid=' . $_REQUEST['sysmapid']);
while ($db_element = DBfetch($db_elements)) {
Beispiel #9
0
 /**
  * Gets all trigger data from DB by Trigger ID
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @param _array $trigger
  * @param array $trigger['triggerid']
  * @return array|boolean array of trigger data || false if error
  */
 public static function getById($trigger)
 {
     $trigger = get_trigger_by_triggerid($trigger['triggerid']);
     $result = $trigger ? true : false;
     if ($result) {
         $result = $trigger;
     } else {
         self::$error[] = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
     }
     return $result;
 }