"Fossies" - the Fresh Open Source Software Archive 
Member "checksuite-3.3/checkhardware" (3 Jun 2010, 4905 Bytes) of package /linux/privat/old/checksuite-3.3.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #!/usr/bin/perl -w
2 ########################################################
3 # Hardware Monitor by Larry Long - larry@djslyde.com #
4 # [checkhardware] - 2/9 programs in checksuite v3.3 #
5 # #
6 # This greps the system's dmesg log for any errors #
7 # that may be hardware related. #
8 ########################################################
9 use strict;
10 use Getopt::Std;
11 use Net::SMTP;
12
13 $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin';
14
15 # Options: -h (help) -l (log) -o (output to screen) -e (email) -p (pager)
16 my %opt;getopts('hloe:p:', \%opt);
17 usage_info() unless defined @ARGV;
18 usage_info() if exists $opt{h};
19
20 # Localize variables throughout the rest of the program
21 my($email,$host,$dmesg,@note,$notify,$logdate,$logfile,$logsnip,$script,@errors,$possibility,$subject,@pnote,$pmail,$psubject,@dlog,@temp);
22
23 # Are we root?
24 if($> != 0)
25 {
26 print STDERR "\n$0: This program HAS to be ran as root!!!\n\nPlease su to root
27 or use 'sudo $0'!\n";
28 exit 2;
29 }
30
31 # Define variables
32 $email = $opt{e};$email = 'root@localhost' unless defined $opt{e};
33 $pmail = $opt{p};
34 $host = `hostname`;
35 $logfile = "/var/log/checksuite.d/checkhardware";
36 $logdate = `date '+%m/%d/%Y %H:%M:%S' `;
37 $script = " - [checksuite] checkhardware\n";
38 $logsnip = "----\n";
39 $notify = 0;
40 $subject = "[checksuite] advisory - possibly hardware issues found on $host";
41 $psubject = "[checksuite] checkhardware";
42 chomp $host;chomp $logdate;chomp $subject;chomp $psubject;
43
44 push(@note, "\n");
45 push(@note, "Possible problems found in system log:\n\n");
46
47 # False positives
48 # Here you can add additional false positives you may find or you can
49 # just e-mail me at djslyde@users.sourceforge.net and I will include
50 # them in my next release.
51
52 my $false1= "keyboard: Timeout - AT keyboard not present?";
53 my $false2= "Checking 386/387 coupling... OK, FPU using exception 16 error reporting.";
54 my $false3= "Error: only one processor found";
55 my $false4= "task migration cache decay timeout";
56 my $false5= "UDP: bad checksum.";
57 my $false6= "hw tcp v4 csum failed";
58
59 # Are there any errors in dmesg?
60 @errors = ("error", "failed", "unable to load", "timeout", "bad", "timed out", "call trace");
61
62 @dlog = `dmesg`;
63
64 foreach my $dline (@dlog)
65 {
66 if(($dline !~ /$false1/i) && ($dline !~ /$false2/i) && ($dline !~ /$false3/i) && ($dline !~ /$false4/i) && ($dline !~ /$false5/i) && ($dline !~ /$false6/i))
67 {
68 push(@temp, "$dline");
69 }
70 }
71
72 foreach my $tline (@temp)
73 {
74 foreach my $eline (@errors)
75 {
76 if($tline =~ /$eline/i)
77 {
78 $notify++;
79 push(@note, "Possibility $notify: $tline");
80 push(@pnote, "$tline");
81 }
82 }
83 }
84
85 # Define where the output goes
86 if($notify > 0)
87 {
88 push(@note,"");
89 push(@note,"");
90 push(@note,"DISCLAIMER: If you see any possibilities come up in this e-mail, it is *strongly* recommended you view your system's dmesg log immediately for more information!");
91 log_data() if exists $opt{l};
92 email_data() if exists $opt{e};
93 screen_data() if exists $opt{o};
94 pager_data() if exists $opt{p};
95 }
96
97 # Subroutines
98 sub usage_info
99 {
100 my $usage = "
101 Usage: $0 [-h | -lo] [-e <email>] [-p <email>]
102 Options:
103 -h display this help
104 -l log the output to /var/log/checksuite.d/checkhardware
105 -o force output to screen
106 -e e-mail the output to a specified e-mail address
107 -p send shortened output to a pager or cell phone
108 Where:
109 <email> e-mail address of the recipient of the notification
110 default is 'root'
111 \n";
112 die $usage;
113 }
114
115 sub log_data
116 {
117 open(LOG, ">>$logfile") or die "Uh oh! Can't open logfile!\n";
118 print LOG $logdate,$script,@note,$logsnip;
119 close(LOG);
120 }
121
122 sub screen_data
123 {
124 print STDERR @note;
125 }
126
127 sub email_data
128 {
129 my $smtp = Net::SMTP->new($host);
130 if(! ref($smtp))
131 {
132 log_die("Cannot connect to SMTP\n");
133 }
134 $smtp->mail($email);
135 $smtp->to($email);
136 $smtp->data();
137 $smtp->datasend("To: " . $email . "\n");
138 $smtp->datasend("From: Checksuite Notification <root\@$host>\n");
139 $smtp->datasend("Return-Path: " . $email. "\n");
140 $smtp->datasend("Subject: " . $subject . "\n");
141 $smtp->datasend("\n");
142 $smtp->datasend(@note);
143 $smtp->datasend();
144 $smtp->quit();
145 }
146
147 sub pager_data
148 {
149 my $smtp = Net::SMTP->new($host);
150 if(! ref($smtp))
151 {
152 log_die("Cannot connect to SMTP\n");
153 }
154 $smtp->mail($pmail);
155 $smtp->to($pmail);
156 $smtp->data();
157 $smtp->datasend("To: " . $pmail . "\n");
158 $smtp->datasend("From: Checksuite Notification <root\@$host>\n");
159 $smtp->datasend("Return-Path: " . $pmail. "\n");
160 $smtp->datasend("Subject: " . $psubject . "\n");
161 $smtp->datasend("\n");
162 $smtp->datasend(@pnote);
163 $smtp->datasend();
164 $smtp->quit();
165 }