Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use an undefined value as a HASH reference #11

Open
kssupport opened this issue Sep 25, 2014 · 6 comments
Open

Can't use an undefined value as a HASH reference #11

kssupport opened this issue Sep 25, 2014 · 6 comments
Labels

Comments

@kssupport
Copy link

I tried to use the plugin directly from the shell on a CentOS 5 server and i got the following message.

Can't use an undefined value as a HASH reference at /usr/lib/perl5/5.8.8/Net/Proxmox/VE.pm line 367.

@dpiquet
Copy link
Owner

dpiquet commented Oct 1, 2014

Hi, I would need more info to help you. Options used? Configuration file ?

@kssupport
Copy link
Author

HI,

I execute the script with this command line :

./pve-monitor.pl --nodes --singlenode --conf /root/pve-monitor-master/pve-monitor.conf

here is the kind of configuration file i use :

node col-srv-vm-01 {
address 10.184.1.11
port 8006 # Optional, default is 8006
monitor_account root
monitor_password XXXXXX
realm pam # Optional, default is pam
mem 80 90 # optional, not monitored if not defined
cpu 80 95 # optional
disk 80 90 # optional
}

I've installed the script directly on a Proxmox that use Perl version 5.14 and it work good but no luck on CentOS 5 with 5.8.8.
If i launch the script with perl -W on CentOS i get this message :
Bareword "Types::Serialiser::Error::" refers to nonexistent package at /usr/lib/perl5/site_perl/5.8.8/Types/Serialiser.pm line 126.
Bareword "Types::Serialiser::Error::" refers to nonexistent package at /usr/lib/perl5/site_perl/5.8.8/Types/Serialiser.pm line 135.

@mbeenonic
Copy link

Hi

same issue here on CentOS 5.11 (for all parameters, not only storages):
perl /usr/lib64/nagios/plugins/pve-monitor.pl --conf /etc/nagios/pve-monitor.conf --storages
Can't use an undefined value as a HASH reference at /usr/lib/perl5/5.8.8/Net/Proxmox/VE.pm line 367.

rpm -qa | grep perl
perl-Digest-SHA1-2.12-1.el5.rf
perl-Switch-2.14-1.el5.rf
perl-Crypt-DES-2.05-3.2.el5.rf
perl-HTML-Parser-3.55-1.fc6
perl-BSD-Resource-1.28-1.fc6.1
perl-DBI-1.52-2.el5
perl-Digest-HMAC-1.01-15
perl-Git-1.7.12.4-1.el5.rf
perl-JSON-2.50-1.el5.rf
perl-Net-SSLeay-1.30-4.fc6
perl-URI-1.35-3
perl-String-CRC32-1.4-2.fc6
mod_perl-2.0.4-6.el5
perl-Net-SNMP-5.2.0-1.2.el5.rf
perl-Curses-1.28-1.el5.rf
perl-HTML-Tagset-3.10-2.1.1
perl-libwww-perl-5.805-1.1.1
perl-rrdtool-1.4.7-1.el5.rf
perl-Socket6-0.23-1.el5.rf
perl-GD-2.45-1.el5.rf
perl-DBD-Pg-1.49-4.el5_8
perl-Compress-Zlib-1.42-1.fc6
perl-YAML-0.72-1.el5.rf
subversion-perl-1.6.11-12.el5_10
perl-IO-Socket-SSL-1.01-2.el5
perl-5.8.8-43.el5_11

(had to add sub for DELETE and export definition by hand to HTTP::Request::Common, since my version didn't implement it yet :/ )

cat /etc/nagios/pve-monitor.conf
node skrullian {
address 10.0.20.83
port 8006 # Optional, default is 8006
monitor_account xxxxxx
monitor_password xxxxxx
realm pve # Optional, default is pam
# test
mem 80 90 # optional, not monitored if not defined
cpu 80 95 # optional
disk 80 90 # optional
}

openvz example {
mem 80 90
cpu 80 95
disk 80 90
}

qemu msvm {
mem 80 90
cpu 80 95
disk 80 90
}

storage local {
disk 80 90
node qwe
}

Subroutine from VE.pm with marked line 367:

sub new {

    my $c     = shift;
    my @p     = @_;
    my $class = ref($c) || $c;

    my %params;

    if ( scalar @p == 1 ) {

        croak 'new() requires a hash for params'
          unless ref $p[0] eq 'HASH';

        %params = %{ $p[0] };

    }
    elsif ( scalar @p % 2 != 0 ) {    # 'unless' is better than != but anyway
        croak 'new() called with an odd number of parameters'

    }
    else {
        %params = @p
          or croak 'new() requires a hash for params';
    }

    croak 'host param is required'     unless $params{'host'};
    croak 'password param is required' unless $params{'password'};

    $params{port}     ||= 8006;
    $params{username} ||= 'root';
    $params{realm}    ||= 'pam';
    $params{debug}    ||= undef;
    $params{timeout}  ||= 10;

    my $self->{params} = \%params;  # <<<< line 367; yes, tried adding single quotes 
    $self->{'ticket'}           = undef;
    $self->{'ticket_timestamp'} = undef;
    $self->{'ticket_life'}      = 7200;    # 2 Hours

    bless $self, $class;
    return $self
}

@dpiquet
Copy link
Owner

dpiquet commented Apr 24, 2015

Hi,

Thanks for this well detailed bug report. I will need to install a test setup with that configuration so i can reproduce the bug and fix it.

I'm quite busy right now but i will take a look at this asap and update this bug report. If you find a fix for this problem feel free to explain it here or even better, create a pull request. I think the problem is not directly caused by the pve-monitor code itself but by the underlying proxmox-ve-api-perl lib.

https://github.com/dpiquet/proxmox-ve-api-perl

@dpiquet dpiquet added the bug label Apr 24, 2015
@mbeenonic
Copy link

Hi

sadly, my pearl skills are too rusty to play with the code, but I'm pretty sure, that it is because of some incompatibility between perl version and Proxmox api - CentOS 5.11 is quite old and it has Perl 5.8.8 from Feb 2006 (HTTP::Request::Common.pm had info that it's from 2004), so I'm not sure if that is a point in trying to backport it now :)

@dpiquet
Copy link
Owner

dpiquet commented Apr 24, 2015

Well I don't think it's the case. Currently the code dies at argument parsing. Of course it's not excluded that i'll have problems with the rest of the code but as PVE provides JSON data, i don't think the Perl version we use locally can prevent from reading the data.

I'll know more when i'll actually test the code in the same conditions to see if i can harden code or if I have to give up on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants