Koozali.org: home of the SME Server

how to track the work of the DHCP Server?

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
how to track the work of the DHCP Server?
« Reply #30 on: March 11, 2007, 10:37:35 PM »
Quote from: "TeNeCo"

It would be nice if a certain MAC address would get always the same IP from the DHCP server.


Hostnames and addresses panel. Have you read the User Manual?

Offline TeNeCo

  • ***
  • 60
  • +0/-0
how to track the work of the DHCP Server?
« Reply #31 on: March 18, 2007, 09:48:42 AM »
Fine.

And how can I add the call of the script to the suface of the server-manager?

Offline cjensen

  • *
  • 133
  • +0/-0
    • http://acenet-tech.org
how to track the work of the DHCP Server?
« Reply #32 on: May 13, 2007, 06:40:59 AM »
For the server-manager to display your dhcp data you would require a 'panel' (see the dev manual).

I have a nice script which will display this info in a browser.  Let me know if you are interested.

Craig

Offline rick1908

  • ***
  • 56
  • +0/-0
    • http://theevansfamily.com/
Re: how to track the work of the DHCP Server?
« Reply #33 on: December 07, 2007, 08:24:51 PM »
What i did was:

Create a directory called /opt/dhcpactive

Put the dhcpactiv.sh script in there:

Code: [Select]
#!/bin/sh
#
# dhcpactiv.sh
#
# v.004
# - rewritten again to pull data from dhcpd files according to labels instead of position
#
# v.003
# - add code to remove tstp information from dpcpd.leases
#
# v.002
# - rewritten to use awk more for parsing
# - added "GMT" indicator to Expiration col head
#
date

echo "Source        Host                      MAC Address            IP Address      Expiration (GMT)"
echo "============= ========================= ====================== =============== ================"
#
awk ' { out = ""} \
      { $1=="lease"||$1=="client-hostname" ? out=" " $2 : out=out } \
      { $1=="binding"||$1=="hardware" ? out= " " $3: out=out } \
      { $1=="ends"? out=" " $3 " " $4: out=out } \
      { $1=="}"? out="\n": out=out } \
      { printf out," " }' /var/lib/dhcp/dhcpd.leases \
  | grep active \
  | sed -e s/'[{};" ]'/\ /g  \
  | awk '{ printf "%-13s %-25s %-22s %-15s %-10s %-5s\n", "dhcpd.leases", $6, $5, $1, $2, $3 }'

#
# Now do the same for /etc/dhcpd.conf~
#
 awk ' { out = ""}
       { $1=="host"||$1=="fixed-address" ? out=" " $2 : out=out } \
       { $1=="hardware" ? out= " " $3: out=out } \
       { $1=="}"? out="\n": out=out } \
       { printf out," " }' /etc/dhcpd.conf \
  | grep : \
  | sed -e  s/'[{};\" ]'/\ /g -e  s/\.`config get DomainName`// \
  | awk  '{ printf "%-13s %-25s %-22s %-15s %-15s \n", "dhcpd.conf", $1, $2, $3, "reservation"}'
#
# Finally, grab the current arp table
#
arp -a \
  |  sed -e s/\\..*\(/\ / -e s/\)// \
  |  awk '{ printf "%-13s %-25s %-22s %-15s %-15s \n", "arp", $1, $4, $2, "n/a"}'

Note I changed the script ever so slightly to include the current date/time in the output as well as making the columns for the output just a little bit wider so it was easier to read.

Then created another script called dhcplog:
Code: [Select]
#!/bin/sh
#
# Creats a log file from the dhcpactiv.sh script
./dhcpactiv.sh > ./dhcpleases.now


Which simply writes the output to a file in the /opt/dhcpactive directory.

Then, I created a symbolic link from /opt/dhcpactive/dhcpleases.now to /var/log

Code: [Select]
ln -s /opt/dhcpactive/dhcpleases.now /var/log/dhcpleases.now
Finally, I used Stephen Nobels dungog-cron contrib. http://www.dungog.net/wiki/Dungog-cron to create a cron job that runs every 5 mins to update the /opt/dhcpactive/dhcpleases.now file. I can now take a look at it in the server-manager Administration -> View log files panel.

-Rick
Seeeeeeeeeeeeeeee ya,
Rick :pint: