JS Structure duplicator
Takes a json structure and duplicates it n times if it find a property has a comma in its value.
by Ben Clayton
JavaScript
var data = [
{ name:"A12-server,B12-server", type:"status", message:"Bashful", status:"unknown", poll:
[
{
nagiosreq:{
query:"host",
hostname:"bashful"
},
responsehdlr : function( nagios ){
var ndh = nagios.data.host;
var status = ndh.status;
this.context.status = ( status == 2 ) ? "ok" : "bad";
this.log("status " + ndh.status, this.context.status ,( status == 2 ) ? "" : ndh.plugin_output );
return ndh.next_check - nagios.result.query_time;// return when Nagios says it is next goint to check in ms
}
}
]
},
{ name:"LB1,LB2,LB3", type:"status", message:"hello", status:"unknown", poll:
[
{
nagiosreq:{
query:"host",
hostname:"LB1,LB2,LB3"
},
responsehdlr : function( nagios ){
var ndh = nagios.data.host;
var status = ndh.status;
this.context.status = ( status == 2 ) ? "ok" : "bad";
this.log("status " + ndh.status, this.context.status ,( status == 2 ) ? "" : ndh.plugin_output );
return ndh.next_check - nagios.result.query_time;// return when Nagios says it is next goint to check in ms
}
}
]
},
{ name:"A", type:"status", message:"hello", status:"unknown", poll:
[
{
nagiosreq:{
query:"host",
hostnamex:"L1,L2,L3"
},
responsehdlr : function( nagios ){
var ndh = nagios.data.host;
var status = ndh.status;
this.context.status = ( status == 2 ) ? "ok" : "bad";
this.log("status,fred,bert,sid,harry " + ndh.status, this.context.status ,( status == 2 ) ? "" : ndh.plugin_output );
return ndh.next_check - nagios.result.query_time;// return when Nagios says it is next goint to check in ms
}
}
]
}
]
//var $j = $.clone(data[0]);
//console.log($j);
function clone( p ){
var rtn = {};
for ( var name in p ) {
var v = p[name];
//console.log(name, typeof v, v );
if ( typeof v == "object" ){
v = clone( v );
}
rtn[name] = v
}
return rtn;
}
function findDups( p ){
for ( var...