SOLVED: Help with Script Data Queries

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

shull
Cacti User
Posts: 54
Joined: Thu Aug 24, 2006 1:20 am
Location: South Texas
Contact:

SOLVED: Help with Script Data Queries

Post by shull »

I am trying to make my script work and I am having problems. I have followed the docs and I have the script executing as it should. Here are some of the results:


[root@localhost scripts]# ./multiple_index_resolve_test2.pl 192.168.1.250 public query ifSpeed
1:10000000
65539:1000000000

[root@localhost scripts]# ./multiple_index_resolve_test2.pl 192.168.1.250 public query ifInOctets
1:299098223
65539:4268454900

[root@localhost scripts]# ./multiple_index_resolve_test2.pl 192.168.1.152 public query ifInOctets
1:384
2:49174705
3:64
4:64
5:64
6:64
7:64
8:64
9:64
10:61729483
11:64
12:404570335
13:0
14:299261527

[root@localhost scripts]# ./multiple_index_resolve_test2.pl 192.168.1.152 public query ifInErrors
1:0
2:0
3:0
4:0
5:0
6:0
7:0
8:0
9:0
10:0
11:0
12:0
13:0
14:0

[root@localhost scripts]# ./multiple_index_resolve_test2.pl 192.168.1.152 public query ifDescr
1:FastEthernet0/1
2:FastEthernet0/2
3:FastEthernet0/3
4:FastEthernet0/4
5:FastEthernet0/5
6:FastEthernet0/6
7:FastEthernet0/7
8:FastEthernet0/8
9:FastEthernet0/9
10:FastEthernet0/10
11:FastEthernet0/11
12:FastEthernet0/12
13:Null0
14:Vlan1

[root@localhost scripts]# ./multiple_index_resolve_test2.pl 192.168.1.152 public query ifPhysAddress
1:0x000c852890c1
2:0x000c852890c2
3:0x000c852890c3
4:0x000c852890c4
5:0x000c852890c5
6:0x000c852890c6
7:0x000c852890c7
8:0x000c852890c8
9:0x000c852890c9
10:0x000c852890ca
11:0x000c852890cb
12:0x000c852890cc
13:
14:0x000c852890c0




Here is the XML file I am using:



- <interface>
<name>Cisco 2950</name>
<description>Cisco Catalyst 2950-12 Switch</description>
<arg_query>query</arg_query>
<arg_get>get</arg_get>
<arg_prepend>|host_hostname| |host_snmp_community|</arg_prepend>
<arg_index>index</arg_index>
<script_path>/usr/bin/perl |path_cacti|/scripts/multiple_index_resolve_test2.pl</script_path>
<output_delimiter>,</output_delimiter>
<index_title_format>|chosen_order_field|</index_title_format>
<index_order>ifIndex</index_order>
<index_order_type>numeric</index_order_type>
<oid_index_parse />
<oid_num_indexes />
<oid_index>.1.3.6.1.2.1.2.2.1.1</oid_index>
- <fields>
<ifIndex>
<name>ifIndex</name>
<direction>input</direction>
<query_name>ifIndex</query_name>
</ifIndex>
<ifStatus>
<name>ifStatus</name>
<direction>input</direction>
<query_name>ifStatus</query_name>
</ifStatus>
<ifDescr>
<name>ifDescr</name>
<direction>input</direction>
<query_name>ifDescr</query_name>
</ifDescr>
<ifName>
<name>ifName</name>
<direction>input</direction>
<query_name>ifName</query_name>
</ifName>
<ifAlias>
<name>ifAlias</name>
<direction>input</direction>
<query_name>ifAlias</query_name>
</ifAlias>
<ifType>
<name>ifType</name>
<direction>input</direction>
<query_name>ifType</query_name>
</ifType>
<ifInOctets>
<name>ifInOctets</name>
<direction>output</direction>
<query_name>ifInOctets</query_name>
</ifInOctets>
<ifInUcastPkts>
<name>ifInUcastPkts</name>
<direction>output</direction>
<query_name>ifInUcastPkts</query_name>
</ifInUcastPkts>
<ifInNUcastPkts>
<name>ifInNUcastPkts</name>
<direction>output</direction>
<query_name>ifInNUcastPkts</query_name>
</ifInNUcastPkts>
<ifInDiscards>
<name>ifInDiscards</name>
<direction>output</direction>
<query_name>ifInDiscards</query_name>
</ifInDiscards>
<ifInErrors>
<name>ifInErrors</name>
<direction>output</direction>
<query_name>ifInErrors</query_name>
</ifInErrors>
<ifInUnknownProtos>
<name>ifInUnknownProtos</name>
<direction>output</direction>
<query_name>ifInUnknownProtos</query_name>
</ifInUnknownProtos>
<ifSpeed>
<name>ifSpeed</name>
<direction>input</direction>
<query_name>ifSpeed</query_name>
</ifSpeed>
<ifPhysAddress>
<name>ifPhysAddress</name>
<direction>input</direction>
<query_name>ifPhysAddress</query_name>
</ifPhysAddress>
<ifOutOctets>
<name>ifOutOctets</name>
<direction>output</direction>
<query_name>ifOutOctets</query_name>
</ifOutOctets>
<ifOutUcastPkts>
<name>ifOutUcastPkts</name>
<direction>output</direction>
<query_name>ifOutUcastPkts</query_name>
</ifOutUcastPkts>
<ifOutNUcastPkts>
<name>ifOutNUcastPkts</name>
<direction>output</direction>
<query_name>ifOutNUcastPkts</query_name>
</ifOutNUcastPkts>
<ifOutDiscards>
<name>ifOutDiscards</name>
<direction>output</direction>
<query_name>ifOutDiscards</query_name>
</ifOutDiscards>
<ifOutErrors>
<name>ifOutErrors</name>
<direction>output</direction>
<query_name>ifOutErrors</query_name>
</ifOutErrors>
</fields>
</interface>



When I run a verbose query, I get this:

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Notice: Undefined index: output_delimeter in /var/www/html/lib/data_query.php on line 116

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/lib/data_query.php:116) in /var/www/html/host.php on line 77

When I execute the script from the command line, it works fine. When I set it up as a device in Cacti, I get this from the Cacti screen.

Please give me direction.


Thanks,

Stephen
Attachments
Cacti Screen
Cacti Screen
cacti-sdq-issue1.JPG (31.33 KiB) Viewed 3115 times
Last edited by shull on Tue Sep 04, 2007 3:04 pm, edited 1 time in total.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

There are some syntax errors in your XML, like
<oid_index_parse />
<oid_num_indexes />
Please correct and retry
Reinhard
shull
Cacti User
Posts: 54
Joined: Thu Aug 24, 2006 1:20 am
Location: South Texas
Contact:

Post by shull »

I just removed those and I still have the same problem. Any other ideas?
shull
Cacti User
Posts: 54
Joined: Thu Aug 24, 2006 1:20 am
Location: South Texas
Contact:

Post by shull »

Can someone tell me what those errors pertain to or what they mean? If I knew that, I could probably figure it out.

Also, here is the script:

Code: Select all

#!/usr/bin/perl -Wall
use strict;

use vars qw( $session @print_names @print_values %oid_list);

use Net::SNMP qw(:snmp);

undef $,;
undef $\;

##
# usage
#
sub usage()
{
	print "\nusage: $0 hostname community [cmd] [field] [index]\n";
	exit 1;
}

##
# resolve_oid
#
sub resolve_oid
{
	my ($oid) = @_;

	my $result = $session->get_request($oid);
	
	die "unable to resolve oid '" . $oid . "'" unless(defined $result);
	
#	print "resolv_oid(): OID '" . $oid . "' = '" . $result->{$oid} . "'\n";

	return $result->{$oid};
}


##
# walk_oid
#
sub walk_oid
{
	my ($oid) = @_;
	my $resultHash = {};
	
	my $nextOid = $oid;
	
	while (defined($nextOid))
	{
		my $bulkResult = $session->get_bulk_request( -maxrepetitions => 10, -varbindlist => [$nextOid] );

		die "unable to walk oid '" . $oid . "'" unless(defined $bulkResult);

		foreach my $tempOid (oid_lex_sort(keys(%$bulkResult)))
		{
			if (!oid_base_match($oid, $tempOid))
			{
				$nextOid = undef;
				last;
			}
			else
			{
				$nextOid = $tempOid;
				$resultHash->{$tempOid} = $bulkResult->{$tempOid};
			}
		}
	}
	
	return $resultHash;
}

##
# print_oid
#
sub print_oid
{
	my ($name, $value) = @_;

	my $refType = ref($value);
	
	# array?
	if ($refType eq 'ARRAY')
	{
		for (my $i = 0, my $n = scalar(@$value); $i < $n; $i++)
		{
			push @print_names , $name . '_' . ($i + 1);
			push @print_values, $value->[$i];
		}
	}
	# scalar?
	elsif ($refType eq '')
	{
		push @print_names , $name;
		push @print_values, $value;
	}
	else
	{
		die "Unknown ref type '" . $refType . "' for print value with name '" . $name . "'";
	}
}

##
# process_command
#
sub process_command
{
	my ($cmd, $field, $index_pos) = @_;

	if (!exists($oid_list{'index'}))
	{
		die "Command 'index' called in non-indexed script";
	}

	# list?
	if ($cmd eq 'list')
	{
		print "Here is a list of all the oids defined in this file:\n";
		
		foreach my $oid_name (keys %oid_list)
		{
			print "  ${oid_name} -> ${oid_list{$oid_name}}\n";
		}
	}
	# index?
	elsif ($cmd eq 'index')
	{
		my $index_values = reindex(walk_oid($oid_list{'index'}));
		
		for (my $i = 0; $i < scalar(@$index_values); $i++)
		{
			print $index_values->[$i] . "\n";
		}
	}
	else
	{
		# query?
		if ($cmd eq 'query')
		{
			if (!$field)
			{
				foreach my $oid_name (keys %oid_list)
				{
					if ($oid_name ne 'index')
					{
						if ($field)
						{
							die "Cannot call 'query' command with no 'field' parameter when multiple oids are defined";
						}
						else
						{
							$field = $oid_name;
						}
					}
				}
			}
			else
			{
				if (!exists($oid_list{$field}))
				{
					die "Field '${field}' is not defined in this script";
				}
			}

			my $index_values = reindex(walk_oid($oid_list{'index'}));
			
			my $query_values;
	
			if ($field eq 'index')
			{
				$query_values = $index_values;
			}
			else
			{
				$query_values = reindex(walk_oid($oid_list{$field}));
			}
			
			for (my $i = 0; $i < scalar(@$index_values); $i++)
			{
				print $index_values->[$i] . ':' . $query_values->[$i] . "\n";
			}
		}
		elsif ($cmd eq 'get')
		{
			if (!$field)
			{
				die "Missing 'field' parameter required for 'query' command";
			}
			if (!exists($oid_list{$field}))
			{
				die "Field '${field}' is not defined in this script";
			}
			if (!$index_pos)
			{
				die "Missing 'index' parameter required for 'get' command";
			}

			# Shortcut for 'index' which could print an invalid value
			if ($field eq 'index')
			{
				print $index_pos;
			}
			else
			{
				my $index_value = resolve_oid($oid_list{$field} . '.' . $index_pos);

				print $index_value;
			}
		}
		else
		{
			die "Unknown command '${cmd}'";
		}
	}
}

##
# reindex - Takes a hash of oid's and returns an array of values
#           in the order of oid_lex_sort of the oid's
#
sub reindex
{
	my ($hash) = @_;

	my $values = [];

	foreach my $oid (oid_lex_sort(keys(%$hash)))
	{
		push(@$values, $hash->{$oid});
	}
	
	return $values;
}

##
# print_final
#
sub print_final
{
	if (scalar(@print_values) != scalar(@print_names))
	{
		die "Error: scalar(\@print_values) != scalar(\@print_names)";
	}
	
	if (scalar(@print_values) <= 0)
	{
		die "Error: Nothing to print!";
	}

	if (scalar(@print_values) == 1)
	{
		print $print_values[0];
	}
	elsif (scalar(@print_values) > 1)
	{
		for (my $i = 0, my $n = scalar(@print_values); $i < $n; $i++)
		{
			if ($i > 0)
			{
				print ' ';
			}
			print $print_names[$i] . ':' . $print_values[$i];
		}
	}
}

my $snmp_hostName  = $ARGV[0] or usage();
my $snmp_community = $ARGV[1] or usage();
my $cacti_cmd      = $ARGV[2] || '';
my $cacti_field    = $ARGV[3] || '';
my $cacti_index    = $ARGV[4] || '';

my $error;

@print_names  = ();
@print_values = ();
%oid_list     = ();

# requires a hostname and a community string as its arguments
($session, $error) = Net::SNMP->session('Hostname' => $snmp_hostName, 'Community' => $snmp_community, 'version' => 'snmpv2c');

die "session error: $error" unless ($session);

##### START DYNAMIC SCRIPT ####

my $index = '1.3.6.1.2.1.2.2.1.1';
$oid_list{'index'} = '1.3.6.1.2.1.2.2.1.1';
my $ifIndex = '1.3.6.1.2.1.2.2.1.1';
$oid_list{'ifIndex'} = '1.3.6.1.2.1.2.2.1.1';
my $ifStatus = '1.3.6.1.2.1.2.2.1.8';
$oid_list{'ifStatus'} = '1.3.6.1.2.1.2.2.1.8';
my $ifDescr = '1.3.6.1.2.1.2.2.1.2';
$oid_list{'ifDescr'} = '1.3.6.1.2.1.2.2.1.2';
my $ifType = '1.3.6.1.2.1.2.2.1.3';
$oid_list{'ifType'} = '1.3.6.1.2.1.2.2.1.3';
my $ifInOctets = '1.3.6.1.2.1.2.2.1.10';
$oid_list{'ifInOctets'} = '1.3.6.1.2.1.2.2.1.10';
my $ifInUcastPkts = '1.3.6.1.2.1.2.2.1.11';
$oid_list{'ifInUcastPkts'} = '1.3.6.1.2.1.2.2.1.11';
my $ifInNUcastPkts = '1.3.6.1.2.1.2.2.1.12';
$oid_list{'ifInNUcastPkts'} = '1.3.6.1.2.1.2.2.1.12';
my $ifInDiscards = '1.3.6.1.2.1.2.2.1.13';
$oid_list{'ifInDiscards'} = '1.3.6.1.2.1.2.2.1.13';
my $ifInErrors = '1.3.6.1.2.1.2.2.1.14';
$oid_list{'ifInErrors'} = '1.3.6.1.2.1.2.2.1.14';
my $ifInUnknownProtos = '1.3.6.1.2.1.2.2.1.15';
$oid_list{'ifInUnknownProtos'} = '1.3.6.1.2.1.2.2.1.15';
my $ifSpeed = '1.3.6.1.2.1.2.2.1.5';
$oid_list{'ifSpeed'} = '1.3.6.1.2.1.2.2.1.5';
my $ifPhysAddress = '1.3.6.1.2.1.2.2.1.6';
$oid_list{'ifPhysAddress'} = '1.3.6.1.2.1.2.2.1.6';
my $ifOutOctets = '1.3.6.1.2.1.2.2.1.16';
$oid_list{'ifOutOctets'} = '1.3.6.1.2.1.2.2.1.16';
my $ifOutUcastPkts = '1.3.6.1.2.1.2.2.1.17';
$oid_list{'ifOutUcastPkts'} = '1.3.6.1.2.1.2.2.1.17';
my $ifOutNUcastPkts = '1.3.6.1.2.1.2.2.1.18';
$oid_list{'ifOutNUcastPkts'} = '1.3.6.1.2.1.2.2.1.18';
my $ifOutDiscards = '1.3.6.1.2.1.2.2.1.19';
$oid_list{'ifOutDiscards'} = '1.3.6.1.2.1.2.2.1.19';
my $ifOutErrors = '1.3.6.1.2.1.2.2.1.20';
$oid_list{'ifOutErrors'} = '1.3.6.1.2.1.2.2.1.20';

#### END DYNAMIC SCRIPT ####

if ($cacti_cmd)
{
	process_command($cacti_cmd, $cacti_field, $cacti_index);
}
else
{

	print_final();
	print "\n";
}

$session->close;


Thanks,

Stephen[/code]
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Please post your current XML file as an attachment.
Reinhard
shull
Cacti User
Posts: 54
Joined: Thu Aug 24, 2006 1:20 am
Location: South Texas
Contact:

Post by shull »

Here it is:


Thanks!
Attachments
xmlmultiresolvetest1.xml
XML File
(2.72 KiB) Downloaded 150 times
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

I did not find any obvious error in there. I recommend reading http://docs.cacti.net/node/284. Please try to build a second Script/XML step-by-step as given in this HowTo. This should help you tracking down the error
Reinhard
shull
Cacti User
Posts: 54
Joined: Thu Aug 24, 2006 1:20 am
Location: South Texas
Contact:

Post by shull »

Thanks,

I did follow that. That is what the script and XML are based on.

If someone could tell me what the error means, I could take it from there. What is Cacti looking for, exactly?

The documentation is good at explaining the "what you do" but there is not any "why you do this" or "here are the reasons this works this way". That, to me, is critical in trying to figure out why something isn't working.

If you have any more knowledge on this, please let me know. How can I see more from the debug logs? Can I log more information? The docs are fine, but they aren't good enough for this issue.

Thanks,

Stephen
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

gandalf wrote:There are some syntax errors in your XML, like
<oid_index_parse />
<oid_num_indexes />
Please correct and retry
Reinhard
Btw, that is correct XML.

That is a short cut for:

Code: Select all

<oid_index_parse></oid_index_parse>
<oid_num_indexes></oid_num_indexes> 
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
shull
Cacti User
Posts: 54
Joined: Thu Aug 24, 2006 1:20 am
Location: South Texas
Contact:

Post by shull »

OK.

I think I am getting somewhere. Here is what the docs say the output needs to be:

Code: Select all

+ Running data query [21].
+ Found type = '4 '[script query].
+ Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml'
+ XML file parsed ok.
+ Executing script for list of indexes '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" index'
+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query index'
+ Found item [ifIndex='1'] index: 1
+ Found item [ifIndex='2'] index: 2
+ Found item [ifIndex='3'] index: 3
+ Found item [ifIndex='4'] index: 4
+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifstatus'
+ Found item [ifstatus='up(1)'] index: 1
+ Found item [ifstatus='up(1)'] index: 2
+ Found item [ifstatus='up(1)'] index: 3
+ Found item [ifstatus='up(1)'] index: 4
+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifdescription'
+ Found item [ifdescription='Ethernet0'] index: 1
+ Found item [ifdescription=''] index: 2
+ Found item [ifdescription=''] index: 3
+ Found item [ifdescription='Ethernet1'] index: 4
+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifname'
+ Found item [ifname=''] index: 1
+ Found item [ifname=''] index: 2
+ Found item [ifname=''] index: 3
+ Found item [ifname=''] index: 4
+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifalias'
+ Found item [ifalias=''] index: 1
+ Found item [ifalias=''] index: 2
+ Found item [ifalias=''] index: 3
+ Found item [ifalias=''] index: 4
+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query iftype'
+ Found item [iftype='ethernetCsmacd(6)'] index: 1
+ Found item [iftype='0'] index: 2
+ Found item [iftype='0'] index: 3
+ Found item [iftype='ethernetCsmacd(6)'] index: 4
+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifspeed'
+ Found item [ifspeed='100000000'] index: 1
+ Found item [ifspeed='0'] index: 2
+ Found item [ifspeed='0'] index: 3
+ Found item [ifspeed='10000000'] index: 4
+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifHWaddress'
+ Found item [ifHWaddress='00:30:30:2E:35:30:2E:37:46:2E:30:43:2E:30:30:2E:44:16:00:00:00:01:00'] index: 1
+ Found item [ifHWaddress=''] index: 2
+ Found item [ifHWaddress=''] index: 3
+ Found item [ifHWaddress=''] index: 4
+ Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml'
+ Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml'
+ Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml'


Here is my output. Notice the difference in the items it finds. Is this a problem?

Code: Select all

+ Running data query [11].
+ Found type = '4 '[script query].
+ Found data query XML file at '/var/www/html/resource/script_queries/xmlmultiresolvetest1.xml'
+ XML file parsed ok.
+ Executing script for list of indexes '/usr/bin/perl /var/www/html/scripts/multiple_index_resolve_test2.pl 192.168.1.152 public index'
+ Executing script query '/usr/bin/perl /var/www/html/scripts/multiple_index_resolve_test2.pl 192.168.1.152 public query ifIndex'
+ Found item [ifIndex=''] index: 1:1
+ Found item [ifIndex=''] index: 2:2
+ Found item [ifIndex=''] index: 3:3
+ Found item [ifIndex=''] index: 4:4
+ Found item [ifIndex=''] index: 5:5
+ Found item [ifIndex=''] index: 6:6
+ Found item [ifIndex=''] index: 7:7
+ Found item [ifIndex=''] index: 8:8
+ Found item [ifIndex=''] index: 9:9
+ Found item [ifIndex=''] index: 10:10
+ Found item [ifIndex=''] index: 11:11
+ Found item [ifIndex=''] index: 12:12
+ Found item [ifIndex=''] index: 13:13
+ Found item [ifIndex=''] index: 14:14
+ Executing script query '/usr/bin/perl /var/www/html/scripts/multiple_index_resolve_test2.pl 192.168.1.152 public query ifStatus'
+ Found item [ifStatus=''] index: 1:2
+ Found item [ifStatus=''] index: 2:1
+ Found item [ifStatus=''] index: 3:2
+ Found item [ifStatus=''] index: 4:2
+ Found item [ifStatus=''] index: 5:2
+ Found item [ifStatus=''] index: 6:2
+ Found item [ifStatus=''] index: 7:1
+ Found item [ifStatus=''] index: 8:2
+ Found item [ifStatus=''] index: 9:2
+ Found item [ifStatus=''] index: 10:1
+ Found item [ifStatus=''] index: 11:2
+ Found item [ifStatus=''] index: 12:1
+ Found item [ifStatus=''] index: 13:1
+ Found item [ifStatus=''] index: 14:1
+ Executing script query '/usr/bin/perl /var/www/html/scripts/multiple_index_resolve_test2.pl 192.168.1.152 public query ifDescr'
+ Found item [ifDescr=''] index: 1:FastEthernet0/1
+ Found item [ifDescr=''] index: 2:FastEthernet0/2
+ Found item [ifDescr=''] index: 3:FastEthernet0/3
+ Found item [ifDescr=''] index: 4:FastEthernet0/4
+ Found item [ifDescr=''] index: 5:FastEthernet0/5
+ Found item [ifDescr=''] index: 6:FastEthernet0/6
+ Found item [ifDescr=''] index: 7:FastEthernet0/7
+ Found item [ifDescr=''] index: 8:FastEthernet0/8
+ Found item [ifDescr=''] index: 9:FastEthernet0/9
+ Found item [ifDescr=''] index: 10:FastEthernet0/10
+ Found item [ifDescr=''] index: 11:FastEthernet0/11
+ Found item [ifDescr=''] index: 12:FastEthernet0/12
+ Found item [ifDescr=''] index: 13:Null0
+ Found item [ifDescr=''] index: 14:Vlan1
+ Executing script query '/usr/bin/perl /var/www/html/scripts/multiple_index_resolve_test2.pl 192.168.1.152 public query ifName'
+ Executing script query '/usr/bin/perl /var/www/html/scripts/multiple_index_resolve_test2.pl 192.168.1.152 public query ifAlias'
+ Executing script query '/usr/bin/perl /var/www/html/scripts/multiple_index_resolve_test2.pl 192.168.1.152 public query ifType'
+ Found item [ifType=''] index: 1:6
+ Found item [ifType=''] index: 2:6
+ Found item [ifType=''] index: 3:6
+ Found item [ifType=''] index: 4:6
+ Found item [ifType=''] index: 5:6
+ Found item [ifType=''] index: 6:6
+ Found item [ifType=''] index: 7:6
+ Found item [ifType=''] index: 8:6
+ Found item [ifType=''] index: 9:6
+ Found item [ifType=''] index: 10:6
+ Found item [ifType=''] index: 11:6
+ Found item [ifType=''] index: 12:6
+ Found item [ifType=''] index: 13:1
+ Found item [ifType=''] index: 14:53
+ Executing script query '/usr/bin/perl /var/www/html/scripts/multiple_index_resolve_test2.pl 192.168.1.152 public query ifSpeed'
+ Found item [ifSpeed=''] index: 1:100000000
+ Found item [ifSpeed=''] index: 2:100000000
+ Found item [ifSpeed=''] index: 3:10000000
+ Found item [ifSpeed=''] index: 4:10000000
+ Found item [ifSpeed=''] index: 5:10000000
+ Found item [ifSpeed=''] index: 6:10000000
+ Found item [ifSpeed=''] index: 7:100000000
+ Found item [ifSpeed=''] index: 8:10000000
+ Found item [ifSpeed=''] index: 9:10000000
+ Found item [ifSpeed=''] index: 10:100000000
+ Found item [ifSpeed=''] index: 11:10000000
+ Found item [ifSpeed=''] index: 12:100000000
+ Found item [ifSpeed=''] index: 13:4294967295
+ Found item [ifSpeed=''] index: 14:1000000000
+ Executing script query '/usr/bin/perl /var/www/html/scripts/multiple_index_resolve_test2.pl 192.168.1.152 public query ifPhysAddress'
+ Found item [ifPhysAddress=''] index: 1:0x000c852890c1
+ Found item [ifPhysAddress=''] index: 2:0x000c852890c2
+ Found item [ifPhysAddress=''] index: 3:0x000c852890c3
+ Found item [ifPhysAddress=''] index: 4:0x000c852890c4
+ Found item [ifPhysAddress=''] index: 5:0x000c852890c5
+ Found item [ifPhysAddress=''] index: 6:0x000c852890c6
+ Found item [ifPhysAddress=''] index: 7:0x000c852890c7
+ Found item [ifPhysAddress=''] index: 8:0x000c852890c8
+ Found item [ifPhysAddress=''] index: 9:0x000c852890c9
+ Found item [ifPhysAddress=''] index: 10:0x000c852890ca
+ Found item [ifPhysAddress=''] index: 11:0x000c852890cb
+ Found item [ifPhysAddress=''] index: 12:0x000c852890cc
+ Found item [ifPhysAddress=''] index: 13:
+ Found item [ifPhysAddress=''] index: 14:0x000c852890c0
+ Found data query XML file at '/var/www/html/resource/script_queries/xmlmultiresolvetest1.xml'
+ Found data query XML file at '/var/www/html/resource/script_queries/xmlmultiresolvetest1.xml'
+ Found data query XML file at '/var/www/html/resource/script_queries/xmlmultiresolvetest1.xml'


When I run my script fro mthe command line, it outputs data in the form of:

1:2345
2:343433
3:3434



or

1:wewew
2:gdfgdfg
...


This is how the docs said to do it. Is this a problem? That is the only difference I see with the examples in the docs and my script.

I am not sure if this is part of the problem. I am still getting the error when I run a Verbose Query, but it now shows the above information on the Cacti screen.

Please give me some insight.


Thanks,

Stephen
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

As per http://docs.cacti.net/node/285, calling your script using the parameter index should return a list of indices, one on each line. Please post the result of your script when using this very parameter.
@Tony: Yes, you're quite right. That's the result of spending only a few seconds for quite complex questions. I apologize
Reinhard
shull
Cacti User
Posts: 54
Joined: Thu Aug 24, 2006 1:20 am
Location: South Texas
Contact:

Post by shull »

Here is the output.
[root@localhost ~]# cd /var/www/html/scripts
[root@localhost scripts]# ./multiple_index_resolve_test2.pl 192.168.1.152 public index
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@localhost scripts]#


Here is another.

[root@localhost scripts]# ./multiple_index_resolve_test2.pl 192.168.1.250 public index
1
65539
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Well, this looks fine. Your case will require more time. Hope I find this time this weekend. But documentation of 0.8.7 is waiting for me ...
Reinhard
shull
Cacti User
Posts: 54
Joined: Thu Aug 24, 2006 1:20 am
Location: South Texas
Contact:

Post by shull »

Thanks for trying to help.

In your opinion, does the output looks right? What should I see in the debugs? What should the verbose query look like?

Thanks,

Stephen
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

I've managed to debug it and produce reasonable results. Then I withdraw my debugging changes and it worked as well!?!
Now, I suspect re-indexing issues. To clarify, please perform:
- a re-index by pressing the green circle next to your data query
- following sql command

Code: Select all

SELECT *
FROM `host_snmp_cache`
WHERE `host_id` =2
AND `snmp_query_id` =10
where "2" is the number of the host you've applied the data query to and "10" is the nuber of that very data query. If you place your mouse above the "Verbose Query" link, you will find both numbers as "host_id" and "id", respectively

Reinhard
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests