Hello,

at first I must confess I really donīt know much about perl.

I like to Monitor an HP MSA 200 via a Script, that i found in the zabbix forum Link:

https://www.zabbix.com/forum/showthread.php?t=26572

If I run the script Iīm getting this message:

"Not a HASH reference at ./hp-msa.pl line 18."

The script:

#!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; use Digest::MD5 qw(md5_hex); use XML::Simple; use JSON; my $zabbixSender="/usr/bin/zabbix_sender"; my $zabbixConfd="/etc/zabbix/zabbix_agentd.conf"; my $sendFile="/var/tmp/zabbixSenderHPP2000"; my $zabbixSendCommand="$zabbixSender -c $zabbixConfd -i "; my $USERNAME = "XXXXX"; my $PASSWORD = "XXXXX"; sub getHPP200Objects { my $ua = shift; my $sessionKey = shift; my $url = shift; my $objectName = shift; my $idName = shift; my $type = shift; my $zbxArray = shift; my $req = HTTP::Request->new(GET => $url); $req->header('sessionKey' => $sessionKey ); $req->header('dataType' => 'api' ); my $res = $ua->request($req); my $ref = XMLin($res->content, KeyAttr => "oid"); foreach my $oid (values %{$ref->{OBJECT}}) {

if ($oid->{name} eq $objectName) {

above is line 18

my $reference; foreach my $entry (@{$oid->{PROPERTY}}) { if ($entry->{name} =~ /^($idName)$/) { $reference = {'{#HP_P2000_ID}' => $entry->{content +}, '{#HP_P2000_TYPE}' => $type}; last; } } push @{$zbxArray}, {%{$reference}}; } } } sub getHPP200Stats { my $ua = shift; my $sessionKey = shift; my $url = shift; my $objectName = shift; my $idName = shift; my $colHash = shift; my $req = HTTP::Request->new(GET => $url); $req->header('sessionKey' => $sessionKey ); $req->header('dataType' => 'api' ); my $res = $ua->request($req); my $ref = XMLin($res->content, KeyAttr => "oid"); foreach my $oid (values %{$ref->{OBJECT}}) { if ($oid->{name} eq $objectName) { my $reference; my $hashKey; foreach my $entry (@{$oid->{PROPERTY}}) { if ($entry->{name} =~ /^($idName|bytes-per-second-nume +ric|iops|number-of-reads|number-of-writes|data-read-numeric|data-writ +ten-numeric)$/) { my $key = $1; if ($key =~ /durable-id/) { $hashKey = lc($entry->{content}); } elsif ($key eq $idName) { $hashKey = $entry->{content}; } else { $reference->{$key} = $entry->{content}; } } } $colHash->{$hashKey} = {%{$reference}}; } } } sub getZabbixValues { my $hostname = shift; my $colHash = shift; my $type = shift; my $outputString = ""; foreach my $key (keys %{$colHash}) { foreach my $itemKey (keys %{$colHash->{$key}}) { $outputString .= "$hostname hp.p2000.stats[$type,$key,$ite +mKey] $colHash->{$key}->{$itemKey}\n"; } } $outputString; } sub logOut { my $ua = shift; my $sessionKey = shift; my $hostname = shift; my $url = "https://$hostname/api/exit"; my $req = HTTP::Request->new(GET => $url); $req->header('sessionKey' => $sessionKey ); $req->header('dataType' => 'api' ); $ua->request($req); } my $hostname = $ARGV[0] or die("Usage: hp-msa-lld.pl <HOSTNAME> [lld|s +tats]"); my $function = $ARGV[1] || 'lld'; die("Usage: hp-msa-lld.pl <HOSTNAME> [lld|stats]") unless ($function = +~ /^(lld|stats)$/); my $md5_data = "${USERNAME}_${PASSWORD}"; my $md5_hash = md5_hex( $md5_data ); my $ua = LWP::UserAgent->new; my $url = "https://$hostname/api/login/" . $md5_hash; my $req = HTTP::Request->new(GET => $url); my $res = $ua->request($req); my $ref = XMLin($res->content); my $sessionKey; if (exists $ref->{OBJECT}->{PROPERTY}->{"return-code"} && $ref->{OBJEC +T}->{PROPERTY}->{"return-code"}->{content} == 1) { $sessionKey = $ref->{OBJECT}->{PROPERTY}->{"response"}->{content}; } else { die($ref->{OBJECT}->{PROPERTY}->{"response"}->{content}); } if ($function eq 'lld') { my $zbxArray = []; getHPP200Objects ( $ua, $sessionKey, "https://$hostname/api/show/c +ontrollers", "controllers", "durable-id", "Controller", $zbx +Array); getHPP200Objects ( $ua, $sessionKey, "https://$hostname/api/show/v +disks", "virtual-disk", "name", "Vdisk", $zbxArray); getHPP200Objects ( $ua, $sessionKey, "https://$hostname/api/show/v +olumes", "volume", "volume-name", "Volume", $zbxArray); print to_json({data => $zbxArray} , { ascii => 1, pretty => 1 }) . + "\n"; logOut($ua, $sessionKey, $hostname); } else { my $ctrls = {}; my $vdisks = {}; my $volumes = {}; my $outputString = ""; getHPP200Stats ( $ua, $sessionKey, "https://$hostname/api/show/con +troller-statistics", "controller-statistics", "durable-id", $ctrls); getHPP200Stats ( $ua, $sessionKey, "https://$hostname/api/show/vdi +sk-statistics", "vdisk-statistics", "name", $vdisks); getHPP200Stats ( $ua, $sessionKey, "https://$hostname/api/show/vol +ume-statistics", "volume-statistics", "volume-name", $volumes); logOut($ua, $sessionKey, $hostname); $outputString .= getZabbixValues($hostname, $ctrls, "Controller"); $outputString .= getZabbixValues($hostname, $vdisks, "Vdisk"); $outputString .= getZabbixValues($hostname, $volumes, "Volume"); $sendFile .= "_${hostname}_$$"; die "Could not open file $sendFile!" unless (open(FH, ">", $sendFi +le)); print FH $outputString; die "Could not close file $sendFile!" unless (close(FH)); $zabbixSendCommand .= $sendFile; if ( qx($zabbixSendCommand) =~ /Failed 0/ ) { $res = 1; } else { $res = 0; } die "Can not remove file $sendFile!" unless(unlink ($sendFile)); print "$res\n"; exit ($res - 1); }

May someone can help me?

Kind regards

Sententiosus

Edit:

thanks McA

the Output

$VAR1 = { 'OBJECT' => { 'PROPERTY' => [ { 'content' => 'error', 'name' => 'response-type' }, { 'content' => '1', 'name' => 'response-type-numer +ic' }, { 'content' => 'Unauthorized acc +ess requested', 'name' => 'response' }, { 'content' => '6', 'name' => 'return-code' } ], 'oid' => '1', 'name' => 'status', 'basetype' => 'status' } }; Not a HASH reference at ./hp-msa.pl line 19.

In reply to HASH error by Sententiosus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.