Last active
August 29, 2015 14:13
-
-
Save jstriebel/a4b3848e9c7ec07182b7 to your computer and use it in GitHub Desktop.
hack to show only interesting stuff in a more beautiful way on icinga status pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name beautify icinga status | |
// @version 0.4 | |
// @description hack to show only interesting stuff in a more beautiful way on icinga status pages | |
// @author Jonathan | |
// @match */icinga/cgi-bin/status.cgi* | |
// @grant none | |
// ==/UserScript== | |
// use only this if you always want to get my newest version of the script: | |
// var jsLink = document.createElement('script'); | |
// jsLink.setAttribute('src','//rawgit.com/jstriebel/a4b3848e9c7ec07182b7/raw/beautify-icinga-status.js'); | |
// document.head.appendChild(jsLink); | |
loadCSS = function(href) { | |
var cssLink = document.createElement('link'); | |
cssLink.setAttribute('rel', 'stylesheet'); | |
cssLink.setAttribute('type', 'text/css'); | |
cssLink.setAttribute('href', href); | |
document.getElementsByTagName('head')[0].appendChild(cssLink); | |
}; | |
loadJS = function(src) { | |
var jsLink = document.createElement('script'); | |
jsLink.setAttribute('src',src); | |
document.head.appendChild(jsLink); | |
}; | |
function beautify() { | |
loadJS("//code.jquery.com/jquery-1.11.2.min.js"); | |
var amountOfRows = $('table.status > tbody').children().length; | |
if ( amountOfRows <= 1 ) { | |
// if there are no things to show, show cats! | |
$('body').children().hide(); | |
var catText = document.createElement('p'); | |
catText.setAttribute('style','color:blue; text-align:center; font-size: 20px; font-family: Lobster, cursive;'); | |
catText.innerHTML = 'Woa, nothing to show here. Maybe wanna random cat pic?'; | |
var cat = document.createElement('img'); | |
cat.setAttribute('src','http://thecatapi.com/api/images/get?format=src&type=jpg,png&size=med,full'); | |
cat.setAttribute('style', 'display: block; margin-left: auto; margin-right: auto;'); | |
loadCSS('//fonts.googleapis.com/css?family=Lobster'); | |
document.body.appendChild(catText); | |
document.body.appendChild(cat); | |
setTimeout(location.reload, 30000); | |
return; | |
} | |
// "normal" beautification, showing the table: | |
loadCSS('//fonts.googleapis.com/css?family=Roboto:300'); | |
var interesting = $('table.status'); | |
$('*').not(interesting).not(interesting.parents()).not(interesting.find('*')).hide(); | |
var beautyCss = $("<style type='text/css'> " + | |
" table,tr,td { " + | |
" font-family: Roboto, sans-serif; " + | |
" font-size: 14px; " + | |
" font-weight: 300; " + | |
" } " + | |
" table.status { " + | |
" width: 98%; " + | |
" margin: 1%; " + | |
" border: #ccc 1px solid; " + | |
" -moz-border-radius: 3px; " + | |
" -webkit-border-radius: 3px; " + | |
" border-radius: 3px; " + | |
" -moz-box-shadow: 0 1px 2px #d1d1d1; " + | |
" -webkit-box-shadow: 0 1px 2px #d1d1d1; " + | |
" box-shadow: 0 1px 2px #d1d1d1; " + | |
" } " + | |
"</style>"); | |
$("head").append(beautyCss); | |
} | |
jQuery(document).ready(beautify); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment