Skip to content

Instantly share code, notes, and snippets.

@bastiao
Last active March 21, 2021 11:17
Show Gist options
  • Save bastiao/b8280f1bf737c68322f9efea80114c69 to your computer and use it in GitHub Desktop.
Save bastiao/b8280f1bf737c68322f9efea80114c69 to your computer and use it in GitHub Desktop.
OVH Racks SGB3
const http = require('http');
var fs = require('fs');
/*********
Random script created to see restart process of OVH Strasburg fire 10.03.2021.
node .\rack_sgb3.js S341 B06
[ 'S341', 'B06' ] is offline
Online Racks: 138
Offline Racks: 493
Online Percentage: 21.87
Floor 4 Online Racks: 16
Floor 4 Offline Racks: 110
***/
var myArgs = process.argv.slice(2);
http.get("http://status.ovh.com/vms/index_sbg3.html", (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
var array = data.toString().split("\n");
var count_online = 0 ;
var count_offline = 0;
var count_floor_online = 0 ;
var count_floor_offline = 0;
var currentFloor = ""
var floor = -1
if (myArgs.length>0)
{
floor = myArgs[0][2];
var currentFloor = myArgs[0].substring(0,3);
console.log("Floor: "+ floor + " => " + currentFloor)
}
for(i in array) {
array[i] = array[i].trim();
if (array[i].includes("<td")&&array[i].length>14&& !array[i].includes("caption")){
//console.log(array[i]);
var tmp = array[i];
if (tmp!=undefined){
tmp = tmp.replace("<td class=\"lv", "");
var printStatus = false;
if (myArgs.length == 2 && tmp.includes(myArgs[0]) && tmp.includes(myArgs[1])){
printStatus = true;
}
var status = tmp.split("\"");
if (status.includes("undef")){
count_offline++;
if (floor!=-1 && tmp.includes(currentFloor)){
count_floor_offline++;
}
if (printStatus){
console.log(myArgs, "is offline");
}
}
else if (!tmp.includes(">&nbsp")) {
count_online++;
if (floor!=-1 && tmp.includes(currentFloor)){
count_floor_online++;
}
if (printStatus){
console.log(myArgs, "is online");
//console.log(tmp);
}
}
}
}
}
console.log("Online Racks: "+ count_online);
console.log("Offline Racks: "+ count_offline);
console.log("Online Percentage: " + (count_online/(count_offline+count_online) * 100).toFixed(2));
if (floor!=-1){
console.log("Floor "+floor+" Online Racks: "+ count_floor_online);
console.log("Floor "+floor+" Offline Racks: "+ count_floor_offline);
console.log("Floor "+floor+ " Online Percentage: " + (count_floor_online/(count_floor_offline+count_floor_online) * 100).toFixed(2));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment