Friday, July 17, 2015

[Solved] Nagvis weather map (traffic map) and Centreon & Nagios

To fix weather maps (traffic maps) with Nagvis and Nagios & Centreon you have to fix 3 things:

1. You have to modify the code of the check script (check_centreon_snmp_traffic).
In this script you have to modify the following line :

printf("|traffic_in=".$in_perfparse_traffic_str."Bits/s;$warningBit;$criticalBit;0;$speed_card                  traffic_out=".$out_perfparse_traffic_str."Bits/s;$warningBit;$criticalBit;0;$speed_card\n");

and replace with:

printf("|traffic_in=".$in_perfparse_traffic_str."Bits/s;$warningBit;$criticalBit;0;$speed_card traffic_out=".$out_perfparse_traffic_str."Bits/s;$warningBit;$criticalBit;0;$speed_card load_In=".$in_usage."%%;$warningBit;$criticalBit;0;0 load_Out=".$out_usage."%%;$warningBit;$criticalBit;0;0 traffic_In=%.2f".$in_prefix."b;".$warningBit.";".$criticalBit.";0;0 traffic_Out=%.2f".$out_prefix."b;".$warningBit.";".$criticalBit.";0;0 \n",$in_traffic,$out_traffic);

2. The file you have to modify  next is : /usr/share/nagvis/share/frontend/nagvis-js/js/NagVisCompressed.js
 
You have to find the function "drawNagVisLine"  and replace it with:

function drawNagVisLine(objectId, lineType, cuts, x, y, z, width, colorFill, colorFill2, perfdata, colorBorder, bLinkArea, bLabelShow, yOffset) {
for(var i=0; i < x.length; i++) {
x[i] = parseInt(x[i], 10);
y[i] = parseInt(y[i], 10);
}
var xStart=x[0];
var yStart=y[0];
var xEnd=x[x.length - 1];
var yEnd=y[y.length - 1];
if(perfdata == null)
perfdata = [];
width = parseInt(width, 10);
var perfdataA="N/A";
var perfdataB="N/A";
var cut=cuts[0];
var cutIn=cuts[1];
var cutOut=cuts[2];
switch (lineType) {
case '10':
if(x.length == 2) {
var xMid=middle(xStart, xEnd, cut);
var yMid=middle(yStart, yEnd, cut);
} else {
var xMid=x[1];
var yMid=y[1];
}
drawArrow(objectId, 1, xStart, yStart, xMid, yMid, z, width, colorFill, colorBorder);
drawLinkOrLabel(objectId, 1, lineType, xMid, yMid, z, perfdataA, perfdataB, bLinkArea, bLabelShow);
drawArrow(objectId, 2, xEnd, yEnd, xMid, yMid, z, width, colorFill, colorBorder);
drawLinkOrLabel(objectId, 2, lineType, xMid, yMid, z, perfdataA, perfdataB, bLinkArea, bLabelShow);
break;
case '11':
var xMid=middle(xStart, xEnd, cut);
var yMid=middle(yStart, yEnd, cut);
drawArrow(objectId, 1, xStart, yStart, xEnd, yEnd, z, width, colorFill, colorBorder);
drawLinkOrLabel(objectId, 1, lineType, xMid, yMid, z, perfdataA, perfdataB, bLinkArea, bLabelShow);
break;
case '12':
var xMid=middle(xStart, xEnd, cut);
var yMid=middle(yStart, yEnd, cut);
drawSimpleLine(objectId, 1, xStart, yStart, xEnd, yEnd, z, width, colorFill, colorBorder);
drawLinkOrLabel(objectId, 1, lineType, xMid, yMid, z, perfdataA, perfdataB, bLinkArea, bLabelShow);
break;
case '13':
if(x.length == 2) {
var xMid=middle(xStart, xEnd, cut);
var yMid=middle(yStart, yEnd, cut);
} else {
var xMid=x[1];
var yMid=y[1];
}
if(isset(perfdata[2]) && isset(perfdata[2][1]) && isset(perfdata[2][2])) // HERE
perfdataA = perfdata[2][1] + perfdata[2][2]; // HERE
drawArrow(objectId, 1, xStart, yStart, xMid, yMid, z, width, colorFill, colorBorder); 
drawLinkOrLabel(objectId, 1, lineType, middle(xStart, xMid, cutIn), middle(yStart, yMid, cutIn), z, perfdataA, perfdataB, bLinkArea, bLabelShow);
if(isset(perfdata[3]) && isset(perfdata[3][1]) && isset(perfdata[3][2])) // HERE
perfdataA = perfdata[3][1] + perfdata[3][2]; // HERE
drawArrow(objectId, 2, xEnd, yEnd, xMid, yMid, z, width, colorFill2, colorBorder);
drawLinkOrLabel(objectId, 2, lineType, middle(xEnd, xMid, cutOut), middle(yEnd, yMid, cutOut), z, perfdataA, perfdataB, bLinkArea, bLabelShow);
break;
case '14':
if(x.length == 2) {
var xMid=middle(xStart, xEnd, cut);
var yMid=middle(yStart, yEnd, cut);
} else {
var xMid=x[1];
var yMid=y[1];
}
yOffset = yOffset + width;
if(isset(perfdata[2]) && isset(perfdata[2][1]) && isset(perfdata[2][2])) // HERE
perfdataA = perfdata[2][1] + perfdata[2][2]; // HERE
if(isset(perfdata[4]) && isset(perfdata[4][1]) && isset(perfdata[4][2])) // HERE
perfdataB = perfdata[4][1] + perfdata[4][2] + '/s'; // HERE
drawArrow(objectId, 1, xStart, yStart, xMid, yMid, z, width, colorFill, colorBorder);
drawLinkOrLabel(objectId, 1, lineType, middle(xStart, xMid, cutOut), middle(yStart, yMid, cutOut), z, perfdataA, perfdataB, bLinkArea, bLabelShow, yOffset);
if(isset(perfdata[3]) && isset(perfdata[3][1]) && isset(perfdata[3][2])) // HERE
perfdataA = perfdata[3][1] + perfdata[3][2]; // HERE
if(isset(perfdata[5]) && isset(perfdata[5][1]) && isset(perfdata[3][2])) // HERE
perfdataB = perfdata[5][1] + perfdata[5][2] + '/s'; // HERE
drawArrow(objectId, 3, xEnd, yEnd, xMid, yMid, z, width, colorFill2, colorBorder);
drawLinkOrLabel(objectId, 3, lineType, middle(xEnd, xMid, cutIn), middle(yEnd, yMid, cutIn), z, perfdataA, perfdataB, bLinkArea, bLabelShow, yOffset);
break;
case '15':
if(x.length == 2) {
var xMid=middle(xStart, xEnd, cut);
var yMid=middle(yStart, yEnd, cut);
} else {
var xMid=x[1];
var yMid=y[1];
}
yOffset = yOffset + width;
if(isset(perfdata[4]) && isset(perfdata[4][1]) && isset(perfdata[4][2])) // HERE
perfdataA = perfdata[4][1] + perfdata[4][2] + '/s' ; // HERE
drawArrow(objectId, 1, xStart, yStart, xMid, yMid, z, width, colorFill, colorBorder);
drawLinkOrLabel(objectId, 1, lineType, middle(xStart, xMid, cutOut), middle(yStart, yMid, cutOut), z, perfdataA, perfdataB, bLinkArea, bLabelShow, yOffset);
if(isset(perfdata[5]) && isset(perfdata[5][1]) && isset(perfdata[5][2])) // HERE 
perfdataA = perfdata[5][1] + perfdata[5][2] + '/s' ;     // HERE
drawArrow(objectId, 3, xEnd, yEnd, xMid, yMid, z, width, colorFill2, colorBorder);
drawLinkOrLabel(objectId, 3, lineType, middle(xEnd, xMid, cutIn), middle(yEnd, yMid, cutIn), z, perfdataA, perfdataB, bLinkArea, bLabelShow, yOffset);
break;
default:
alert('Error: Unknown line type');
}
}

Find another function "drawLine" and replace with:
 
drawLine: function() {
var x=this.parseCoords(this.conf.x, 'x');
var y=this.parseCoords(this.conf.y, 'y');
var width=addZoomFactor(this.conf.line_width);
if(width <= 0)
width = 1; // minimal width for lines
var colorFill='';
var colorFill2='';
var colorBorder='#000000';
var setPerfdata=[];
setPerfdata[0] = Array('dummyPercentIn', 88, '%', 85, 98, 0, 100);
setPerfdata[1] = Array('dummyPercentOut', 99, '%', 85, 98, 0, 100);
setPerfdata[2] = Array('dummyActualIn', 88.88, 'mB/s', 850, 980, 0, 1000);
setPerfdata[3] = Array('dummyActualOut', 99.99, 'mB/s', 850, 980, 0, 1000);
switch (this.conf.summary_state) {
case 'UNREACHABLE':
case 'DOWN':
case 'CRITICAL':
case 'WARNING':
case 'UNKNOWN':
case 'ERROR':
case 'UP':
case 'OK':
case 'PENDING':
colorFill = oStates[this.conf.summary_state].color;
break;
default:
colorFill = '#FFCC66';
break;
}
if(this.conf.line_type == 13 || this.conf.line_type == 14 || this.conf.line_type == 15) {
colorFill  = '#000000';
colorFill2 = '#000000';
setPerfdata = splicePerfdata(this.conf.perfdata);
if(setPerfdata == 'empty'
|| !isset(setPerfdata[0]) || setPerfdata[0][0] == 'dummyPercentIn'
|| !isset(setPerfdata[1]) || setPerfdata[1][0] == 'dummyPercentOut'
|| (this.conf.line_type == 14 && (
!isset(setPerfdata[2]) || setPerfdata[2][0] == 'dummyActualIn'
|| !isset(setPerfdata[3]) || setPerfdata[3][0] == 'dummyActualOut'))) {
var msg="Missing performance data - ";
if(setPerfdata == 'empty')
msg += "perfdata string is empty";
else {
if(isset(setPerfdata[0]) && setPerfdata[0][0] == 'dummyPercentIn')
msg += "value 1 is \'" + setPerfdata[0][1] + "\'";
if(isset(setPerfdata[1]) && setPerfdata[1][0] == 'dummyPercentOut')
msg += " value 2 is \'" + setPerfdata[1][1] + "\'";
if(this.conf.line_type == 14) {
if(isset(setPerfdata[2]) && setPerfdata[2][0] == 'dummyActualIn')
msg += " value 3 is \'" + setPerfdata[2][1] + "\'";
if(isset(setPerfdata[3]) && setPerfdata[3][0] == 'dummyActualOut')
msg += " value 4 is \'" + setPerfdata[3][1] + "\'";
}
}
this.conf.summary_output += ' (Comp:Bouh: ' + msg + ')';
} else {
if(setPerfdata[2][2] === null || setPerfdata[2][2] === '' //HERE
|| setPerfdata[3][2] === null || setPerfdata[3][2] === '') { //HERE
setPerfdata = this.calculateUsage(setPerfdata);
}
if(setPerfdata[2][2] !== null && setPerfdata[2][2] == '%' && setPerfdata[2][1] !== null) { //HERE
colorFill = this.getColorFill(setPerfdata[2][1]); //HERE
} else {
colorFill = '#000000';
this.perfdataError('First', setPerfdata[3][1], this.conf.name, this.conf.service_description); //HERE
}
if(setPerfdata[2][2] !== null && setPerfdata[2][2] == '%' && setPerfdata [2][1] !== null) { //HERE
colorFill2 = this.getColorFill(setPerfdata[2][1]); //HERE
} else {
colorFill2 = '#000000';
this.perfdataError('Second', setPerfdata[3][1], this.conf.name, this.conf.service_description); //HERE
}
}
}
if(this.conf.summary_problem_has_been_acknowledged === 1 || this.conf.summary_in_downtime === 1) {
colorBorder = '#666666';
colorFill = lightenColor(colorFill, 100, 100, 100);
}
var cuts=[this.conf.line_cut, this.conf.line_label_pos_in, this.conf.line_label_pos_out];
drawNagVisLine(this.conf.object_id, this.conf.line_type, cuts, x, y,
this.conf.z, width, colorFill, colorFill2, setPerfdata, colorBorder,
this.needsLineHoverArea(),
(this.conf.line_label_show && this.conf.line_label_show === '1'),
parseInt(this.conf.line_label_y_offset));
}, 

And that`s all !!
 
 
found here 

No comments:

Post a Comment

Cybermap

Internet Storm Center Infocon Status

Internet Storm Center Infocon Status
Internet Storm Center Infocon Status