Ad Widget

Collapse

Trigger Status - Open custom URL for a host

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neuralfraud
    Junior Member
    • Apr 2011
    • 1

    #1

    Trigger Status - Open custom URL for a host

    Hello,

    I've searched in the past for information on whether zabbix included a mechanism to define a quick go-to url for a device when a trigger is set - for example, a router. In addition to ping/traceroute, opening a url to the web interface of a server/router is often desired for reasons which I will not get into because that is unimportant.

    I was unable to find anything substantial so I took a look at the host profiles. Ordinarily you could define a url in the extended profile and see it from the inventory screen, which is fine and dandy, but for a host showing trouble and/or recent recovery from trouble, it's nice to have the URL at your fingertips.

    I examined the feature built into the trigger definition and found it to be inadequate.

    The answer I've come up with is relatively simple though it involves modifying scripts_exec.php

    First you define a new script called "URL" and in the command text, it does not matter what is entered as long as something is present.

    The modified scripts_exec.php checks if the script id being executed is named "url" - the script name is converted to lowercase of course. If the script name is "url" then the next step is to select device_url_1 from hosts_profiles_ext. If the device url is not empty (very simplistic check here) it is assumed to be valid and a http redirect is used to open the url. If the value is empty then a zabbix error message is displayed. If the script name is anything other than "url", the script is exected as normal.

    Here is the modified scripts_exec.php - I hope many find it useful, and hopefully zabbix 2.0 will include some sort of mechanism for this in a more "proper" type of implementation

    I have also modified my hostprofiles.php to display the info directly on the main table for convenience, but that's another post.


    PHP Code:
    <?php
    /*
    ** ZABBIX
    ** Copyright (C) 2000-2007 SIA Zabbix
    **
    ** This program is free software; you can redistribute it and/or modify
    ** it under the terms of the GNU General Public License as published by
    ** the Free Software Foundation; either version 2 of the License, or
    ** (at your option) any later version.
    **
    ** This program is distributed in the hope that it will be useful,
    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ** GNU General Public License for more details.
    **
    ** You should have received a copy of the GNU General Public License
    ** along with this program; if not, write to the Free Software
    ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    **/
    ?>
    <?php
        
    include_once "include/config.inc.php";
        require_once 
    "include/hosts.inc.php";
        require_once 
    "include/scripts.inc.php";
        require_once 
    "include/forms.inc.php";

        
    $page['title'] = "S_SCRIPTS";
        
    $page['file'] = 'scripts_exec.php';

        
    define('ZBX_PAGE_NO_MENU'1);


    //        VAR                            TYPE    OPTIONAL FLAGS    VALIDATION    EXCEPTION
    $fields=array(
        
    'hostid'=>                array(T_ZBX_INTO_OPTP_SYS,            DB_ID,    'isset({execute})'),
        
    'scriptid'=>            array(T_ZBX_INTO_OPTP_SYS,            DB_ID,    'isset({execute})'),
        
    'execute'=>                array(T_ZBX_INTO_OPT,  P_ACT,         IN('0,1'),    null),
    );
    check_fields($fields);

    if(isset(
    $_REQUEST['execute'])){
        
    $scriptid $_REQUEST['scriptid'];
        
    $hostid $_REQUEST['hostid'];

        
    $sql 'SELECT name '.
                
    ' FROM scripts '.
                
    ' WHERE scriptid='.$scriptid;
        
    $script_info DBfetch(DBselect($sql));
    /**
     * Jason Lashua's URL hack
     * OPEN URL
     * Premise: Define a script with the name "URL" that will allow a user to easily
     * access the url defined in the host's extended host profile "device_url_1" field.
     * Action: Check to determine if script type is url, otherwise execute as normal.
     * If script = url, then read the url value from the hostid's profile URL and
     * issue http header to redirect.
     *
     * IF url is empty show error page
     */
        
    if (strtolower($script_info['name']) == 'url')
        {
            
    $sql 'SELECT device_url_1 FROM hosts_profiles_ext WHERE hostid=' $hostid;
            
    $url_info DBfetch(DBselect($sql));
            if (
    strlen($url_info['device_url_1']) > 0)
            {
                
    // Valid URL presumed to exist - let's redirect to it;
                
    header("Location: " $url_info['device_url_1']);
                exit();
            }
            else
            {
                include_once 
    "include/page_header.php";
                
    show_messages(false'A url for this host has not been configured.''A url for this host has not been configured.');
            }
        }
        else
        {
        
            include_once 
    "include/page_header.php";
            
    $result CScript::execute(array('hostid' => $hostid'scriptid' => $scriptid));
            if(
    $result === false){
                
    show_messages(false''S_SCRIPT_ERROR);
            }
            else{
                
    $message $result['value'];
                if(
    $result['response'] == 'failed'){
                    
    error($message);
                    
    show_messages(false''S_SCRIPT_ERROR);
                    
    $message '';
                }
        
                
    $frmResult = new CFormTable($script_info['name'].': '.script_make_command($scriptid$hostid));
                
    $frmResult->addRow(S_RESULT, new CTextArea('message'$message10025'yes'));
                
    $frmResult->addItemToBottomRow(new CButton('close'S_CLOSE'window.close();'));
                
    $frmResult->show();
            }
            
        }
        
    }

    include_once 
    "include/page_footer.php";
    ?>
  • mushero
    Senior Member
    • May 2010
    • 101

    #2
    We did something similar and modified the dashboard to pull host-specific fields from the profile, such as the host-name or tag, etc. that can be used - so our 24x7 team just clicks on the trigger on the dashboard and gets sent to a special place by host, in our case a wiki that has detailed info on that host.

    We also modified the dashboard popup menu when you click on the host name to send you to various places such as a host summary page from other systems, a ticket creation page from our ticket system (with host name, trigger, etc. all filled in), etc.

    Would be great if a trigger had more fields and allowed MACROs for this type of thing, like a trigger URL, host URL, this trigger on this host URL, etc.

    Comment

    Working...