#!/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???'
In reply to Writing SNMP walk to CSV file by getwithrob
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |