Ad Widget

Collapse

Linux DNS Server monitoring (Bind,named)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Linux DNS Server monitoring (Bind,named)

    Linux DNS Server (Bind,named) http://www.isc.org/software/bind

    I use bind util
    /usr/sbin/rndc stats
    This command write statistics in file /var/named/chroot/var/named/named.stats (run from zabbix_bind_stats.pl)
    Script /etc/zabbix/zabbix_bind_stats.pl write statistics for Zabbix in file /tmp/zabbix_named.stats.txt

    Permissions on script /etc/zabbix/zabbix_bind_stats.pl
    Code:
     chmod 4755 zabbix_bind_stats.pl
    ls -l zabbix_bind_stats.pl
    -rwsr-xr-x  1 root root 1585 Mar 18 12:06 zabbix_bind_stats.pl
    Install perl-suidperl rpm!!!!!

    Bind configuration:
    /var/named/chroot/etc/named.conf
    Code:
    options {
    	…
            statistics-file "/var/named/named.stats";
    	…
    	}
    named.stats format is
    Code:
    +++ Statistics Dump +++ (1300812291)
    success 1843046927
    referral 96446157
    nxrrset 188937348
    nxdomain 658140493
    recursion 1158184815
    failure 1373105359
    --- Statistics Dump --- (1300812291)
    zabbix_named.stats.txt format is
    Code:
    date: 1301655089 Fri Apr  1 14:51:29 2011
    success: 30547529
    referral: 834977
    nxrrset: 3616500
    nxdomain: 14214245
    recursion: 15199447
    failure: 15493181
    Zabbix_agent configuration:
    /etc/zabbix/zabbix_agentd.conf
    Code:
    Timeout=30
    ## Named monitoring
    UserParameter=named_stat,/etc/zabbix/zabbix_bind_stats.pl
    UserParameter=named_success,egrep "success:" /tmp/zabbix_named.stats.txt| awk '{print $2}'
    UserParameter=named_referral,egrep "referral:" /tmp/zabbix_named.stats.txt| awk '{print $2}'
    UserParameter=named_nxrrset,egrep "nxrrset:" /tmp/zabbix_named.stats.txt| awk '{print $2}'
    UserParameter=named_nxdomain,egrep "nxdomain:" /tmp/zabbix_named.stats.txt| awk '{print $2}'
    UserParameter=named_recursion,egrep "recursion:" /tmp/zabbix_named.stats.txt| awk '{print $2}'
    UserParameter=named_failure,egrep "failure:" /tmp/zabbix_named.stats.txt| awk '{print $2}'
    UserParameter=named_udp,netstat -nua | grep :53 | wc -l
    UserParameter=named_tcp,netstat -nta | grep :53 | wc -l
    ## End Named monitoring
    Example:
    Click image for larger version

Name:	chart2.jpg
Views:	1
Size:	49.8 KB
ID:	315664
    Click image for larger version

Name:	chart3.jpg
Views:	1
Size:	60.3 KB
ID:	315665
    Attached Files
    Last edited by dima_dm; 01-04-2011, 12:46.

    #2
    This is a great idea!
    But if local scripts are involved already I prefer to let them handle all itself without the agent and use zabbix_sender.

    IMHO it is better, but maybe someone can explain me otherwise.
    No change in zabbix_agentd.conf

    # ln -s /usr/local/sbin/zabbix-bind /etc/cron.min/zabbix-bind
    # chmod +x /usr/local/sbin/zabbix-bind
    # cat /usr/local/sbin/zabbix-bind
    Code:
    #!/bin/sh
    export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
    
    ZAB_CONF=/etc/zabbix/zabbix_agentd.conf
    ZAB_BIN=/usr/local/sbin/zabbix_sender
    RNDC_BIN='/usr/sbin/rndc'
    STATS='/var/cache/bind/named.stats'
    FTMP1=`mktemp`
    
    if $RNDC_BIN stats ; then
      if [ -s ${STATS} ] ; then
        tail -n12 ${STATS} 2>/dev/null | grep -A12 '^+++' | grep '^[a-z]' | sed 's/.*/- named_&/' >${FTMP1}
        if tty >/dev/null ; then
          $ZAB_BIN -vv -c ${ZAB_CONF} -i ${FTMP1}
        else
          $ZAB_BIN -c ${ZAB_CONF} -i ${FTMP1} >/dev/null
        fi
      elif tty >/dev/null ; then
        echo "${STATS} does not exist!" >&2
      fi
    fi
    rm -f ${FTMP1}
    I do hope the OP welcomes this different approach as I have no intention to offend him, nor to hijack his thread.
    It does need some changes in the template as the items are now of type 'zabbix_trapper' and not 'zabbix_agent'.
    Attached Files
    Last edited by frater; 18-01-2011, 17:50.
    Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

    Comment


      #3
      Originally posted by frater View Post
      IMHO it is better, but maybe someone can explain me otherwise.
      In such way I can supervise as the script is executed. If there will be any problems, I at once shall receive a error code on Zabbix (wrong permissions, absence of necessary programs and modules etc).

      Comment


        #4
        Originally posted by dima_dm View Post
        In such way I can supervise as the script is executed. If there will be any problems, I at once shall receive a error code on Zabbix (wrong permissions, absence of necessary programs and modules etc).
        {Template_App_named:named_success.nodata(180)}=1

        I added a trigger that will react when it has less than 10 resolves per second during work hours and less than 1 off hours (both disabled by default).

        Another trigger that will notify you if it didn't receive data the last 3 minutes. The latter will also notify you the script isn't working as it should.
        Attached Files
        Last edited by frater; 18-01-2011, 16:30.
        Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

        Comment


          #5
          Originally posted by frater View Post
          {Template_App_named:named_success.nodata(180)}=1
          I know and use this trigger too.
          But I can send error code also with detail problem description.
          See example:
          http://www.zabbix.com/forum/showthread.php?t=15691
          0 OK
          1 VMWare client error
          2 Status file write error
          3 bad username or password
          4 Can't connect to ESXi
          5 Can't get data from ESXi

          Comment


            #6
            Originally posted by dima_dm View Post
            I know and use this trigger too.
            But I can send error code also with detail problem description.
            See example:
            http://www.zabbix.com/forum/showthread.php?t=15691
            0 OK
            1 VMWare client error
            2 Status file write error
            3 bad username or password
            4 Can't connect to ESXi
            5 Can't get data from ESXi
            I may not have a good idea how you work with zabbix, but I can't see the use of it. It works or it doesn't and if it doesn't there's something wrong with the config and you need to troubleshoot it. That machine is being monitored by an agent and if there's something wrong with the machine I will get other messages.
            I'm getting messages if /etc/zabbix/zabbix_agentd.conf changes, there are errors in /var/log/zabbix/zabbix_agentd.conf.

            Anyway... Thanks for the idea. I guess we have all different ideas about what's a good way to implement things.
            When I saw an example of someone using the zabbix_sender I had some difficulties to implement them for the first time. I now know the pitfalls and prefer it in some situations.
            Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

            Comment


              #7
              Hello,

              Thanks you for the script but i can't make it work.

              Indeed this the result of "more /tmp/zabbix_named.stats.txt" after executed the perl script:

              date: 1300801289 Tue Mar 22 14:41:29 2011
              success:
              referral:
              nxrrset:
              nxdomain:
              recursion:
              failure:

              I think my named.states format is different of your .

              ++ Name Server Statistics ++
              12278 IPv4 requests received
              126 requests with EDNS(0) received
              12278 responses sent
              126 responses with EDNS(0) sent
              4224 queries resulted in successful answer
              12273 queries resulted in authoritative answer
              5 queries resulted in non authoritative answer
              4049 queries resulted in nxrrset
              4005 queries resulted in NXDOMAIN
              4 queries caused recursion

              The regex are differents ...

              I can change the regex, but i don't understand the role of $position variable in your perl script.

              Can you help me ?


              Many thanks !
              Last edited by Zophren; 22-03-2011, 15:58.

              Comment


                #8
                Yes. My named.stats format is
                Code:
                +++ Statistics Dump +++ (1300812291)
                success 1843046927
                referral 96446157
                nxrrset 188937348
                nxdomain 658140493
                recursion 1158184815
                failure 1373105359
                --- Statistics Dump --- (1300812291)

                Originally posted by Zophren View Post
                but i don't understand the role of $position variable in your perl script.
                $position is used to clear file named.stats if size of file named.stats >$maxsize.
                And $position is used for performance optimization. We will use only last statistics sample. For what reason will we parse all file named.stats, when we can process only last statistics sample (I am assume, that one statistics sample can't take more than $data=300 Byte)?
                Last edited by dima_dm; 23-03-2011, 08:06.

                Comment


                  #9
                  Linux DNS Server monitoring (Bind,named)

                  Hi,

                  Thanks for the perl script. As suggested in the script I upgraded my perl-suidperl to version 5.8.5-36.

                  However when I run the script manually I get proper output in /tmp/zabbix_named.stat.txt. Same as you get in yours.

                  But when the same script actually gets executed through the agent it throws blank values. I am puzzled.

                  Any ideas why it must be happening ?

                  Thanks.

                  --
                  Shriram

                  Comment


                    #10
                    run as
                    su - zabbix
                    /etc/zabbix/zabbix_bind_stats.pl

                    Comment


                      #11
                      Linux DNS Server monitoring(Bind,named)

                      Thanks for the reply.

                      I have disabled my zabbix userid shell with /sbin/nologin.

                      I changed that to a valid shell. Zabbix user is without password. I have set the password. My /etc/rndc.conf was having read permission to group named, so added zabbix user to named group in /etc/group. After this when I do

                      su - zabbix
                      /opt/zabbix/sbin/zabbix_bind_stats.pl

                      It worked and gave me proper output in /tmp/zabbix_named_stats.txt

                      However when the same thing runs through agent still gives me blank values.

                      I reverted back again the zabbix user to /sbin/nologin shell and removed zabbix password.

                      Still the same status. In the zabbix_agent.log it throws the error :

                      rnd: error: /etc/rndc.conf:33: open: /etc/rndc.key: permission denied.

                      I even tried changing the permissions of /etc/rndc.conf to 644, but still the same status.

                      Comment


                        #12
                        Linux DNS Server monitoring(Bind,named)

                        I restarted the zabbix_agent on the client and now the data is coming correct.

                        Thanks for all the help and this beautiful script with template.

                        Comment


                          #13
                          named.stats new format

                          Hey. Tx for this script.

                          Since you made it, the format of named.stats changed.

                          Could anyone adapt the script to the new format ? I'm not that good in Perl scripting

                          Would appreciate any help.

                          Here is the new format:

                          Code:
                          +++ Statistics Dump +++ (1359329765)
                          ++ Incoming Requests ++
                                            20 QUERY
                          ++ Incoming Queries ++
                                             9 A
                                             3 PTR
                                             8 AAAA
                          ++ Outgoing Queries ++
                          [View: default]
                          [View: _bind]
                          ++ Name Server Statistics ++
                                            20 IPv4 requests received
                                             9 recursive queries rejected
                                            20 responses sent
                                             7 queries resulted in successful answer
                                            11 queries resulted in authoritative answer
                                             4 queries resulted in nxrrset
                                             9 other query failures
                          ++ Zone Maintenance Statistics ++
                                            18 IPv4 notifies sent
                          ++ Resolver Statistics ++
                          [Common]
                          [View: default]
                          [View: _bind]
                          ++ Cache DB RRsets ++
                          [View: default]
                          [View: _bind (Cache: _bind)]
                          ++ Socket I/O Statistics ++
                                             5 UDP/IPv4 sockets opened
                                             2 TCP/IPv4 sockets opened
                                             1 TCP/IPv6 sockets opened
                                             4 UDP/IPv4 sockets closed
                                             2 TCP/IPv4 sockets closed
                                             3 TCP/IPv4 connections accepted
                                            12 UDP/IPv4 send errors
                          ++ Per Zone Query Statistics ++
                          --- Statistics Dump --- (1359329765)

                          Comment


                            #14
                            I agree, stats file has different format, script doesn't work.
                            Please update script... thanx!

                            My stats file is in the attachment.
                            Attached Files

                            Comment


                              #15
                              Originally posted by skygge View Post
                              I agree, stats file has different format, script doesn't work.
                              Please update script... thanx!

                              My stats file is in the attachment.
                              See Linux DNS Server monitoring LLD (Bind 9.6.X and high,named)
                              https://www.zabbix.com/forum/showthread.php?t=38970

                              Comment

                              Announcement

                              Collapse
                              No announcement yet.
                              Working...
                              X