Here is a proposition.
The idea is to define an object that maps the property (http, ftp...) with related images url indexed by possible property values (OK, WARNING,...).
With this approach :
- get the img src for a service :
object[service_name][service_status]
- get the service status :
$(xml).find(service_name).text()
- get the img dom element
$("." + service_name + " img")
Code :
$(document).ready(function() {
var config = {
"http":{
"OK":"http://placehold.it/40/00cc33/ffffff",
"WARNING":"http://placehold.it/40/ff6600/000000",
"CRITICAL":"http://placehold.it/40/ff0000/000000",
"UNKNOWN":"/path/to/unknow"
},
"ftp":{
"OK":"http://placehold.it/40/00cc33/ffffff",
"WARNING":"http://placehold.it/40/ff6600/000000",
"CRITICAL":"http://placehold.it/40/ff0000/000000",
"UNKNOWN":"/path/to/unknow"
},
"mysql":{
"OK":"http://placehold.it/40/00cc33/ffffff",
"WARNING":"http://placehold.it/40/ff6600/000000",
"CRITICAL":"http://placehold.it/40/ff0000/000000",
"UNKNOWN":"/path/to/unknow"
},
"load":{
"OK":"http://placehold.it/40/00cc33/ffffff",
"WARNING":"http://placehold.it/40/ff6600/000000",
"CRITICAL":"http://placehold.it/40/ff0000/000000",
"UNKNOWN":"/path/to/unknow"
}
};
function refreshView (xml) {
for (var name in config) {
$("." + name +" img").attr("src",config[name][$(xml).find(name).text()] );
}
}
$.ajax({
type: 'GET',
url: 'https://status.clook.net/xml/status/harvey.xml',
dataType: 'xml',
success: refreshView
});
});