use Sys::Virt;
use Sys::Guestfs;
use Sys::Guestfs::Lib qw(open_guest get_partitions);
+use Net::SNMP;
+
+use Data::Dumper;
+
use Pod::Usage;
use Getopt::Long;
+
use Locale::TextDomain 'virt-tools';
-use Net::SNMP;
=encoding utf8
close PIPE;
}
- print "XXX PING XXX\n";
+ my ($hostname, $port, $domain);
+ if ($transport =~ /^udp:(.*):(.*)/) {
+ $domain = "udp";
+ $hostname = $1;
+ $port = $2;
+ } elsif ($transport =~ /^tcp:(.*):(.*)/) {
+ $domain = "tcp";
+ $hostname = $1;
+ $port = $2;
+ } else {
+ die __x("unknown transport type: {t}", t => $transport);
+ }
+
+ if ($verbose) {
+ print STDERR "creating Net::SNMP session to $domain:$hostname:$port with key $key\n"
+ }
+
+ my ($session, $error) = Net::SNMP->session (
+ -version => 3,
+ -username => "virttools",
+ -authpassword => $key,
+ -authprotocol => "sha",
+ -privpassword => $key,
+ -privprotocol => "aes",
+ -hostname => $hostname,
+ -port => $port,
+ -domain => $domain,
+ );
+ return 0 unless $session;
+
+ my $sysUpTime = "1.3.6.1.2.1.1.3.0";
+ my $r = $session->get_request (-varbindlist => [$sysUpTime])
+ or return 0;
+ print STDERR "test_transport: sysUpTime = $r->{$sysUpTime}\n" if $verbose;
+
+ $session->close ();
1;
}
sub title_uname
{
- print_row (__"Guest");
+ print_row (__"Guest", __"System name");
}
sub do_uname
my $key = shift;
my $transport = shift;
-
-
+ my $session = get_snmp_session ($key, $transport);
+ my $sysDescr = "1.3.6.1.2.1.1.1.0";
+ my $r = $session->get_request (-varbindlist => [$sysDescr])
+ or die __x("SNMP error: {e}", $session->error);
+ print_row ($domname, $r->{$sysDescr});
+ $session->close;
}
=head1 virt-ps
my $comma = 0;
foreach (@fields) {
- print "," if $comma;
- $comma = 1;
-
if (!$csv) {
printf "%-16s ", $_
} else {
+ print "," if $comma;
+ $comma = 1;
+
# XXX Use Text::CSV here.
if ($_ =~ /"/) {
s/"/""/;
To determine what precise queries are sent, run the tools in verbose
mode or examine the source.
+=cut
+
+sub get_snmp_session
+{
+ my $key = shift;
+ my $transport = shift;
+
+ my ($hostname, $port, $domain);
+ if ($transport =~ /^udp:(.*):(.*)/) {
+ $domain = "udp";
+ $hostname = $1;
+ $port = $2;
+ } elsif ($transport =~ /^tcp:(.*):(.*)/) {
+ $domain = "tcp";
+ $hostname = $1;
+ $port = $2;
+ } else {
+ die __x("unknown transport type: {t}", t => $transport);
+ }
+
+ if ($verbose) {
+ print STDERR "creating Net::SNMP session to $domain:$hostname:$port with key $key\n"
+ }
+
+ my ($session, $error) = Net::SNMP->session (
+ -version => 3,
+ -username => "virttools",
+ -authpassword => $key,
+ -authprotocol => "sha",
+ -privpassword => $key,
+ -privprotocol => "aes",
+ -hostname => $hostname,
+ -port => $port,
+ -domain => $domain,
+ );
+ die __x("SNMP failure: {e}", e => $error) unless $session;
+
+ $session;
+}
+
=head2 RUNNING YOUR OWN SNMP SERVER IN A GUEST
I<(To be written)>