[prev in list] [next in list] [prev in thread] [next in thread] 

List:       dhcp-users
Subject:    RE: running script at the time of address lease
From:       Denis Laventure <Denis_Laventure () uqac ! ca>
Date:       2011-02-14 13:53:20
Message-ID: 123B7A0675D6F14CAD2B8A35CECFA1CE010ADC4798 () exmbox-a ! uqac ! ca
[Download RAW message or body]

What about :

on commit { execute("command") }   ?

from dhcp-eval man page :

execute (command-path [, data-expr1, ... data-exprN]);

The execute statement runs an external command. The first argument is a string \
literal containing the name or path of the command to run. The other arguments, if \
present, are either string literals or data- expressions which evaluate to text \
strings, to be passed as command-line arguments to the command.

execute is synchronous; the program will block until the external command being run \
has finished. Please note that lengthy program execution (for example, in an "on \
commit" in dhcpd.conf) may result in bad performance and timeouts. Only external \
applications with very short execution times are suitable for use.

Passing user-supplied data to an external application might be dangerous. Make sure \
the external application checks input buffers for validity. Non-printable ASCII \
characters will be converted into dhcpd.conf language octal escapes ("777"), make \
sure your external command handles them as such.

It is possible to use the execute statement in any context, not only on events. If \
you put it in a regular scope in the configuration file you will execute that command \
every time a scope is evaluated. I'm running ISC DHCPD v. 4.2.0

Denis

De : dhcp-users-bounces+denis_laventure=uqac.ca@lists.isc.org \
[mailto:dhcp-users-bounces+denis_laventure=uqac.ca@lists.isc.org] De la part de Jon \
Otterholm Envoyé : 14 février 2011 06:20
À : Users of ISC DHCP
Objet : SV: running script at the time of address lease

The short answer is no, but there are ways to solve this.

I use the exec function in syslog to execute scripts upon lease/expire. You can \
configure dhcpd to do logging which includes the information you need (IP, MAC ...). \
Here is an example:

Dhcpd.conf
______
log-facility local6;

on commit { log(info, concat("commit", " ", binary-to-ascii(10, 8, ".", \
leased-address), " ", concat ( suffix (concat ("0", binary-to-ascii (16, 8, "", \
substring(hardware, 1, 1))),2),":", suffix (concat ("0", binary-to-ascii (16, 8, "", \
substring(hardware, 2, 1))),2),":", suffix (concat ("0", binary-to-ascii (16, 8, "", \
substring(hardware, 3, 1))),2),":", suffix (concat ("0", binary-to-ascii (16, 8, "", \
substring(hardware, 4, 1))),2),":", suffix (concat ("0", binary-to-ascii (16, 8, "", \
substring(hardware, 5, 1))),2),":", suffix (concat ("0", binary-to-ascii (16, 8, "", \
substring(hardware, 6, 1))),2) ), " ", "'", (option agent.circuit-id), "'"));
}

on expiry { log(info, concat("expiry", " ", binary-to-ascii(10, 8, ".", \
leased-address))); }

on release { log(info, concat("expiry", " ", binary-to-ascii(10, 8, ".", \
leased-address))); }
___________

Syslog.conf:
___
local6.debug                                    | exec /usr/bin/awk \
'$6=="commit"{system("/usr/scripts/commit.sh" " " $7 " " $8 " " $9)}' local6.debug    \
| exec /usr/bin/awk '$6=="expiry"{system("/usr/scripts/release.sh" " " $7 " " $8 " " \
$9)}' ___

As you can see dhcpd will log to local6.debug, syslog pipes info to awk that filters \
info and sends it to a script together with necessary variables. In this example it \
sends IP, MAC and Option-82 to the script.

This runs on our FreeBSD-routers and it works really well. ~1000 customers/router and \
the lease-time is set to max 60min giving us about 2000 leases to handle per hour.

The advantage to this solution is the elimination of patches of dhcpd.

Hope this info helps, good luck.

//Jon

Från: dhcp-users-bounces+jon.otterholm=ide.resurscentrum.se@lists.isc.org \
[mailto:dhcp-users-bounces+jon.otterholm=ide.resurscentrum.se@lists.isc.org] För \
                Tapan
Skickat: den 12 februari 2011 13:11
Till: dhcp-users@lists.isc.org
Ämne: running script at the time of address lease

Hi list,
 Is there any way to run a script from dhcpd after an address is assigned to a host ?

Regards,
Tapan


[Attachment #3 (text/html)]

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=Generator content="Microsoft \
Word 12 (filtered medium)"><style><!-- /* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p
	{mso-style-priority:99;
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
span.EmailStyle17
	{mso-style-type:personal;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=FR-CA link=blue vlink=purple><div \
class=WordSection1><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>What \
about&nbsp;:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>on commit { \
execute(</span><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&quot;command&quot;</span><span \
lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>) \
}   ?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>from \
dhcp-eval man page&nbsp;:<o:p></o:p></span></p><p><b><span lang=EN-US>execute \
(<i>command-path [, data-expr1, ... data-exprN]);</i></span></b><span lang=EN-US> \
<o:p></o:p></span></p><p><span lang=EN-US>The <b>execute</b> statement runs an \
external command. The first argument is a string literal containing the name or path \
of the command to run. The other arguments, if present, are either string literals or \
data- expressions which evaluate to text strings, to be passed as command-line \
arguments to the command. <o:p></o:p></span></p><p><b><span \
lang=EN-US>execute</span></b><span lang=EN-US> is synchronous; the program will block \
until the external command being run has finished. Please note that lengthy program \
execution (for example, in an &quot;on commit&quot; in dhcpd.conf) may result in bad \
performance and timeouts. Only external applications with very short execution times \
are suitable for use. <o:p></o:p></span></p><p><span lang=EN-US>Passing user-supplied \
data to an external application might be dangerous. Make sure the external \
application checks input buffers for validity. Non-printable ASCII characters will be \
converted into dhcpd.conf language octal escapes (&quot;777&quot;), make sure your \
external command handles them as such. <o:p></o:p></span></p><p><span lang=EN-US>It \
is possible to use the execute statement in any context, not only on events. If you \
put it in a regular scope in the configuration file you will execute that command \
every time a scope is evaluated.<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I&#8217;m \
running ISC DHCPD v. 4.2.0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Denis<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><div><div \
style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p \
class=MsoNormal><b><span lang=EN-US \
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De&nbsp;:</span></b><span \
lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> \
dhcp-users-bounces+denis_laventure=uqac.ca@lists.isc.org \
[mailto:dhcp-users-bounces+denis_laventure=uqac.ca@lists.isc.or</span><span lang=FR \
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>g] <b>De la part de</b> \
Jon Otterholm<br><b>Envoyé&nbsp;:</b> 14 février 2011 06:20<br><b>À&nbsp;:</b> Users \
of ISC DHCP<br><b>Objet&nbsp;:</b> SV: running script at the time of address \
lease<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p>&nbsp;</o:p></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The short \
answer is no, but there are ways to solve this.<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I use the \
exec function in syslog to execute scripts upon lease/expire. You can configure dhcpd \
to do logging which includes the information you need (IP, MAC &#8230;). Here is an \
example:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Dhcpd.conf<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>______<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>log-facility \
local6;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>on commit { \
log(info, concat(&quot;commit&quot;, &quot; &quot;, binary-to-ascii(10, 8, \
&quot;.&quot;, leased-address), &quot; &quot;, concat (<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>suffix \
(concat (&quot;0&quot;, binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 1, \
1))),2),&quot;:&quot;,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>suffix \
(concat (&quot;0&quot;, binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 2, \
1))),2),&quot;:&quot;,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>suffix \
(concat (&quot;0&quot;, binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 3, \
1))),2),&quot;:&quot;,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>suffix \
(concat (&quot;0&quot;, binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 4, \
1))),2),&quot;:&quot;,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>suffix \
(concat (&quot;0&quot;, binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 5, \
1))),2),&quot;:&quot;,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>suffix \
(concat (&quot;0&quot;, binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 6, \
1))),2)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>), &quot; \
&quot;, &quot;'&quot;, (option agent.circuit-id), \
&quot;'&quot;));<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>}<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>on expiry { \
log(info, concat(&quot;expiry&quot;, &quot; &quot;, binary-to-ascii(10, 8, \
&quot;.&quot;, leased-address)));<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>}<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>on release \
{ log(info, concat(&quot;expiry&quot;, &quot; &quot;, binary-to-ascii(10, 8, \
&quot;.&quot;, leased-address)));<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>}<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>___________<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Syslog.conf:<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>___<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>local6.debug \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n \
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
| exec /usr/bin/awk '$6==&quot;commit&quot;{system(&quot;/usr/scripts/commit.sh&quot; \
&quot; &quot; $7 &quot; &quot; $8 &quot; &quot; $9)}'<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>local6.debug \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n \
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
| exec /usr/bin/awk '$6==&quot;expiry&quot;{system(&quot;/usr/scripts/release.sh&quot; \
&quot; &quot; $7 &quot; &quot; $8 &quot; &quot; $9)}'<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>___<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>As you can \
see dhcpd will log to local6.debug, syslog pipes info to awk that filters info and \
sends it to a script together with necessary variables. In this example it sends IP, \
MAC and Option-82 to the script. <o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>This runs \
on our FreeBSD-routers and it works really well. ~1000 customers/router and the \
lease-time is set to max 60min giving us about 2000 leases to handle per \
hour.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The \
advantage to this solution is the elimination of patches of \
dhcpd.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hope this \
info helps, good luck.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>//Jon<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><div \
style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div \
style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p \
class=MsoNormal><b><span lang=EN-US \
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>Från:</span></b><span \
lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> \
dhcp-users-bounces+jon.otterholm=ide.resurscentrum.se@lists.isc.org \
[mailto:dhcp-users-bounces+jon.otterholm=ide.resurscentrum.se@lists.isc.org] <b>För \
</b>Tapan<br><b>Skickat:</b> den 12 februari 2011 13:11<br><b>Till:</b> \
dhcp-users@lists.isc.org<br><b>Ämne:</b> running script at the time of address \
lease<o:p></o:p></span></p></div></div><p class=MsoNormal><span \
lang=EN-US><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=SV>Hi \
list,<br>&nbsp;Is there any way to run a script from dhcpd after an address is \
assigned to a host ?<br><br>Regards,<br>Tapan<o:p></o:p></span></p></div></div></body></html>




_______________________________________________
dhcp-users mailing list
dhcp-users@lists.isc.org
https://lists.isc.org/mailman/listinfo/dhcp-users
--===============5833573959252159946==--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic