1 #!/usr/bin/perl -w
2 # File: nt_event_generator.pl
3 # Author: unknown
4 # Location: http://www.thelug.org/docs/
5 # Description: The GenEvent.pl Perl Script
6 # Requires: Win32::EventLog module. Check CPAN
7 # at http://www.cpan.org
8
9 use Win32::EventLog;
10
11 ($ARGV[0] =~ /\?/) and PrintHelp();
12
13 #*begin callout A
14 foreach (@ARGV) {
15 (/h=/i) and $host = (split(/=/, $_, 2))[1];
16 (/s=/i) and $src = (split(/=/, $_, 2))[1];
17 (/i=/i) and $id = (split(/=/, $_, 2))[1];
18 (/t=/i) and $type = (split(/=/, $_, 2))[1];
19 (/d=/i) and $desc = (split(/=/, $_, 2))[1];
20 }
21 #*end callout A
22
23 ($host) ? "\\\\".$host : "\\\\".($ENV{COMPUTERNAME});
24 ($src) or ($src = "PerlWin32");
25 ($id) or ($id = 1);
26 ($type) or ($type = 'i');
27
28 ($type =~ /e/i) and ($type = EVENTLOG_ERROR_TYPE);
29 ($type =~ /i/i) and ($type = EVENTLOG_INFORMATION_TYPE);
30 ($type =~ /w/i) and ($type = EVENTLOG_WARNING_TYPE);
31
32 #**begin callout B
33 %Event = ('EventID' => $id, 'EventType' => $type, 'Strings' => $desc);
34 #**end callout B, ***begin callout C
35 Win32::EventLog::Open($EventObj, $src, $host) || die "Unable to open NT Event Log: $!\n";
36 $EventObj->Report(\%Event) || die "Unable to generate event: $!\n";
37 #***end callout C
38
39
40 sub PrintHelp {
41 print <<END;
42
43 Event Generator How To
44 ----------------------
45
46 Syntax: c:\\> perl genevent.pl [h=TargetHost] [s=Source] [i=ID] [t=Type] [d=Description]
47
48 GenEvent.pl is a Perl for Win32 script that lets you generate user-
49 defined events into the NT Application log. The script accepts the
50 following command line arguments:
51
52 h= Target host. Local system is the default.
53
54 s= String representing the source of the event. If the source string
55 contains spaces, enclose in "quotes." Default is PerlWin32.
56
57 i= Integer Event ID. Default is 1.
58
59 t= Single character representing the event type (default is i):
60 e - Error | i - information | w - Warning
61
62 d= Event Description. If the description contains spaces, enclose in
63 "quotes." Default is blank.
64
65 Example:
66 c:\\>perl genevent.pl h=Gecko s=BobsScript i=100 t=i d="Script completed successfully"
67
68 END
69
70 exit(0);
71 }
syntax highlighted by Code2HTML, v. 0.9.1