Skip to content

Instantly share code, notes, and snippets.

@Albirew
Last active November 29, 2022 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Albirew/229c3993f4ababad62083c2a2b462141 to your computer and use it in GitHub Desktop.
Save Albirew/229c3993f4ababad62083c2a2b462141 to your computer and use it in GitHub Desktop.
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>IPMI Midgard</title>
<meta name="description" content="page IPMI du serveur Albirew Midgard">
<style type="text/css">
tr:nth-child(even) {background-color: #f2f2f2;}
table, .list{
margin: auto;
border: 4px dotted #4CAF50;
width:50%;
margin-bottom: 2ex;
}
#nom{text-transform: lowercase;}
#nom::first-letter{text-transform: uppercase;}
.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: #4CAF50;
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;
padding: 1px 0;
font-variant:small-caps;
}
.dygraph-roller {
position: relative;
z-index:9;
}
</style>
</head>
<body style='text-align:center;'>
<header><h1>IPMI Midgard</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>');
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';
}
echo ('<div class="list" style="padding-bottom:3em;">');
if (file_exists('temp.html')) {include('temp.html');} else {echo("temp.html not found");}
?>
</div>
<!-- Début pied-de-page -->
<div style="margin-bottom:5em;"></div>
<footer>
<a href="https://twitter.com/albirew">Albirew</a>℠ 2019 - Aucun droit réservé
</footer>
</body>
<script>
document.querySelectorAll('tr td:nth-child(3)').forEach(el=>{if(el.innerHTML.includes('ns')){el.parentNode.style.display='none'}})
</script>
</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
<script type="text/javascript" src="res/dygraph.min.js"></script>
<link rel="stylesheet" src="res/dygraph.css" />
<style type="text/css" title="design">
.dygraph-legend{margin-top: 18em;}
</style>
<div id="graphdiv" style="width:100%; height:300px;"></div>
<script type="text/javascript">
window.onload = function () {
legendFormatter = function(data) {
if (data.x == null) {return 'Température IPMI';}
var html = '<b>' + new Date(data.xHTML).toLocaleString(); + '</b>&nbsp;&nbsp;&nbsp;&nbsp;';
data.series.forEach(function (series) {
if (!series.isVisible)
return;
var labeledData = series.labelHTML + ': ' + series.yHTML;
if (series.isHighlighted) {labeledData = '<b>' + labeledData + '</b>';}
html += series.dashHTML + ' ' + labeledData + '&nbsp;&nbsp;&nbsp;&nbsp;';
});
return html;
},
g = new Dygraph(
document.getElementById("graphdiv"),
"temperature.log", // ---------- path to CSV file ----------
{ // options
labels: ['timestamp', 'temp'],
legend: 'always',
animatedZooms: true,
showRangeSelector: true,
//title: 'Temperature IPMI',
rollPeriod: 90,
showRoller: true,
//errorBars: true,
//valueRange: [-10,45],
legendFormatter: legendFormatter,
interactionModel: Dygraph.defaultInteractionModel,
axes: {
x: {
axisLabelFormatter: function (d, gran, opts) {return new Date(d).toLocaleString();}
}
}
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment