Ad Widget

Collapse

Zabbix Trapper Item (LLD Zabbix Trapper Item)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • syndeysider
    Senior Member
    • Oct 2013
    • 115

    #1

    Zabbix Trapper Item (LLD Zabbix Trapper Item)

    Hi All

    I've spent 3 days on this issue and have really google fu'ed my heart out trying to get to the bottom of this. Would really like a pointer in the right direction.

    Background :
    I've got a little script that sends SMS based alerts out via a 3rd party provider.This works a treat. What I am trying to incorporate is zabbix_sender to send back the sent SMS to the Zabbix Server. Attached at the images from my template.

    I have created a template : Template SMS Provider
    I have created a discovery item : SMS -> This key stores an item per unique sms sent number
    I have created an item prototype : MSG Send : {#NUMBER} -> this key should store a unique value per item? i.e. sms text per sms sent

    Problem :
    I am first off a bit confused with the correct JSON format but the following seems to partially work :

    My SMS Script writes the following two lines out to a file which I than zabbix_sender -i later :

    host1 whispir.api.sms { "data":[{ "{#NUMBER}":"+61411111111" }]}
    host1 whispir.api.sms.sent { "data":[{ "{#MSGSENT}":"2013-10-21 06:09:08 Test SMS from console JSON API." }]}

    My response on a zabbix_sender -z server1 -i sms_sent.txt is :

    zabbix_sender [2340]: DEBUG: answer [{
    "response":"success",
    "info":"Processed 1 Failed 1 Total 2 Seconds spent 0.007768"}]
    info from server: "Processed 1 Failed 1 Total 2 Seconds spent 0.007768"
    sent: 2; skipped: 0; total: 2

    The first line get's partially processed correctly server side i.e. I see the item on the host configuration, but i do not see any data in latest data.

    I know tha t a) i'm either confused about the JSON format or how to use a zabbix trapper item or b) somethings not working the way it should?

    Any help would be greatly appreciated.

    Images : http://imgur.com/9f0Xhww,ykyxRpc,9S5tMzh,LDlJ40G
  • steveboyson
    Senior Member
    • Jul 2013
    • 582

    #2
    I dont think that a trapper item can be used for a LLD rule.

    I would:
    - write a LLD script to enumerate the items as a regular "zabbix agent" or "zabix agent (active)" item
    - for item prototypes for this LLD rule, you can use trapper items

    So your LLD enums all sent SMS with
    {
    "data":[

    { "{#MSGNUM}":"1" },
    { "{#MSGNUM}":"2" },
    { "{#MSGNUM}":"3" },
    { "{#MSGNUM}":"4" }
    ]
    }

    and the items appear as follows:

    Name: Text of SMS {#MSGNUM}
    Key: msgtext[{#MSGNUM}
    Type: Trapper
    Data: Text (or char if length < 255)

    Name: send Date of SMS {#MSGNUM}
    Key: msgdate[{#MSGNUM}
    Type: Trapper
    Data: char

    Then your script would just send data to the according trapper items.

    Comment

    • timbo
      Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Sep 2013
      • 50

      #3
      Hi syndeysider,

      I'm going to go out on a limb here and presume you're a Sydney sider (i.e. Sydney, Australia) - As I am also a resident of the wonderful city that is Sydney. Although I have only been a member of the Zabbix forums for a month or two, I'd like to say Welcome to the forums!

      Now, onto the task at hand.

      Great idea, notifications via SMS are an obvious addition, but logging SMS responses to those notifications is a great idea!

      So, if I am reading this correctly, you're not having any issues with the LLD, or creating hosts/items, you're having trouble getting data from your script/SMS provider into the existing hosts/items. Yeah?

      I do a lot of scripting, and I'm always updating Zabbix Trappers from many different machines, but I have never used the Zabbix Sender. Instead of using the Zabbix Sender I establish a simple TCP connection to port 10051 (of the Zabbix Server/Proxy) and send the appropriate JSON message to it.

      It can be that simple.

      Note: The Zabbix Sender is the official way of updating items, so I'm not suggesting my way is better (or even supported) it just works for me.

      So, if you'd like to attempt my method, try and find a TCP function in the language you're using to script the retrieval of SMS responses.

      I know the 'fsockopen' function in PHP works (many SMS providers have PHP APIs), and at a quick glance it seems 'MSWINSOCK.Winsock' may work in VBScript (or most windows scripting languages).

      Anyway, in your script instead of writing the SMS responses to a text file for the Zabbix Sender, open a TCP connection to the Zabbix Server (using the available methods) and send something like the following:
      {"request":"agent data","data":[{"host":"host1","key":"whispir.api.sms","value" :"+61411111111"}]}

      As '+61411111111' is not a number, nor will you need to graph the values, you'd probably want the 'Type of information' to be set to 'Text'.

      Hope this helps! If not, I'm more than happy to clarify.

      -Timbo

      Comment

      • timbo
        Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Sep 2013
        • 50

        #4
        Originally posted by timbo
        Anyway, in your script instead of writing the SMS responses to a text file for the Zabbix Sender, open a TCP connection to the Zabbix Server (using the available methods) and send something like the following:
        {"request":"agent data","data":[{"host":"host1","key":"whispir.api.sms","value" :"+61411111111"}]}
        Hmm, I'm not sure how you want things set up, but perhaps you'd like to create items with keys like:
        whispir.api.sms[+61411111111]

        Then send JSON messages like:
        {"request":"agent data","data":[{"host":"host1","key":"whispir.api.sms.sent[+61411111111]","value" :"2013-10-21 06:09:08 Test SMS from console JSON API."}]}

        Or maybe name the Host after the sending Mobile number:
        {"request":"agent data","data":[{"host":"Mob61411111111","key":"whispir.api.sms.se nt","value" :"2013-10-21 06:09:08 Test SMS from console JSON API."}]}

        -Timbo

        Comment

        • syndeysider
          Senior Member
          • Oct 2013
          • 115

          #5
          Thanks !

          Hi Guys

          Thanks so much for the replies. It's giving me some thinking to do and i'll post back when i've got a solution.

          Am indeed from Sydney

          The thought behind all of this was that LLD would automatically pickup new "Mobile Numbers" and add them as items to my host. Than, I would want further dynamic values added as each sms is sent.

          So in a scenario where

          +641111111 "SENT: text message 1"
          +641111111 "SENT: text message 2"
          +642222222 "SENT: text message 3"
          +643333333 "SENT: text message 4"

          I'd have 3 items (unique mobile numbers) added to my host with a historical list of sms' sent per item.

          Why am I getting so complicated? Because our SMS provider allows SMS Responses and they post this information back to us. The response script would than utilize the same methodology and have something like

          +641111111 "RECIEVED: response 1"
          +641111111 "RECIEVED: response 2"
          +642222222 "RECIEVED: response 3"
          +643333333 "RECIEVED: response 4"

          Than what i would have is one item for each mobile on my host (zabbix server) which would have a history of SENT/RECEIVED messages history log which i could than trigger on.

          What i've identified thus far today is that it appears I cant use Trapper Items in LLD the way i want to, unless im missing something. My workaround presently is a single Zabbix Trapper Item (non discovery) which contains the whole text string i.e. it traps all messages sent and received including number, text, sent/recieved etc. and my triggers are a little more complex....

          Would still like to graph out number of texts sent or recieved to/from a particular number and maybe even get the timing delay in responses going but that requires some more thought. This would allow me to effectively manage our on call response times and escalate etc.

          Very new to Zabbix but really amazed at this product thus far. Have some really awesome scripts etc. that I will share to contribute shortly.

          Any more input on this topic is greatly appreciated.

          Comment

          • syndeysider
            Senior Member
            • Oct 2013
            • 115

            #6
            Solved

            timbo!! You put me on the right track. Thanks so much!!

            I finally got this working the way I wanted.

            How it works is as follows :

            1. You create a Discovery trapper item with an api name e.g. whispir.api.sms
            2. You zabbix_sender data in the format { "data":[{"{#NUMBER}":"$mobile", "{#NAME}":"$fullname"}]}";

            This creates an item on the host you specify.

            3. You create an item prototype with an api name whispir.api.sms.s[{#NUMBER}]
            4. You zabbix_sender data with -k (key) = whispir.api.sms.s[mobilenumbervariable] "Message Text"

            This backlinks the number from the Discovery Item to the Item Prototype

            e.g.

            SMS: Mobile : +6111111111111111 = Discovery Item 1
            Text 1
            Text 2
            Text 3
            SMS: Mobile : +6333333333333333 = Discovery Item 2
            Text 1
            Text 2

            etc.

            So... You can get LLD working with Trapper items... it's just a little confusing understanding how they work.

            Comment

            • nail
              Member
              • Jun 2012
              • 32

              #7
              How exactly did you manage to do that?
              Did your zabbix_sender line looked like this?
              Code:
              zabbix_sender -vv -z ZABBIX -s HOST -k ITEM -o '"{#NUMBER}":"$mobile"'
              Trying to do this now with .NET sender, got sender data:
              Code:
              {
              	"request": "sender data",
              	"data": [{
              		"host": "LLD_TEST",
              		"key": "DISCOVERY_KEY",
              		"value": [{
              			"{#ITEM}": "200"
              		}, {
              			"{#ITEM}": "100"
              		}]
              	}]
              }
              and response:
              Code:
              {"response":"success","info":"processed: 0; failed: 1; total: 1; seconds spent: 0.000019"}
              zabbix_server.log:
              Code:
              trapper got '{"request":"sender data","data":[{"host":"LLD_TEST","key":"DISCOVERY_KEY","value":[{"{#ITEM}":"200"},{"{#ITEM}":"100"}]}]}'
              and no errors there.

              upd. found solution to format string correctly in C#
              first serialize your data
              Code:
              string zstr = Newtonsoft.Json.JsonConvert.SerializeObject(new { data = zval });
              then pass it to sender here:
              Code:
              value   = zstr
              (full .NET zabbix_sender code can be found on forum)
              Last edited by nail; 14-07-2016, 11:52. Reason: found solution

              Comment

              Working...