Ad Widget

Collapse

Extract values from Telnet session.

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • StefTresMan
    Member
    • Feb 2022
    • 32

    #1

    Extract values from Telnet session.

    Hi All,

    At first a real world scenario: we have temperature and humidity loggers. I want those values in Zabbix. I can get those values when i connect from my pc to the devices with telnet.
    I open a telnet session in Putty. connect to the IP of the logger on port 2101 and send this command:

    { 99RDDG\r

    The device replies with following string:

    {F00rdd 001; 52.75;%rh;000;=; 22.16;▒C;000;=;nc;---.- ;▒C;000; ;001;V2.0-2;0061358018;Accelero ;000;M

    The loggers need no authentication. It's actually just a UART to TCP bridge inside the logger, so it's quite raw.

    In this reply you can clearly see that relative humidity currently is 52.75% and temperature is 22.16 degrees Celcius. The other information in the response is obsolete.
    From what i have understood in the zabbix manual it should be possible to let zabbix connect and derive these values, and with RegEx it should be possible to get them in the right place.

    Running Zabbix 6.0

    I need a kick in the butt to point me to the right direction on how to achieve this, is there a wizard out there that somehow used this mechanism before and is willing to share his/her experience with me?

    Thank you!
  • Answer selected by StefTresMan at 06-07-2022, 14:29.
    Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    If you can create a script on your favorite shell that will connect and receive the necessary data, then you can use the capabilities of the extension agent via UserParameter.

    Comment

    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #2
      first step: https://www.zabbix.com/documentation.../telnet_checks
      second: https://www.zabbix.com/documentation.../preprocessing

      Comment

      • StefTresMan
        Member
        • Feb 2022
        • 32

        #3
        Hi Hamardaban ,

        Thank you for getting in to this. I have found these pages also. Though i am not a complete noob on Zabbix - currently running Zabbix on our company network - i can't derive the information needed to get working what i want to from this documentation. It's very rudimentary. Other resources i find on the web just give me more noise. Lots of usefull information, but no guideline - no glue that sticks this info together.
        I'm just lost in the provided building blocks Zabbix has and i am not able to translate these in to the scenario i'm in. What steps do I need to take?
        First a script connecting to the loggers? how do I integrate telnet in that script?
        Create a template with 2 items and call the script from the template?

        That's where i'm lost. I know my way a little around scripting and a tidy bit of developing, but i need a kick in the butt on how to get this done in zabbix. just a path to get me going.

        Comment

        • Hamardaban
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • May 2019
          • 2713

          #4
          Create an item of the "Telnet checks" type.
          Specify the username and password and the commands to be executed.
          The Z server connects to the specified host, executes your set of commands, and returns output.
          Next, using preprocessing, you parse this output and select what you need.

          Comment

          • StefTresMan
            Member
            • Feb 2022
            • 32

            #5
            Hi Hamardaban,

            Owkay, i've followed your advice. And immediately bounced against a Zabbix limitation. Seems like telnet cannot poll without logging in. Since the loggers are just a UART to TCP/IP bridge - there is no login procedure. So Telnet checks fail. It seemst that using Telnet within Zabbix without username/password is on the feature requests since 2020.

            I'm nearly affraid to ask, but do you have any other idea what to do now?
            I appreciate your effort.

            Comment

            • Hamardaban
              Senior Member
              Zabbix Certified SpecialistZabbix Certified Professional
              • May 2019
              • 2713

              #6
              If you can create a script on your favorite shell that will connect and receive the necessary data, then you can use the capabilities of the extension agent via UserParameter.

              Comment

              • StefTresMan
                Member
                • Feb 2022
                • 32

                #7
                Hi Hamardaban,
                Great solution, i'll look into it and share my experiences on this path.
                Thank you for your cooperation.

                Comment

                • StefTresMan
                  Member
                  • Feb 2022
                  • 32

                  #8
                  Hi Hamardaban,

                  So i have created a shellscript : etc/zabbix/rotronic.sh
                  It parses commandline parameters: -t, -h and -ip=
                  In a realworld scenario if i call
                  Code:
                  ./rotronices.sh -t -ip=10.9.5.33
                  it returns the temperature of that probe. Same for using -h: then it returns humidity.

                  In zabbix_agentd.conf i have added this line:
                  Code:
                  UserParameter=rotronic.temperature,/etc/zabbix/rotronic.sh -t -ip={HOST:IP}
                  as a sidenote, i have chmodded and chowned the script zo zabbix agent can run it.

                  Next i have created a host with the ip of one of the loggers, and created a template called "rotronics"
                  In that template i have created an item called Temperature, type zabbix agent, key rotronic.temperature, and type of information numeric(float)

                  If i check the host's latest data, i get an error next to the item:
                  Cannot compile script: SyntaxError: unterminated statement (line 1)
                  Any ideas? I feel like i'm getting close, but i'm not there yet.



                  Comment

                  • Hamardaban
                    Senior Member
                    Zabbix Certified SpecialistZabbix Certified Professional
                    • May 2019
                    • 2713

                    #9
                    1)
                    Code:
                    UserParameter=rotronic.temperature[*],/etc/zabbix/rotronic.sh -t -ip=$1
                    2) key at item Temperature -
                    Code:
                     rotronic.temperature[{HOST:IP}]
                    3) read the documentation carefully

                    Comment

                    • StefTresMan
                      Member
                      • Feb 2022
                      • 32

                      #10
                      Got one step further. Zabbix agent IS runnin the script.
                      In conf file i've changed userparameter to
                      Code:
                      UserParameter=rotronic.temperature[*],/etc/zabbix/rotronic.sh -t -ip=$1
                      Changed the item's key to
                      Code:
                      rotronic.temperature[{HOST.IP}]
                      When I test the item, it returns

                      Code:
                      [LIST][*]Value of type "string" is not suitable for value type "Numeric (unsigned)". Value "nc: missing port number"[/LIST]
                      This is actually correct, the scripts runs NC to open the socket and retrieve the info. But this means the $1 is empty,
                      Any ideas?

                      Comment

                      • Hamardaban
                        Senior Member
                        Zabbix Certified SpecialistZabbix Certified Professional
                        • May 2019
                        • 2713

                        #11
                        Since I can't see the settings of your item, I can't say anything more.
                        Try {HOST.HOST}.
                        Debug script input value.
                        etc

                        note
                        The {HOST.*} macros supported in item key parameters will resolve to the interface that is selected for the item. When used in items without interfaces they will resolve to either the Zabbix agent, SNMP, JMX or IPMI interface of the host in this order of priority or to 'UNKNOWN' if the host does not have any interface.

                        Comment

                        • StefTresMan
                          Member
                          • Feb 2022
                          • 32

                          #12
                          I came to the point that the HOST.IP is unusable. The host is always 127.0.0.1, since it's the agent that's running the script. So I have added a custom macro to the template: {$ROTR.IP}, and for this host i have set the macro in the host's configuration to the IP of the rotronic.

                          I do still get the same results, though.

                          My item settings are:
                          Click image for larger version

Name:	zbx_item.png
Views:	1222
Size:	31.9 KB
ID:	447171

                          When I test the item i get this:

                          Click image for larger version

Name:	zbx_test.png
Views:	1183
Size:	27.8 KB
ID:	447172

                          So it's quite clear that the information in the macro is not sent to the script.
                          The script does this: nc -w 1 IP PORT
                          If IP is not there, it thinks the port is the ip and says "nc: missing port number"

                          So zabbix does run the script, but the macro containing the IP is not parsed to the $1 in the userparameter, which looks like:

                          UserParameter=rotronic.temperature[*],/etc/zabbix/rotronic.sh -t -ip=$1

                          there is something going wrong between zabbix calling the agent to run the script and the parsing of the macro.


                          Comment

                          • Hamardaban
                            Senior Member
                            Zabbix Certified SpecialistZabbix Certified Professional
                            • May 2019
                            • 2713

                            #13
                            The last but important element of the chain is the script. Perhaps you are incorrectly passing a parameter to it or parsing it incorrectly.

                            Comment

                            • vladimir_lv
                              Senior Member
                              • May 2022
                              • 240

                              #14
                              Use zabbix_get and you will see what the value send agent to the server

                              Comment

                              • StefTresMan
                                Member
                                • Feb 2022
                                • 32

                                #15
                                Ok, i need a slap in the face... I called the script with "-ip=", should have been "-i="

                                Thanks for all your help, IT'S WORKING!!!

                                Comment

                                Working...