Jump to content

jscript


Recommended Posts

I am trying to learn jscript and do some things that I have been doing in php for a while. I have a loop going and I would like to change a variable each time through the loop.

 

here is what the loop looks like.

while ( !oRs.EOF )
{

	var nIndex = "" + oRs("nIfIndex");
	Context.LogMessage( "nIndex= " + nIndex);


	// Do the actual polling:

		var nInOctets = getInOctets(nIndex);
		Context.LogMessage( "nInOctets= " + nInOctets);
		var nOutOctets = getOutOctets(nIndex);
		Context.LogMessage( "nOutOctets= " + nOutOctets);
		var nIfSpeed = getIfSpeed(nIndex);
		Context.LogMessage( "nIfSpeed= " + nIfSpeed);

	if (isNaN(nInOctets) == true || isNaN(nOutOctets) == true || isNaN(nIfSpeed) == true)
	{
		Context.SetResult(1, "Failure to poll this device1.");
	}
	else
	{

		// Retrieve the octets value and date of the last poll saved in a context variable:
		var nInOutOctetsMonitorPreviousPolledValueIn = new Array();
		var nInOutOctetsMonitorPreviousPolledValueOut = new Array();
		var nInOutOctetsMonitorPreviousPollDate = new Array();
		nInOutOctetsMonitorPreviousPolledValueIn["nIndex"] = Context.GetProperty("nInOutOctetsMonitorPreviousPolledValueIn["nIndex"]");
		nInOutOctetsMonitorPreviousPolledValueOut["nIndex"] = Context.GetProperty("nInOutOctetsMonitorPreviousPolledValueOut["nIndex"]");
		nInOutOctetsMonitorPreviousPollDate["nIndex"] = Context.GetProperty("nInOutOctetsMonitorPreviousPollDate["nIndex"]");

		Context.LogMessage( "nInOutOctetsMonitorPreviousPolledValueIn["nIndex"]= " + nInOutOctetsMonitorPreviousPolledValueIn["nIndex"]);

		if (nInOutOctetsMonitorPreviousPolledValueIn["nIndex"] == null || nInOutOctetsMonitorPreviousPolledValueOut["nIndex"] == null || nInOutOctetsMonitorPreviousPollDate["nIndex"] == null)
		{
			// the context variable has never been set, this is the first time we are polling.
			Context.LogMessage("This monitor requires two polls.");
			Context.SetResult(0, "success");
			var nFail = 1;
		}
		else
		{


		}

		// Save this poll information in the context variables:
		Context.PutProperty("nInOutOctetsMonitorPreviousPolledValueIn["nIndex"]", nInOctets)
		Context.PutProperty("nInOutOctetsMonitorPreviousPolledValueOut["nIndex"]", nOutOctets)
		Context.PutProperty("nInOutOctetsMonitorPreviousPollDate["nIndex"]", nPollDate);
	}

	oRs.moveNext();
}

 

Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/55458-jscript/
Share on other sites

After thinking about it I see that the code that I posted was not even close to what I wanted to do. here is a new version and some more info.

 

What I am trying to do is add to an array each time through the loop using a variable as the array key. and then use that variable to pull that entry form the array later.

 

here is what I am working with now.

while ( !oRs.EOF )
{

	var nIndex = "" + oRs("nIfIndex");
	Context.LogMessage( "nIndex= " + nIndex);


	// Do the actual polling:
		var nInOctets = new Array();
		nInOctets[nIndex] = getInOctets(nIndex);
		Context.LogMessage( "nInOctets= " + nInOctets);

		var nOutOctets = new Array();
		nOutOctets[nIndex] = getOutOctets(nIndex);
		Context.LogMessage( "nOutOctets= " + nOutOctets);

		var nIfSpeed = getIfSpeed(nIndex);
		Context.LogMessage( "nIfSpeed= " + nIfSpeed);

	}
	Context.LogMessage( "nInOctets= " + nInOctets[1]);
	// Save this poll information in the context variables:
	Context.PutProperty("nInOutOctetsMonitorPreviousPolledValueIn", nInOctets)
	Context.PutProperty("nInOutOctetsMonitorPreviousPolledValueOut", nOutOctets)
	Context.PutProperty("nInOutOctetsMonitorPreviousPollDate", nPollDate);
	oRs.moveNext();
}

 

the output of

Context.LogMessage( "nInOctets= " + nInOctets);

only shows the last enty in the array.

 

Any ideas? make any sense at all?

 

 

Link to comment
https://forums.phpfreaks.com/topic/55458-jscript/#findComment-274155
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.