Ad Widget

Collapse

Complete recipe for monitoring DNS and NTP on your Network

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OneLoveAmaru
    Member
    • Jan 2008
    • 41

    #16
    I turned debug on, ran zabbix_get and it's returning the correct value of 1. I also checked for the Process listener error: ZBX_TCP_WRITE() failed [Broken pipe] and i'm actually not seeing it anymore. Hmm... weird. But good.

    Latest data still shows no value for my item so the only thing I can think of, is that my item is mis-configured. It asks for DNS1 correctly, the server answers but the item must be expecting something else. That's the only thing that really would make sense here. Does my item look correct?

    Comment

    • tokind
      Member
      • May 2007
      • 47

      #17
      Yes, it does look correct. I would disable and then re-enable the item and see if it starts getting the value. I sometimes needed to do this a time or two when setting up a new item. It would report Not Supported, or No data until I disabled and enabled it again. Then it would run fine.

      Zabbix should be accepting this vaule as an integer. If there is a decimal point involved (?) you would want a float.

      How about the "\n" business in the return value from your php script? Could that cause the agent to handle the value as a string?

      Comment

      • OneLoveAmaru
        Member
        • Jan 2008
        • 41

        #18
        tokind, one thing I am curious about.. how did you create a trigger without creating an item first? Your instructions don't show how to make the item. If I try to just make a trigger with no item, the zabbix server errors out on me when trying to save. Which makes sense because the item is what picks up the value and the trigger is what responds to that value. Do you have an item on yours? If so what values did you use to create it?

        Comment

        • OneLoveAmaru
          Member
          • Jan 2008
          • 41

          #19
          I did take the \n's off one of the servers I was running the script on with no go. I just took it off of another server I am testing on, so I will enable and disable it like you said and see what happens.

          Comment

          • tokind
            Member
            • May 2007
            • 47

            #20
            Ahh, you are right. My article does not mention the Items. It jumps from Host to Triggers. I'll edit the Wiki article to correct this. All triggers are based on Items. I didn't do anything magical there.


            Originally posted by OneLoveAmaru
            tokind, one thing I am curious about.. how did you create a trigger without creating an item first? Your instructions don't show how to make the item. If I try to just make a trigger with no item, the zabbix server errors out on me when trying to save. Which makes sense because the item is what picks up the value and the trigger is what responds to that value. Do you have an item on yours? If so what values did you use to create it?

            Comment

            • OneLoveAmaru
              Member
              • Jan 2008
              • 41

              #21
              can you send me a screenshot of your item and trigger for dns?

              Comment

              • tokind
                Member
                • May 2007
                • 47

                #22
                Kinda inefficient, but here you go.



                Comment

                • OneLoveAmaru
                  Member
                  • Jan 2008
                  • 41

                  #23
                  Yeah besides the names, everything you have is identical to mine. This is the weirdest thing.

                  I changed the logging to debug on the zabbix server, tried searching in the server logs for DNS1 and didn't find anything. Do you see anything in your server logs about sending the key out? I see other keys, but nothing about the key DNS1 in there.

                  Also, what version of zabbix agent and zabbix server are you running?

                  Comment

                  • OneLoveAmaru
                    Member
                    • Jan 2008
                    • 41

                    #24
                    This is what is in my logs now:

                    15177:20080708:171557 Requested [DNS1]
                    15177:20080708:171557 Before
                    15177:20080708:171557 Run remote command [php /etc/zabbix/alert.d/dnschk.php 192.168.2.1] Result [1] [1]...
                    15177:20080708:171557 Sending back [1]


                    but still UNKNOWN according to the zabbix server GUI. Command line returns a value of 1 as well.

                    Comment

                    • tokind
                      Member
                      • May 2007
                      • 47

                      #25
                      Doh! Your PHP script is returning a string instead of an integer! Take the quotes away:

                      Code:
                          if($failed)
                          {
                              echo 0;
                          } else {
                              echo 1;
                          }
                      Originally posted by OneLoveAmaru
                      Yeah besides the names, everything you have is identical to mine. This is the weirdest thing.

                      I changed the logging to debug on the zabbix server, tried searching in the server logs for DNS1 and didn't find anything. Do you see anything in your server logs about sending the key out? I see other keys, but nothing about the key DNS1 in there.

                      Also, what version of zabbix agent and zabbix server are you running?

                      Comment

                      • OneLoveAmaru
                        Member
                        • Jan 2008
                        • 41

                        #26
                        Tried, no cigar.

                        15474:20080708:181028 Requested [DNS1]
                        15474:20080708:181028 Before
                        15474:20080708:181028 Run remote command [php /etc/zabbix/alert.d/dnschk.php 192.168.2.1] Result [1] [1]...
                        15474:20080708:181028 Sending back [1]

                        I disabled, re-enabled, unlinked and cleared from the HOST, then added back, no go.

                        Comment

                        • OneLoveAmaru
                          Member
                          • Jan 2008
                          • 41

                          #27
                          Tokind, what is the exact script you are using? I want to try that, rule out if it's the script or my zabbix server that's the problem. You know yours works, so I should try it. Can you post it for me? Thanks a lot.

                          Comment

                          • OneLoveAmaru
                            Member
                            • Jan 2008
                            • 41

                            #28
                            If anyone is interested in how I did it, I think my way is better than all of these other ways AND I even supply you with a template to import.

                            Here is the script you want to use. You can make it look up as many DNS names to IP's as you want. Script returns a 0, it's good, if it's a 1, something failed.

                            Also, you need to have php-cli installed to run this script correctly. I use Debian/Ubuntu, apt-get install php5-cli works for me.

                            #!/usr/bin/php
                            <?php
                            // Define defaults
                            if($_SERVER[argv][1])
                            {
                            $ns_server = $_SERVER[argv][1];
                            } else {
                            echo "You need to supply a DNS server to check. Quitting.\n";
                            exit;
                            }

                            $hosts = array("zabbix.com" => "85.113.250.92",
                            "pizza.com" => "208.236.9.57",

                            // Do query
                            foreach($hosts as $host => $ip)
                            {
                            $result = shell_exec("dig +time=1 +tries=5 +short @".$ns_server." ".$host);
                            if(!preg_match('/'.$ip.'/', $result))
                            {
                            $failed = TRUE;
                            }
                            }

                            if($failed)
                            {
                            $val = 1;
                            } else {
                            $val = 0;
                            }
                            echo $val."\n";
                            ?>

                            Yes, you need to specify the DNS name and what IP it should map to. if your IP changes daily, you will need to modify this script a little to accommodate your needs.

                            You need to add this line to zabbix_agentd.conf:
                            UserParameter=custom.dns.check[*],/usr/bin/php /etc/zabbix/scripts/dnschk.php $1

                            The template is also generic and it is setup to query 3 name servers. If you want more, it's all you. if you want less, either delete or disable what you don't need. The IP's in the items are the name server IP's the script query. The IP's in the Triggers for each item need to match those in the items(had to say it for the n00bs). I also customized the name of the triggers a bit more than in this template, so the Monitoring page didn't just show me, DNS Check 1 and so on. I made mine DNS Check Nameserver. Nameserver being the actual name of the NS server.

                            Questions comments, I'm here.
                            Attached Files

                            Comment

                            • Alexei
                              Founder, CEO
                              Zabbix Certified Trainer
                              Zabbix Certified SpecialistZabbix Certified Professional
                              • Sep 2004
                              • 5654

                              #29
                              Not sure if this helps, but try replacing

                              echo $val."\n";

                              with

                              echo $val;
                              Alexei Vladishev
                              Creator of Zabbix, Product manager
                              New York | Tokyo | Riga
                              My Twitter

                              Comment

                              • OneLoveAmaru
                                Member
                                • Jan 2008
                                • 41

                                #30
                                Help what? What I posted works perfect. With this script you don't have to put 3 lines in your zabbix_agentd.conf to monitor 3 different name servers, just 1 line and then everything else can be configured from the GUI.

                                The only other thing you need to do is just configure your script with the servers you want to run the queries on. The 1 line you need in zabbix_agentd.conf just needs the path to wherever you decide to place the script and name it.

                                After you get it working on one server, it's really easy to roll out to other servers. Just need to copy the script to other servers and paste that line in the zabbix_agendt.conf file.
                                Last edited by OneLoveAmaru; 01-08-2008, 22:07.

                                Comment

                                Working...