getwithrob has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl my @columns = qw/interfaces.ifTable.ifEntry.ifDescr interfaces.ifTable +.ifEntry.ifAdminStatus interfaces.ifTable.ifEntry.ifOperStatus interf +aces.ifTable.ifEntry.ifLastChange/; my $CSV = "/opt/home/johnsonr/scripts/output.csv"; my $NODES = "/opt/home/johnsonr/scripts/nodes"; # use strict 'vars'; use Getopt::Std; use vars qw/ %opt /; my (%snmpwalk); my ($csv, $nodes, $tmp, $i, $x, $nam, $val, $node); my ($opt_d, $opt_c, $opt_n, $debug, $column, $node, $line); getopts ('dc:n:',\%opt) or &usage; $debug = $opt{d} ? 1 : 0; $csv = $opt{c} ? $opt{c} : $CSV; $nodes = $opt{n} ? $opt{n} : $NODES; print "nodes=$nodes\n"; sub usage() { print STDERR << "EOF"; This program read a nodes files and creates a csv file with snmp v +alues for each node. usage: $0 [-d] [-c:csv_file] [-n:nodes_file] [test-input-file-jus +t-for-demo] -d : print debugging messages to stderr -c : csv output file name. Default $CSV -n : nodes input file name. Default $NODES EOF exit; } open (NODES, "<$nodes") or die "could not open nodes file $nodes"; + open (CSV, ">$csv") or die "could not open scv file $csv"; + $tmp = join(",",@columns); print CSV "$tmp\n"; while (<NODES>) { chop; $node = $_; $line = ""; print "- $node\n" if $debug; foreach $column (@columns) { $_ = `snmpwalk $node VER143r $column`; if (/=\s*(.*)$/) { $val = $1; } else { $val = "???"; } $line .= $val . ","; print "-- $column, $val\n" if $debug; } chop $line; print CSV $line."\n"; }
2005-09-23 Retitled by g0n, as per Monastery guidelines
Original title: 'Can someone help???'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing SNMP walk to CSV file
by traveler (Parson) on Sep 22, 2005 at 20:05 UTC | |
by getwithrob (Initiate) on Sep 23, 2005 at 01:51 UTC | |
by traveler (Parson) on Sep 23, 2005 at 15:06 UTC | |
|
Re: Writing SNMP walk to CSV file
by CountZero (Bishop) on Sep 22, 2005 at 19:56 UTC | |
by getwithrob (Initiate) on Sep 22, 2005 at 20:08 UTC | |
by CountZero (Bishop) on Sep 22, 2005 at 20:24 UTC | |
by getwithrob (Initiate) on Sep 22, 2005 at 21:05 UTC | |
by traveler (Parson) on Sep 22, 2005 at 21:11 UTC | |
|
Re: Writing SNMP walk to CSV file
by runrig (Abbot) on Sep 22, 2005 at 18:01 UTC | |
by getwithrob (Initiate) on Sep 22, 2005 at 19:10 UTC | |
by runrig (Abbot) on Sep 22, 2005 at 19:45 UTC | |
by getwithrob (Initiate) on Sep 22, 2005 at 20:00 UTC | |
by runrig (Abbot) on Sep 22, 2005 at 20:04 UTC |