Solved

DHCP Scripr error

Posted on 2007-03-25
25
508 Views
Last Modified: 2008-02-01
Hi,

I have a DHCP vb script but gives an error can any one help me in this.

'**** DHCP Server Log Checking Script
'**** Copyright © 2005 Chris Pratt
'**** You may use this script free of charge but may not make any changes except to the variables to meet your needs
'**** without the permission of the author.
'****
'****
'**** The script is best set-up to run as a scheduled task. It can check for any event ID in the DHCP Server logs.
'**** It does not need to run on the DHCP server but you will need the full UNC path and the user that the script
'**** is set to run as will need rights to the servers log file areas.
'****
'**** The time interval is configurable and your scheduled task running time should be set to match that so areas of the
'**** logs don't go unchecked.

'Variables

strfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\inexchange1\c$\WINDOWS\system32\dhcp\dhcpsrvlog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@***.com" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject
objCDOMail.From = "sharath.reddy@***.com" 'E-mail from address (needs to be a valid address)
objCDOMail.From    =  "SYSTEM <INEXCHANGE1.***.co.uk>" ' E-mail from address (needs to be a valid address)

'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
set objCDOMail = CreateObject("CDONTS.NewMail")
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0
      
strline = objtextfile.readline

if instr(strline, "ID Date,Time,Description,IP Address,Host Name,MAC Address") then
            strline = objtextfile.readline
      else

      end if

if instr(strline, ",") then
            arrdhcprecord = split(strline, ",", 7)
            ceventid = arrdhcprecord(0)
            ceventdte = arrdhcprecord(1)
            ceventtime = arrdhcprecord(2)
            ceventdesc = arrdhcprecord(3)
            ceventip = arrdhcprecord(4)
            ceventhost = arrdhcprecord(5)
            ceventmac = arrdhcprecord(6)
      else

      End if
      i=i+1

findtime = datediff("n", ceventtime, strfindtime)

if findtime < intfindtime then
            posfind = posfind + 1
      else

      end if

if ceventid = streventid then
            posfind = posfind + 1
else

end if

if posfind = 2 then
            strBody = "===================" & vbCrLf
            strBody = strBody & " DHCP Server Alert" & vbCrLf
            strBody = strBody & "===================" & vbCrLf
            strBody = strBody & vbCrLf
            strBody = strBody & "Event ID: " & ceventid & vbCrLf
            strBody = strBody & "Date: " & ceventdte & vbCrLf
            strBody = strBody & "Time: " & ceventtime & vbCrLf
            strBody = strBody & "Desc: " & ceventdesc & vbCrLf
            strBody = strBody & "IP: " & ceventip & vbCrLf
            strBody = strBody & "Host: " & ceventhost & vbCrLf
            strBody = strBody & "Mac:" & ceventmac & vbCrLf
            objCDOMail.To      = strTo
            objCDOMail.Subject = strSubject
            objCDOMail.Body    = strBody
            objCDOMail.Send
      else

      end if

loop
objtextfile.close
Set objCDOMail = Nothing
0
Comment
Question by:bsharath
  • 14
  • 11
25 Comments
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18790883
Please tell us what is the error you are getting while executing this script
0
 
LVL 11

Author Comment

by:bsharath
ID: 18790998
---------------------------
Windows Script Host
---------------------------
Script:      C:\Documents and Settings\sharathr\Desktop\dhcpchecker_287\dhcpchecker.vbs
Line:      23
Char:      1
Error:      Object required: ''
Code:      800A01A8
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18791088
Create another variable on line 23 and 24;

Line 23, and 24 to after line 30 where you have written "set objCDOMail = CreateObject("CDONTS.NewMail")"

this will help

this error was because you have tried to use the object "objCDOMail" before initializing it.
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18791092
you can create variable to define to and from email address.

use these variables in the form.

objCDOMail.From = variable1
objCDOMail.From    = variable2
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18791102
change this portion of script



'Variables

estrfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\inexchange1\c$\WINDOWS\system32\dhcp\dhcpsrvlog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@***.com" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject
objCDOMail.From = "sharath.reddy@***.com" 'E-mail from address (needs to be a valid address)
objCDOMail.From    =  "SYSTEM <INEXCHANGE1.***.co.uk>" ' E-mail from address (needs to be a valid address)

'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
set objCDOMail = CreateObject("CDONTS.NewMail")
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0




to




'Variables

strfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\inexchange1\c$\WINDOWS\system32\dhcp\dhcpsrvlog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@***.com" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject



'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
set objCDOMail = CreateObject("CDONTS.NewMail")
objCDOMail.From = strTo 'you have already defined the email-to field
objCDOMail.From    =  "SYSTEM <INEXCHANGE1.***.co.uk>" ' E-mail from address (neds to be a valid address)
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0



this should work :)
0
 
LVL 11

Author Comment

by:bsharath
ID: 18791722
mailtosinghs:
Now i get this error

C:\>cscript a.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\a.vbs(88, 3) (null): 0x80040108
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18791781
this error is related to CDONTS

can you tell me what is on 88th line in that file...



0
 
LVL 11

Author Comment

by:bsharath
ID: 18791813
This is from the first line

strBody = strBody & "===================" & vbCrLf


Or started count from 'Variables

if posfind = 2 then
            strBody = "===================" & vbCrLf
            strBody = strBody & " DHCP Server Alert" & vbCrLf
            strBody = strBody & "===================" & vbCrLf
            strBody = strBody & vbCrLf
            strBody = strBody & "Event ID: " & ceventid & vbCrLf
            strBody = strBody & "Date: " & ceventdte & vbCrLf
            strBody = strBody & "Time: " & ceventtime & vbCrLf
            strBody = strBody & "Desc: " & ceventdesc & vbCrLf
            strBody = strBody & "IP: " & ceventip & vbCrLf
            strBody = strBody & "Host: " & ceventhost & vbCrLf
            strBody = strBody & "Mac:" & ceventmac & vbCrLf
            objCDOMail.To      = strTo
            objCDOMail.Subject = strSubject
            objCDOMail.Body    = strBody
            objCDOMail.Send
      else


Else is on the 80th line
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18791835
please mail me this in .txt attachment to my user name here  at yahoo dot com

0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18791846
I dont know whether posting email address for attachments are allowed or not;
alternatively you can paste the entire script here again
0
 
LVL 11

Author Comment

by:bsharath
ID: 18792031
Here is the full script


'**** DHCP Server Log Checking Script
'**** Copyright © 2005 Chris Pratt
'**** You may use this script free of charge but may not make any changes except to the variables to meet your needs
'**** without the permission of the author.
'****
'****
'**** The script is best set-up to run as a scheduled task. It can check for any event ID in the DHCP Server logs.
'**** It does not need to run on the DHCP server but you will need the full UNC path and the user that the script
'**** is set to run as will need rights to the servers log file areas.
'****
'**** The time interval is configurable and your scheduled task running time should be set to match that so areas of the
'**** logs don't go unchecked.
'Variables

strfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\in-ads-srv02\c$\WINNT\system32\dhcp\DhcpSrvLog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject



'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
set objCDOMail = CreateObject("CDONTS.NewMail")
objCDOMail.From = strTo 'you have already defined the email-to field
objCDOMail.From    =  "SYSTEM <sharath.reddy@com>" ' E-mail from address (neds to be a valid address)
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0

      
strline = objtextfile.readline

if instr(strline, "ID Date,Time,Description,IP Address,Host Name,MAC Address") then
            strline = objtextfile.readline
      else

      end if

if instr(strline, ",") then
            arrdhcprecord = split(strline, ",", 7)
            ceventid = arrdhcprecord(0)
            ceventdte = arrdhcprecord(1)
            ceventtime = arrdhcprecord(2)
            ceventdesc = arrdhcprecord(3)
            ceventip = arrdhcprecord(4)
            ceventhost = arrdhcprecord(5)
            ceventmac = arrdhcprecord(6)
      else

      End if
      i=i+1

findtime = datediff("n", ceventtime, strfindtime)

if findtime < intfindtime then
            posfind = posfind + 1
      else

      end if

if ceventid = streventid then
            posfind = posfind + 1
else

end if

if posfind = 2 then
            strBody = "===================" & vbCrLf
            strBody = strBody & " DHCP Server Alert" & vbCrLf
            strBody = strBody & "===================" & vbCrLf
            strBody = strBody & vbCrLf
            strBody = strBody & "Event ID: " & ceventid & vbCrLf
            strBody = strBody & "Date: " & ceventdte & vbCrLf
            strBody = strBody & "Time: " & ceventtime & vbCrLf
            strBody = strBody & "Desc: " & ceventdesc & vbCrLf
            strBody = strBody & "IP: " & ceventip & vbCrLf
            strBody = strBody & "Host: " & ceventhost & vbCrLf
            strBody = strBody & "Mac:" & ceventmac & vbCrLf
            objCDOMail.To      = strTo
            objCDOMail.Subject = strSubject
            objCDOMail.Body    = strBody
            objCDOMail.Send
      else

      end if

loop
objtextfile.close
Set objCDOMail = Nothing
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18792090
Use the modified script. I have moved set objcdomail.... to inside the while loop



'**** DHCP Server Log Checking Script
'**** Copyright © 2005 Chris Pratt
'**** You may use this script free of charge but may not make any changes except to the variables to meet your needs
'**** without the permission of the author.
'****
'****
'**** The script is best set-up to run as a scheduled task. It can check for any event ID in the DHCP Server logs.
'**** It does not need to run on the DHCP server but you will need the full UNC path and the user that the script
'**** is set to run as will need rights to the servers log file areas.
'****
'**** The time interval is configurable and your scheduled task running time should be set to match that so areas of the
'**** logs don't go unchecked.
'Variables

strfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\in-ads-srv02\c$\WINNT\system32\dhcp\DhcpSrvLog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@isc.com" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject



'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0

     
strline = objtextfile.readline

if instr(strline, "ID Date,Time,Description,IP Address,Host Name,MAC Address") then
            strline = objtextfile.readline
      else

      end if

if instr(strline, ",") then
            arrdhcprecord = split(strline, ",", 7)
            ceventid = arrdhcprecord(0)
            ceventdte = arrdhcprecord(1)
            ceventtime = arrdhcprecord(2)
            ceventdesc = arrdhcprecord(3)
            ceventip = arrdhcprecord(4)
            ceventhost = arrdhcprecord(5)
            ceventmac = arrdhcprecord(6)
      else

      End if
      i=i+1

findtime = datediff("n", ceventtime, strfindtime)

if findtime < intfindtime then
            posfind = posfind + 1
      else

      end if

if ceventid = streventid then
            posfind = posfind + 1
else

end if

if posfind = 2 then
            strBody = "===================" & vbCrLf
            strBody = strBody & " DHCP Server Alert" & vbCrLf
            strBody = strBody & "===================" & vbCrLf
            strBody = strBody & vbCrLf
            strBody = strBody & "Event ID: " & ceventid & vbCrLf
            strBody = strBody & "Date: " & ceventdte & vbCrLf
            strBody = strBody & "Time: " & ceventtime & vbCrLf
            strBody = strBody & "Desc: " & ceventdesc & vbCrLf
            strBody = strBody & "IP: " & ceventip & vbCrLf
            strBody = strBody & "Host: " & ceventhost & vbCrLf
            strBody = strBody & "Mac:" & ceventmac & vbCrLf
            set objCDOMail = CreateObject("CDONTS.NewMail")
            objCDOMail.From    =  "SYSTEM <sharath.reddy@i.com>" ' E-mail from address (neds to be a valid address)
            objCDOMail.To      = strTo
            objCDOMail.Subject = strSubject
            objCDOMail.Body    = strBody
            objCDOMail.Send
            Set objCDOMail = Nothing
      else

      end if

loop
objtextfile.close
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 11

Author Comment

by:bsharath
ID: 18792174
Hi

Some thing went on it came out without any error but how do i find it is working.
Until you have understood can you tell me what this script does
THX
Sharath
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18792216
if you wnat to know that it went into the loop or not you can insert the line

WScript.Echo "some text"

and run the script again, you should see the echo message while the script in loop.

if this was not what you need, please specify the qn again clearly
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18792226
please insert above line before the

objCDOMail.Send
0
 
LVL 11

Author Comment

by:bsharath
ID: 18792322
I got a box containing "Sometext"

But where will i get the result.I now that this is correct but where can i see the result.

THX
For replying so patiently.

THX
Sharath
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18792365
You will get the result in the email address mentioned in the script which is sharath.reddy@isc.com here.

For a successful email, you need direct internet connectivity of the system where this script is running, or you have to setup intranet properly
0
 
LVL 11

Author Comment

by:bsharath
ID: 18792432
This mail will come when ever a error is encountered on the server or ?? Is there any wany i can genetrate a faulse error or through the script can we send a test mail.
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18792560
this will send a mail if you have eventid 10 in today's dhcp log in past 30 min.

if you want to generate an email do this:.....

open
\\in-ads-srv02\c$\WINNT\system32\dhcp\DhcpSrvLog." & strtoday
for this go to the folder "\\in-ads-srv02\c$\WINNT\system32\dhcp\"
open today's logfile dhcpsrvlog.mon if day is monday
you will find following texts after scrolling some lines


ID Date,Time,Description,IP Address,Host Name,MAC Address
00,04/19/99,12:43:06,Started,,,
60,04/19/99,12:43:21,No DC is DS Enabled,,MYDOMAIN,
63,04/19/99,12:43:28,Restarting rogue detection,,,
01,04/19/99,13:11:13,Stopped,,,
00,04/19/99,12:43:06,Started,,,
55,04/19/99,12:43:54,Authorized(servicing),,MYDOMAIN,

change 10 in following line of code to 00 in the script file.
streventid = "10"


stop and restart the dhcp service.
rerun the script


please remove the line
WScript.Echo "some text"
or change this to a comment
0
 
LVL 8

Expert Comment

by:mailtosinghs
ID: 18792564
the log text i have posted is a sample, you may find different texts but in same format
0
 
LVL 11

Author Comment

by:bsharath
ID: 18792772
In the log file what should i change
0
 
LVL 11

Author Comment

by:bsharath
ID: 18792798
I have changed all 10 to 00 the restart the DHCP service the ran the script but did not receive any mails

THX
Sharath
0
 
LVL 8

Accepted Solution

by:
mailtosinghs earned 500 total points
ID: 18792902
CDONTS is not able to send mail to the the recipient.

CDONTS is older version and not recommended. CDOSYS is now used in place of CDONTS and is more reliable and configurable.
you should use CDOSYS to send mail using an SMTP server in your intranet where the ip of your system (where the script is executing) is  allowed to relay mails.

for cdosys example search cdosys examples in google.


http://kb.webecs.com/Article.aspx?id=10169&cNode=7U0G0Q
http://www.pacificonline.com/SmarterTicket/Customer/KBArticle.aspx?articleid=36&KBSearchID=16275
0
 
LVL 11

Author Comment

by:bsharath
ID: 18792937
Hi,

I have no clue on what you said now sorry to say i dont know anything about scripting.Please help me in this regard.

THX
Sharath
0
 
LVL 11

Author Comment

by:bsharath
ID: 18890149
Thanks for the support.Even though i havent got the solution i am closing the question
0

Featured Post

Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

Join & Write a Comment

This is my 3rd article on SCCM in recent weeks, the 1st (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/A_4466-A-beginners-guide-to-installing-SCCM2007-on-Windows-2008-R2-Server.html) dealing with installat…
On a regular basis I get questions about slow RDP performance, RDP connection problems, strange errors and even BSOD, remote computers freezing or restarting after initiation of a remote session. In a lot of this cases the quick solutions made b…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now