affichage IPMI vers une page web
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Stats IPMI</title> | |
<meta name="description" content="page IPMI"> | |
<style type="text/css"> | |
tr:nth-child(even) {background-color: #f2f2f2;} | |
table{ | |
margin: auto; | |
border: 4px dotted darkgreen; | |
width:50%; | |
margin-bottom: 2ex; | |
} | |
.bouton{ | |
margin-top:5ex; | |
transform:skew(12deg,-3deg) rotateZ(0deg) | |
} | |
.bouton span{ | |
margin-left:40%; | |
padding:0.3ex; | |
} | |
#titre,th,header,footer, footer a,tr:hover{ | |
background-color: darkgreen; | |
color: white; | |
} | |
table a:link{ | |
text-decoration: none; | |
} | |
table a:link, table a:visited, table a:active{ | |
color:black; | |
} | |
table a:hover, tr:hover a:link,tr:hover a:visited{ | |
color:white; | |
text-decoration:underline; | |
} | |
#titre,th,header{ | |
font-variant:small-caps; | |
} | |
#maitre{ | |
border-left: 1ex solid green; | |
text-transform: uppercase; | |
} | |
fieldset{ | |
width: 50ex; | |
margin:auto; | |
text-align: right; | |
} | |
fieldset div{margin:2px;} | |
::placeholder { | |
color: white; | |
opacity: 0.5; | |
} | |
footer{ | |
position: fixed; | |
bottom:0; | |
left:0; | |
right:0; | |
margin-top: 2px; | |
padding: 1px 0; | |
font-variant:small-caps; | |
} | |
</style> | |
</head> | |
<body style='text-align:center;'> | |
<header><h1>Stats IPMI</h1></header> | |
<!-- Fin en-tete --> | |
<?php | |
if (file_exists('ipmi-lst.html')) | |
{ include('ipmi-lst.html'); } | |
if (file_exists('ipmi-events.html')) | |
{ include('ipmi-events.html'); } | |
if (file_exists('ipmi-errors.log') and filesize('ipmi-errors.log')) | |
{ | |
echo ' <div style="margin: auto; border: 4px solid darkred; width:60%;"><pre>'; | |
include('ipmi-errors.log'); | |
echo ' </pre></div>'; | |
} | |
echo ('<div class="bouton"><span id="titre">Données mises à jour '.time_elapsed_string('@'.filemtime('ipmi-lst.html')).'</span></div>'); | |
/* | |
* Fonction epoch->time ago pompée sur stack overflow: | |
* https://stackoverflow.com/questions/1416697/converting-timestamp-to-time-ago-in-php-e-g-1-day-ago-2-days-ago/18602474#18602474 | |
*/ | |
function time_elapsed_string($datetime, $full = false) { | |
$now = new DateTime; | |
$ago = new DateTime($datetime); | |
$diff = $now->diff($ago); | |
$diff->w = floor($diff->d / 7); | |
$diff->d -= $diff->w * 7; | |
$string = array( | |
'y' => 'an', | |
'm' => 'mois', | |
'w' => 'semaine', | |
'd' => 'jour', | |
'h' => 'heure', | |
'i' => 'minute', | |
's' => 'seconde', | |
); | |
foreach ($string as $k => &$v) { | |
if ($diff->$k) { | |
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); | |
} else { | |
unset($string[$k]); | |
} | |
} | |
if (!$full) $string = array_slice($string, 0, 1); | |
return $string ? 'il y a ' . implode(', ', $string) : 'à l\'instant'; | |
} | |
?> | |
<!-- Début pied-de-page --> | |
<footer> | |
<a href="https://twitter.com/albirew">Albirew</a>℠ 2019 - Aucun droit réservé | |
</footer> | |
</body> | |
</html> |
#!/bin/bash | |
if [ "$EUID" -ne 0 ]; then | |
echo "CE SCRIPT DOIT ÊTRE LANCÉ AVEC LES DROITS ROOT" && exit 1 | |
fi | |
#apt install freeipmi-tools ipmitool | |
dossier="/path/to/www/ipmi" | |
cd $dossier || exit 1 | |
ipmitool -I free sdr list full > $dossier/ipmi-lst.log | |
# exemple: Temp | 41 degrees C | ok | |
echo '<table class="ipmi-list">' > $dossier/ipmi-lst.html | |
echo '<tr><th>Sonde</th><th>Valeur</th><th>État</th></tr>' >> $dossier/ipmi-lst.html | |
while read INPUT ; do echo "<tr><td>${INPUT//|/</td><td>}</td></tr>" ; done < $dossier/ipmi-lst.log >> $dossier/ipmi-lst.html | |
echo '</table>' >> $dossier/ipmi-lst.html | |
ipmitool -I free sel list last 10 > $dossier/ipmi-events.log | |
# exemple: 1 | 06/06/2019 | 21:26:54 | Event Logging Disabled #0x51 | Log area reset/cleared | Asserted | |
echo '<table class="ipmi-events">' > $dossier/ipmi-events.html | |
echo '<tr><th>ID</th><th>Date</th><th>Heure</th><th>Type</th><th>Évènement</th><th>Confirmation</th></tr>' >> $dossier/ipmi-events.html | |
while read INPUT ; do echo "<tr><td>${INPUT//|/</td><td>}</td></tr>" ; done < $dossier/ipmi-events.log >> $dossier/ipmi-events.html | |
echo '</table>' >> $dossier/ipmi-events.html | |
ipmitool -I free sdr list event > $dossier/ipmi-errors.log | |
chmod -R a+rw $dossier |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment