#!/usr/local/Hughes/bin/lite
/*
** 	Title	: cisco_isdn 
**	Purpose	: Grab a Cisco ISDN call history table
**	Author	: David J. Hughes  (bambi@Hughes.com.au)
*/

modload "mod_snmp";


$CALL_TABLE = "enterprises.cisco.ciscoMgmt.ciscoCallHistoryMib.ciscoCallHistoryMibObjects.ciscoCallHistory.ciscoCallHistoryTable.ciscoCallHistoryEntry";
/*
** Check command line args
*/

if ($argc != 3)
{
	echo("\nUsage : cisco_isdn hostname community\n\n");
	exit(1);
}

printf("\nDumping ISDN call table from %s using a community of %s\n\n",
	$argv[1], $argv[2]);

/*
** Fire up SNMP and get a connection to the box
*/

$fd = snmpopen($argv[1],$argv[2]);
if ($fd < 0)
{
	printf("\n\n%s : %s!\n\n",$argv[0], $ERRMSG);
	exit(1);
}


/*
** Print a header
*/
echo("   Hostname     Entry       OutBytes        InBytes      \n");
echo("----------------------------------------------------------\n");


/*
** Setup the variables we want to snarf and then loop until the
** getnext returns an object ID with a different prefix.
*/

$vars[0] = "$CALL_TABLE.ciscoCallHistoryDestinationHostName";
$vars[1] = "$CALL_TABLE.ciscoCallHistoryTransmitBytes";
$vars[2] = "$CALL_TABLE.ciscoCallHistoryReceiveBytes";

$testCase = $vars[0];

while($vars[0] =~ $testCase)
{
	$result = snmpgetnext($fd,$vars);
	$index = 0;

	if ( # $result == 0)
	{
		printf("\n%s : $ERRMSG\n",$argv[0]);
		exit(1);
	}

	/*
	** Loop through the returned array splitting the returned
	** OID from the returned data.  Store each part in a new
	** array for later use.
	*/

	while($index < #$result)
	{
		$data = split($result[$index],LITE_BRK);
		$vars[$index] = $data[0];
		$out[$index] = $data[1];
		$index = $index + 1;
	}


	/*
	** Work out the table entry number
	*/
	$tmp = split($vars[0],".");
	$entry = $tmp[#$tmp -1];

	/*
	** Print the results
	*/
	$outBytes = (uint)$out[1];
	$inBytes = (uint)$out[2];
	if($vars[0] =~ $testCase)
	{
		printf(" %-15s %-4s %15s %15s\n",$out[0], $entry,
			(char)$outBytes, (char)$inBytes);
	}

}

echo("----------------------------------------------------------\n");
