Ad Widget

Collapse

use script on label (network maps)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spoonman
    Member
    • Aug 2013
    • 45

    #1

    use script on label (network maps)

    Hi,

    I'm trying to display my Dynamic WAN ip address on a device/label on the map layout.
    The script is : curl ifconfig.me
    This works OK if you click on a device and choose this command, it then shows the WAN address.
    What I want is this address always to be displayed on the network map.
    So a device with a label <WAN address>.
    How is this done ??
    Last edited by Spoonman; 03-06-2014, 22:22.
  • aib
    Senior Member
    • Jan 2014
    • 1615

    #2
    Create an Item and use that Item.last(0) as a description of label
    Sincerely yours,
    Aleksey

    Comment

    • Spoonman
      Member
      • Aug 2013
      • 45

      #3
      Originally posted by aib
      Create an Item and use that Item.last(0) as a description of label
      I know what you mean, but in my case I need the script output, not the Item output...

      Comment

      • aib
        Senior Member
        • Jan 2014
        • 1615

        #4
        wait a second.

        I told you that you can redirect the "script output" into "Item output", then you can use "Item output" everywhere, even on Network Map for labels.

        What wrong with that?
        Sincerely yours,
        Aleksey

        Comment

        • Spoonman
          Member
          • Aug 2013
          • 45

          #5
          Originally posted by aib
          wait a second.

          I told you that you can redirect the "script output" into "Item output", then you can use "Item output" everywhere, even on Network Map for labels.

          What wrong with that?
          I'm sorry if I understood it wrong.
          I have created a Template, with an Item (Show WAN address).
          But what key do I insert, there is no script item I can select or link with it...
          - I selected: Type "external check"
          - Key "curl ifconfig.me" > not supported

          Comment

          • aib
            Senior Member
            • Jan 2014
            • 1615

            #6


            1) create an external script (show_wan.sh) in directory for ExternalScripts
            Code:
            [zabbix]# grep extern /etc/zabbix/zabbix_server.conf
            #       Full path to location of external scripts.
            ExternalScripts=/usr/lib/zabbix/externalscripts
            2) script will be as simple as :
            Code:
            [zabbix]# cat show_wan.sh
            #!/bin/bash
            curl ifconfig.me
            3) Create an Item
            Name: Show WAN address
            Type: External check
            Key: show_wan.sh
            Type of information: {select the proper type - Numeric OR Text}

            4) Configuration -> Maps -> (select map) -> (select Host)
            in Host Label field type: {{HOST.HOST}: show_wan.sh.last(0)}

            5) profit.
            Sincerely yours,
            Aleksey

            Comment

            • Spoonman
              Member
              • Aug 2013
              • 45

              #7
              Hi Aleksey,

              thank you very much for helping me

              I followed your instructions, but what I now see on the map/label is : {show_wan.sh.last(0)} , but no ip address.

              Comment

              • aib
                Senior Member
                • Jan 2014
                • 1615

                #8
                Check, please, that you entered the name correctly
                it has to include the name of host, ":", the name of item, ".", the name of function - all without any space in between and with curly brackets around.

                like that:
                {server1:show_wan.sh.last(0)}

                The name of host can be replaced to macros {HOST.HOST}, and it will looks like I showed to you in my previous message.

                if you see only {show_wan.sh.last(0)} - it means that you lost the name of host.
                Also check Monitoring -> Latest data - if you have any data for new Item.
                Sincerely yours,
                Aleksey

                Comment

                • Spoonman
                  Member
                  • Aug 2013
                  • 45

                  #9
                  Hello Aleksey,

                  maybe my problem is due to the fact that the label is attached to an image, rather then an actual host.
                  The device is a modem, which cannot be monitored or accessed.
                  All I want is the IP address to show in the label, with the script.

                  - edit - I already have labels with up and download speeds in them, works great. So I know how the "trick" works.

                  Comment

                  • aib
                    Senior Member
                    • Jan 2014
                    • 1615

                    #10
                    I see what you mean.
                    In case of uncontrolled device, the formula has to have the name of Host where that Item created.
                    For example, if you create an Item show_wan.sh under Zabbix_server host, the formula would be:
                    {zabbix_server:show_wan.sh.last(0)}

                    It's because Zabbix has to have FQIN (Fully Qualified Item Name), includes:
                    • host name
                    • item name
                    • formula (last/max/min/avg)
                    Sincerely yours,
                    Aleksey

                    Comment

                    • Spoonman
                      Member
                      • Aug 2013
                      • 45

                      #11
                      Thanks for your answers.
                      Now the label says : *UNKNOWN*
                      I followed your previous mail and also tried variations like

                      {zbx-server:show_wan.sh.last(0)}
                      > *UNKNOWN*

                      {{zbx-server}:show_wan.sh.last(0)}
                      > label displays {{zbx-server}:show_wan.sh.last(0)}

                      I see in the Item list "item not supported" and "permission denied".
                      I will change permissions and see what gives.
                      Last edited by Spoonman; 06-06-2014, 15:27.

                      Comment

                      • aib
                        Senior Member
                        • Jan 2014
                        • 1615

                        #12
                        check permissions for show_wan.sh
                        Code:
                        [root@zabbix ~]# ls -la /usr/lib/zabbix/externalscripts/
                        drwxr-xr-x  2 zabbix zabbix  4096 Jun  6 09:25 .
                        -rwxr-xr-x  1 zabbix zabbix    92 Feb 28 08:50 aacraid.active_drives
                        -rwxr-xr-x  1 zabbix zabbix   101 Feb 28 08:51 aacraid.controller_status
                        -rwxr-xr-x  1 zabbix zabbix   330 Feb 27 10:54 dnschk.sh
                        -rwxr-xr-x  1 zabbix zabbix   249 Feb 27 11:10 ntpchk.sh
                        -rwxr-xr-x  1 zabbix zabbix    95 Jun  6 09:25 sharesamount
                        Do you mind to take a screenshot of Item configuration?
                        I would like to see to give you more precise advice.
                        Sincerely yours,
                        Aleksey

                        Comment

                        • Spoonman
                          Member
                          • Aug 2013
                          • 45

                          #13
                          These are the permissions and owner settings:

                          -rwxr-xr-x 1 root root 28 Jun 4 19:35 show_wan.sh

                          I use CentOS 6.5 and ZABBIX 2.2.3

                          Comment

                          • aib
                            Senior Member
                            • Jan 2014
                            • 1615

                            #14
                            from Documentation
                            Zabbix server will look in the directory defined as the location for external scripts (parameter 'ExternalScripts' in Zabbix Server configuration file) and execute the command. The command will be executed as the user Zabbix server runs as, so any access permissions or environment variables should be handled in a wrapper script, if necessary, and permissions on the command should allow that user to execute it. Only commands in the specified directory are available for execution.
                            So, if your Zabbix Server works under zabbix credentials, that external script has to have permissions for zabbix, not for root

                            change it, please
                            Code:
                            chown zabbix:zabbix show_wan.sh
                            Sincerely yours,
                            Aleksey

                            Comment

                            • Spoonman
                              Member
                              • Aug 2013
                              • 45

                              #15
                              Originally posted by aib
                              change it, please
                              Code:
                              chown zabbix:zabbix show_wan.sh
                              Ok, I changed the permissions.
                              If I look now in Items, it says "timeout while executing a shell script".
                              And still "not supported".

                              Comment

                              Working...