Ad Widget

Collapse

Supervise an DHCP Server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jguigot
    Junior Member
    • Mar 2008
    • 14

    #1

    Supervise an DHCP Server

    Hello,

    I would like to know if my server DHCP is up. But, i ping the physical host (windows server 2003) but i don't know if service DHCP is OK. You have an idea?
  • Tenzer
    Senior Member
    • Nov 2007
    • 316

    #2
    You will have to either query the DHCP server with some sort of DHCP client, in order to check if the server is running, or else check if the DHCP service is running.

    You could probably also check the latest entry in the service's logfile, in order to see if anything has been logged within the last X minutes, but that could bring false positives.

    Comment

    • Jguigot
      Junior Member
      • Mar 2008
      • 14

      #3
      OK Thanks, I try this now^^

      Comment

      • Kai-Kai
        Senior Member
        • Apr 2009
        • 142

        #4
        Hello.
        Were you successfull with this ?

        Comment

        • nelsonab
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Sep 2006
          • 1233

          #5
          About the only way to tell if DHCP is running is by checking how well it replies to a dhcp request. You could sniff for bootp packets, but writing a script is the better. The script would use the dhcptest tools for linux which to querie your DHCP server. I would write the tool to use a specific MAC address which is configured to expire quickly in the DHCP server. This way you don't accidentaly hork your leases.

          Pseudocode

          1)configure DHCP server to serve our bogus MAC 01:02:03:04:05:06 the ip address of 1.1.1.1

          2)query the DHCP server using the bogus MAC, set our timeout for replies to be somewhat low, say 10 seconds.

          3)time how long it takes to respond, or if it responded at all. If it did not respond set the return value of the timer to our timeouot value, 10 seconds in this case.

          4)Send the length of time back to the Zabbix server.
          RHCE, author of zbxapi
          Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
          Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

          Comment

          • Tenzer
            Senior Member
            • Nov 2007
            • 316

            #6
            I've made a small PHP snippet which runs the dhcping program (found as package in some OS's), and check the return value:
            PHP Code:
            #!/usr/bin/php
            <?
                // Do query
                $query = exec("dhcping -t 1 -c 192.168.0.2 -s 192.168.0.1 -h 01:02:03:04:05:06 2> /dev/null", $output, $return);

                if($return == 0) {
                    echo "TRUE\n";
                } else {
                    echo "FALSE\n";
                }
            ?>
            You will however have to modify the IP addresses and MAC address to match the informations of the host you are monitoring from and to.

            Comment

            • rover
              Junior Member
              • Apr 2023
              • 1

              #7
              I tried dhcping and it's seriously broken for me.

              I've downloaded https://code.activestate.com/recipes/577649-dhcp-query/ modified a bit to return "ok" or "timeout" and put a cron job to run it every minute and write the output in a file.
              Then a userparameter for zabbix-agent that gets the file contents.

              Comment

              • Simon74
                Junior Member
                • Oct 2021
                • 6

                #8
                My idea would be to use nmap on zabbix-server for this task.

                ok my test:

                1. apt install nmap (on zabbix host)
                2. visudo: zabbix ALL=(ALL:ALL) NOPASSWD:/usr/bin/nmap
                3. import template
                4. set the macro in template {$DHCP_SUBNET}
                5. add the template (DHCP Discover with nmap) to the Zabbix server host​

                the template file (zbx_export_templates.yaml):
                Code:
                zabbix_export:
                  version: '6.4'
                  template_groups:
                    - uuid: 0b1e511f04504972a86074e86b5cc43d
                      name: Services/DHCP
                  templates:
                    - uuid: 5d6379397696470d9d8e76da6c6a1250
                      template: 'DHCP Discover with nmap'
                      name: 'DHCP Discover with nmap'
                      groups:
                        - name: Services/DHCP
                      items:
                        - uuid: 1f90fa3ac2454446b5a414f99eb4bad6
                          name: 'DHCP Server (get ip)'
                          key: 'system.run[sudo nmap -Pn --script broadcast-dhcp-discover {$DHCP_SUBNET} | grep "IP Offered" | wc -l]'
                          delay: 3m
                          valuemap:
                            name: 'Service state'
                          tags:
                            - tag: Application
                              value: 'DHCP Server'
                          triggers:
                            - uuid: 1e7f6240499145329a8493cddfd2f72f
                              expression: 'last(/DHCP Discover with nmap/system.run[sudo nmap -Pn --script broadcast-dhcp-discover {$DHCP_SUBNET} | grep "IP Offered" | wc -l])=0'
                              name: 'DHCP Server down'
                              priority: DISASTER
                              description: 'DHCP Server down'
                              manual_close: 'YES'
                      macros:
                        - macro: '{$DHCP_SUBNET}'
                          value: 10.8.0
                      valuemaps:
                        - uuid: d1986d8fe8c64401ba46de595ef05ba2
                          name: 'Service state'
                          mappings:
                            - value: '0'
                              newvalue: Down
                            - value: '1'
                              newvalue: Up
                ​
                Testing, shutdown the dhcp server daemons..
                When dhcp servers down, the nmap broadcast takes a while, so the timeout for scripts in zabbix_agent must be i set higher! (Timeout=15)

                Last edited by Simon74; 14-01-2024, 21:41.

                Comment

                Working...