Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

If possible, I want the output of a snmp command to be put directly in a 2 dimensional array:
Possible output of snmp command (I removed a bit to make question easier):
/ 8263349 /var/run 26112 @FS_list_usage=`/usr/sfw/bin/snmpdf -v1 -c public $host`;

With above definition of the array, I can only access/print each line as a whole:
print @FS_list_usage[$i]

Would it be possible to directly (when you define the array) specify you need two rows for each line by specifying a possible delimiter or so ?
I don't want to use the split command and build myself the array, because this would take too much system resources ( given the amount to process : 50 servers x 10 filesystems = 500 split commands / test)

Replies are listed 'Best First'.
Re: Multidimensional array
by Joost (Canon) on Aug 16, 2007 at 16:09 UTC
      Thanks for your quick reply!
      The map does the job , sweet :-)
Re: Multidimensional array
by dynamo (Chaplain) on Aug 16, 2007 at 22:35 UTC
    Couple thoughts:

    1 - If you have 50 servers, and each one has 10 fs's to process, you can do it 50x faster by running each batch of 10 on the actual servers, and then transfer the data to wherever you were using it before.
    2 - This looks a lot like a set of keys and values to me, why not use a hash?
    3 - If you are doing the shell-out command 50x, and it's a network query, the cpu use of the split of the data is _totally_ insignificant. Any way to do all 50 as a batch query?
      Thanks for your quick reply!
      From the CPU-point of view, your remark is absolutly correct. But the initial reason we start working with SNMP to monitor several aspects of the systems, was to centralise monitoring jobs, so we don't need specifique monitoring agents on each hosts, which brings easier management. I know it is discusable , but the descision is already taken by upper-management.
      Thanks anyway!
Re: Multidimensional array
by leighsharpe (Monk) on Aug 17, 2007 at 00:53 UTC
    Is there any reason why you must use an external SNMP query? NET::SNMP has a good non-blocking SNMP dispatcher which will go all 500+ queries in next to no time, with very little overhead. Have a quick look at this writeup: Re^3: threads and SNMP Session for an example of how.
      Thanks for your quick reply!
      Now I am using Solaris SMA (based on free-net-snmp) which is included in Solaris 10 by default. Next step may indeed/probably be to switch to NET::SNMP.
      Thanks for info, as I did not know such perl-module did exsist!