Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
emulab-devel
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
111
Issues
111
List
Boards
Labels
Milestones
Merge Requests
4
Merge Requests
4
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
emulab
emulab-devel
Commits
e4dd337c
Commit
e4dd337c
authored
Dec 13, 2005
by
Mike Hibler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send mail if a power controller isn't responding or is failing.
parent
4b6bad6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
13 deletions
+62
-13
sensors/powermon/powermon.in
sensors/powermon/powermon.in
+62
-13
No files found.
sensors/powermon/powermon.in
View file @
e4dd337c
...
...
@@ -42,7 +42,8 @@ use POSIX qw(strftime);
sub
usage
()
{
print
<<
"
END
";
Usage:
$0
[
-
TPC
]
[
<
type
>
...
]
Usage:
$0
[
-
w
]
[
-
TPC
]
[
<
type
>
...
]
-
w
whiner
flag
,
send
mail
to
$TBOPS
about
errors
-
T
turn
on
temperature
(
in
degrees
F
)
monitoring
-
P
turn
on
power
(
watts
)
consumption
monitoring
-
C
turn
on
current
(
amps
)
used
monitoring
...
...
@@ -55,10 +56,19 @@ Usage: $0 [-TPC] [ <type> ... ]
END
}
my
$optlist
=
"
ANTPC
";
my
$optlist
=
"
w
ANTPC
";
my
$dotemps
=
1
;
my
$dopower
=
0
;
my
$docurrent
=
0
;
my
$whiner
=
0
;
my
$whinefile
=
"
/tmp/powermon.$$
";
my
$childpid
=
-
1
;
# un-taint path
$ENV
{'
PATH
'}
=
'
/bin:/usr/bin:/usr/local/bin
';
delete
@ENV
{'
IFS
',
'
CDPATH
',
'
ENV
',
'
BASH_ENV
'};
$|
=
1
;
#Turn off line buffering on output
#
# Parse command arguments. Once we return from getopts, all that should be
...
...
@@ -68,6 +78,13 @@ my %options = ();
if
(
!
getopts
(
$optlist
,
\%
options
))
{
usage
();
}
if
(
defined
(
$options
{"
w
"}))
{
if
(
open
(
WHINE
,
"
>
$whinefile
"))
{
$whiner
=
1
;
}
else
{
print
"
*** Could not open
$whinefile
,
$TBOPS
whining disabled
\n
";
}
}
if
(
defined
(
$options
{"
A
"}))
{
$dotemps
=
$dopower
=
$docurrent
=
1
;
}
...
...
@@ -137,33 +154,52 @@ sub dostatus(@) {
# We do this in a child process so we can time it out if
# one of the controllers is not responding.
#
my
$sys
pid
=
fork
();
if
(
$
sys
pid
)
{
$child
pid
=
fork
();
if
(
$
child
pid
)
{
#
# Allow 5 seconds per controller
#
local
$SIG
{
ALRM
}
=
sub
{
kill
("
TERM
",
$
sys
pid
);
};
local
$SIG
{
ALRM
}
=
sub
{
kill
("
TERM
",
$
child
pid
);
};
my
$to
=
5
*
scalar
(
@wanted
);
alarm
$to
;
waitpid
(
$
sys
pid
,
0
);
waitpid
(
$
child
pid
,
0
);
alarm
0
;
if
(
$?
)
{
logit
("
*** Status fetch failed after
$to
seconds with exit val $?
");
my
$ecode
=
$?
;
if
(
$ecode
)
{
my
$cause
;
if
((
$ecode
&
0xff
)
>
0
)
{
$cause
=
"
timed out after
$to
seconds
";
}
else
{
$cause
=
"
failed with exit value
"
.
(
$ecode
>>
8
);
}
logit
("
*** Status fetch
$cause
");
#
# If pissin' and moanin' send the last run log to TBOPS
#
if
(
$whiner
)
{
SENDMAIL
(
$TBOPS
,
"
WARNING: power controller(s)
$cause
",
"
There were errors getting status from one or more
"
.
"
of the power controllers,
\n
the log is appended.
",
$TBOPS
,
undef
,
(
$whinefile
));
}
}
return
$
?
;
return
$
ecode
;
}
for
my
$ctrl
(
@wanted
)
{
my
%
status
;
if
(
!
defined
(
$ctrls
{
$ctrl
}))
{
warn
"
No such power controller '
$ctrl
', ignored
\n
"
;
logit
("
No such power controller '
$ctrl
', ignored
")
;
$errors
++
;
next
;
}
if
(
$ctrls
{
$ctrl
}
=~
/^RPC/
)
{
if
(
rpc27status
(
$ctrl
,
\%
status
))
{
warn
"
Could not get status for
$ctrl
.
\n
"
;
logit
("
Could not get status for
$ctrl
.
")
;
$errors
++
;
next
;
}
...
...
@@ -182,11 +218,12 @@ sub dostatus(@) {
}
logit
(
$msg
);
}
elsif
(
!
$doall
)
{
warn
"
Cannot get status for
$ctrl
(type
"
.
$ctrls
{
$ctrl
}
.
"
) yet
\n
"
;
logit
(
"
Cannot get status for
$ctrl
(type
"
.
$ctrls
{
$ctrl
}
.
"
) yet
")
;
$errors
++
;
}
}
close
(
WHINE
);
exit
(
$errors
);
}
...
...
@@ -194,4 +231,16 @@ sub logit($) {
my
(
$msg
)
=
@_
;
print
strftime
("
%b %e %H:%M:%S
",
localtime
)
.
"
powermon[$$]:
$msg
\n
";
if
(
$whiner
&&
$childpid
==
0
)
{
print
WHINE
$msg
,
"
\n
";
}
}
END
{
return
if
(
$childpid
==
0
||
!
$whiner
);
my
$ecode
=
$?
;
unlink
(
$whinefile
);
$?
=
$ecode
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment