[NetQos] Auto Embedded NPC Graphs

Document created by d.pereyra on Aug 31, 2016
Version 1Show Document
  • View in full screen mode

A development of a dashboard led me to need an automatic generation of graphics from NetQos NPC, and for that is needed to generate a URL for each interface and get the iframe code. That is simple for few interfaces, but when you have 900 routers... its a lot work.

Doing tests I realized that the same two tokens are used for all interfaces. One for the inflow and one for outflow. Great !

But I also need to relate the name of the router with ElementID interfaces...

 

So running this query to export all interfaces details, name, and elementid

\NETQOS\mysql51\bin>mysql nqrptr -t -e "select * from netqosportal.t_interface;" > t_interface_all.txt

 

Getting something like this, after delete some cols

deviceName ifName ID InterfaceId
r783 Fa0/1 183233269

 

With the information from MySQ I create a simple MySqlite DB

 

The bad about this is if new devices are discover, I must do a manual update for DB.

 

And finally entering the name of router in a PHP page, It shows the NPC Graphs of available interfaces in MySqlite.

 

<?php

 

$device = $_GET["device"];

 

function npcgraph($device,$token,$InterfaceId,$sent) {

$scrolling="no";
$width = "100%";
$height = "400";

$npciframe ='<div><iframe ';
$npciframe .='name="'.$device.'_'.$sent.'" ';
$npciframe .='src="http://nq/npc/View.aspx?Integration=1&pg=i';
$npciframe .='&InterfaceId='.$InterfaceId.'';
$npciframe .='&EndTime=CurrentTime';
$npciframe .='&TimeSpan=Weekly';
$npciframe .='&ViewContainer=1';
$npciframe .='&DrillDown=0';
$npciframe .='&Token='.$token.'" ';
$npciframe .='scrolling='.$scrolling.' ';
$npciframe .='frameborder=1 ';
$npciframe .='height="'.$height.'" width="'.$width.'"></iframe></div>';

echo $npciframe;
}

 

$db = new SQLite3('netqos_db.sqlite');

 

/*
DB records examples
486|r715|r715.::Fa0/0.620 - VLAN-620-PA-FO-REF_82983 |0
487|r715|r715.::Fa0/0.630 - VLAN-620-PA-FO-REF_82986 |0
*/


$match = $db->querySingle("SELECT COUNT(*) as count FROM my_table WHERE Nodo='".$device."'");
$result = $db->query("SELECT ItemID,ItemName FROM my_table WHERE Nodo='".$device."'");

 

 

$i = 0;
while($res = $result->fetchArray(SQLITE3_ASSOC)){

$row[$i]['ItemID'] = $res['ItemID'];
$row[$i]['ItemName'] = $res['ItemName'];
$i++;

}

 

if ($i > 0) {

       echo '<ul class="collapsible" data-collapsible="accordion">';

 

for ($x = 0; $x<$i; $x++) {

 

// I DO AN IF BECAUSE I DONT WANT TO SHOW ALL AVAILABLE INTERFACES, JUST WHEN THE NAME CONTAINS 
if (strpos($row[$x]['ItemName'], 'Fa0/0.620') !== false) {
echo '<li><div class="collapsible-header"><i class="material-icons">assessment</i>'.$row[$x]['ItemName'].'</div><div class="collapsible-body">';
npcgraph($row[$x]['ItemName'],"###############TOKEN IN ###########################,$row[$x]['ItemID'],"IN");
npcgraph($row[$x]['ItemName'],"###############TOKEN OUT ###########################",$row[$x]['ItemID'],"OUT");
echo '</div></li>';
}

 

if (strpos($row[$x]['ItemName'], 'Fa0/0.630') !== false) {
echo '<li><div class="collapsible-header"><i class="material-icons">assessment</i>'.$row[$x]['ItemName'].'</div><div class="collapsible-body">';
npcgraph($row[$x]['ItemName'],"###############TOKEN IN ###########################,$row[$x]['ItemID'],"IN");
npcgraph($row[$x]['ItemName'],"###############TOKEN OUT ###########################",$row[$x]['ItemID'],"OUT");
echo '</div></li>';
}

}

echo '</ul>';

} else {
echo "<b>NO IN SQLITE DB</b><br>";

}

 

The result ? The iframes from NPC from an specific router, without generate the url in NPC. =)

 

The GAP in the middle is because a server maintenance.

 

If something is not understood consult me, and forgive my English is not the best. And my PHP code is basic, not a professional developer,  but is useful. 

Thanks and I await comments !!!

Diego MP

2 people found this helpful

Attachments

    Outcomes