Page 1 of 2
Config Wizard issue
Posted: Fri Mar 28, 2014 3:21 pm
by kyle.parker
I am trying to create a custom config wizard to allow me to add Calix devices. I want to have a routine run in one of my steps if a box is checked to scan the card and return the port index so I can then choose to monitor bandwidth. php isn't my strong suit and I can't seem to figure it out. I want to completely avoid using mrtg which is why I am not using Switch/Router device config wizard. We don't want mrtg polling 1000's of interfaces in the background that we don't want to monitor. Is there anybody proficient in php willing to help me?
Re: Config Wizard issue
Posted: Mon Mar 31, 2014 10:31 am
by abrist
Do you have some code that you are working with that you would care to post? My guess is that you will need to run a commandline with exec(); - probably an snmpwalk or snmpget to query for the table in question. You will need to pay attention to escaping as well. In XI, we load the options (ip, community, oid/mib, etc) into variables, escape the relevant ones, and then run the walk with:
(/usr/local/nagiosxi/html/includes/configwizards/snmpwalk/snmpwalk.inc.php, Line #389)
Code: Select all
$cmdline="/usr/bin/snmpwalk -v ".escapeshellcmd($snmpversion)." -c ".escapeshellcmd($snmpcommunity).escapeshellcmd($cmdargs)." ".escapeshellcmd($address).":".escapeshellcmd($port)." ".$useoid." > ".$resultfile." 2>&1 & echo $!";
We then parse the $resultfile for the data to create the necessary checks.
Re: Config Wizard issue
Posted: Tue Apr 01, 2014 12:47 pm
by kyle.parker
This is what I have been working with. In this step I would like to create a check box for scanning the card for monitorable interfaces. and in the stage 2 validate check to see if that box is checked. If it is then scan and return the port indexes. If it isn't then obviously don't scan.
Code: Select all
case CONFIGWIZARD_MODE_GETSTAGE2HTML:
// get variables that were passed to us
$address=grab_array_var($inargs,"address");
$snmpcommunity=grab_array_var($inargs,"snmpcommunity");
$snmpversion=grab_array_var($inargs,"snmpversion");
$hostname=@gethostbyaddr($address);
if($hostname=="")
$hostname=$address;
$output='
<input type="hidden" name="address" value="'.htmlentities($address).'">
<div class="sectionTitle">'.gettext('Calix Device Details').'</div>
<table>
<tr>
<td>
<label>'.gettext('Calix Device Address').':</label><br class="nobr" />
</td>
<td>
<input type="text" size="40" name="address" id="address" value="'.htmlentities($address).'" class="textfield" disabled/><br class="nobr" />
</td>
</tr>
<tr>
<td>
<label>'.gettext('Host Name').':</label><br class="nobr" />
</td>
<td>
<input type="text" size="20" name="hostname" id="hostname" value="'.htmlentities($hostname).'" class="textfield" /><br class="nobr" />
'.gettext('The name you\'d like to have associated with this Calix device.').'
</td>
</tr>
</table>
<div class="sectionTitle">'.gettext('Device Services').'</div>
<p>'.gettext('Specify which services you\'d like to monitor for the Calix device.').'</p>
<table>
<tr>
<td valign="top">
<input type="checkbox" class="checkbox" id="ping" name="services[ping]" checked>
</td>
<td>
<b>'.gettext('Ping').'</b><br>
'.gettext('Monitors the Calix device with an ICMP ping. Useful for watching network latency and general uptime of your device.').'<br><br>
</td>
</tr>
</table>
';
break;
case CONFIGWIZARD_MODE_VALIDATESTAGE2DATA:
// get variables that were passed to us
$address=grab_array_var($inargs,"address");
$snmpcommunity=grab_array_var($inargs,"snmpcommunity");
$snmpversion=grab_array_var($inargs,"snmpversion");
$hostname=grab_array_var($inargs,"hostname");
// check for errors
$errors=0;
$errmsg=array();
if(is_valid_host_name($hostname)==false)
$errmsg[$errors++]=gettext("Invalid host name.");
if($errors>0){
$outargs[CONFIGWIZARD_ERROR_MESSAGES]=$errmsg;
$result=1;
}
break;
Re: Config Wizard issue
Posted: Tue Apr 01, 2014 4:39 pm
by abrist
What exactly are you having issues with? Creating a checkbox? Preserving the checkbox state moving between wizard pages? Actually running the walk?
I highly suggest that you look at one of the current wizards and lift as much of that code as possible.
Re: Config Wizard issue
Posted: Wed Apr 02, 2014 9:46 am
by kyle.parker
I am having an issue with running the snmpwalk. I tried looking at some of the other config wizards and copying some code from those ones, but when I did that and I loaded the wizard we losts all our other wizards and could no longer use the config wizard functionality until we removed the custom wizard from the nagios server back end. I will try again, as I now have a test server so I don't affect our running instance of nagios again.
Re: Config Wizard issue
Posted: Wed Apr 02, 2014 2:39 pm
by tmcdonald
If you want to toss the code our way in a PM we can take a look at it, see if anything sticks out. Let us know how the test goes though before that.
Re: Config Wizard issue
Posted: Thu Apr 10, 2014 12:29 pm
by kyle.parker
I PM'd you my code for the scan interfaces snippet. It doesn't crash when I load it on my test, but it doesn't even attempt to scan when I go to the next step. The code I tried to parse through from the SNMPWalk wizard seems so complex for when I am trying to do. All I really want to do is scan the device for ports available and then return an array of port with their relative index number. Where you can check off what ports you want to monitor. Like I mentioned we can't use the network switch/router wizard as it creates an rrd file in mrtg whether you want to monitor that port or not. And in turn our server admins come ask why they have 100's of errors from MRTG. We are also trying to utilize a custom plugin that shows BW in a % which will be used in NagVis which is another big reason for trying to create a custom Wizard.
Re: Config Wizard issue
Posted: Thu Apr 10, 2014 4:22 pm
by tmcdonald
One thing that pops out is that your arguments don't seem to have any spacing in between some of them:
Code: Select all
$cmdline="/usr/bin/snmpwalk -v ".escapeshellcmd($snmpversion)." -c ".escapeshellcmd($snmpcommunity).escapeshellcmd($cmdargs)." ".escapeshellcmd($address).":".escapeshellcmd($port)." > ".$resultfile." 2>&1 & echo $!";
should be
Code: Select all
$cmdline="/usr/bin/snmpwalk -v ".escapeshellcmd($snmpversion)." -c ".escapeshellcmd($snmpcommunity)." ".escapeshellcmd($cmdargs)." ".escapeshellcmd($address).":".escapeshellcmd($port)." > ".$resultfile." 2>&1 & echo $!";
I would also look at turning debugging on in your code with the following at the beginning:
Code: Select all
error_reporting(-1);
ini_set('display_errors', 'On');
Re: Config Wizard issue
Posted: Mon Apr 14, 2014 8:44 am
by kyle.parker
Okay, I have taken a completely different route than the one I was trying previously. I actually have the entire wizard working with the custom plugin. The only thing I can't get working is to auto-fill an argument for our config wizard. I am trying to load an array variable in one of the steps so that I can unload it when I get the point where it needs to start filling in arguments for each service. I am going to just add certain lines of code I am having issues with. Hopefully someone can point me in the right direction.
Code: Select all
//defining array counter and defining array variable
$y=0;
$linespeeds=array();
foreach($ports as $port_num => $parr){
//loading array with max port speed from other function called in this loop
$linespeeds[$y++]=$speed;
}
//Go through a few more stages, then in the same stage where where other arrays are serialized for passing to 'case CONFIGWIZARD_MODE_GETOBJECTS:'
$linespeeds=grab_array_var($inargs,"linespeeds");
$linespeeds_serial=grab_array_var($inargs,"linespeeds_serial",base64_encode(serialize($linespeeds)));
<input type="hidden" name="linespeeds_serial" value="'.$linespeeds_serial.'">
<!-- SERVICES='.serialize($services).'<BR>
SERVICEARGS='.serialize($serviceargs).'<BR>
LINESPEEDS='.serialize($linespeeds).'<BR>-->
//In my stage for services
case CONFIGWIZARD_MODE_GETOBJECTS:
$linespeeds_serial=grab_array_var($inargs,"linespeeds_serial","");
$linespeeds=unserialize(base64_decode($linespeeds_serial));
//resetting counters and variables
$y=0;
$speeds=0;
//loop that runs for all ports
foreach($svcstate as $portnum => $portstate){
$speeds=$linespeeds[$y++];
/*This is where I have an issue, I get an error stating uninitialized strings. I know it is working because the other arguments are getting passed and filled in correctly. Just seems I am missing something with my array. This is my error when I put $speeds in 5th line of the $objs[] array, Notice: Uninitialized string offset: 0 in /usr/local/nagiosxi/html/includes/configwizards/CalixWizard/CalixWizard.inc.php on line 655 Notice: Uninitialized string offset: 1 in /usr/local/nagiosxi/html/includes/configwizards/CalixWizard/CalixWizard.inc.php on line 655 Notice: Uninitialized string offset: 2 in /usr/local/nagiosxi/html/includes/configwizards/CalixWizard/CalixWizard.inc.php on line 655*/
$objs[]=array(
"type" => OBJECTTYPE_SERVICE,
"host_name" => $hostname,
"service_description" => $portname." Bandwidth",
"use" => "xiwizard_generic_service",
"check_command" => "check_if_percent_usage!".$snmpcommunity."!".$portnum."!".$speeds."!".$label,
"_xiwizard" => $wizard_name,
Re: Config Wizard issue
Posted: Mon Apr 14, 2014 10:10 am
by kyle.parker
I should also note that my array is filling correctly as I did a print_r($linespeeds) as a debug step and I got Array ( [0] => 1 [1] => 10 [2] => 1 ), which is exactly what I would expect. As my first port is a 1Gbps, second is 10Gbps, third is 1Gbps. I guess I am just having trouble passing it and then referencing a single value in the array when I need it.