I must be missing something here so I'm asking for more eyes on something.
I built a fairly simple straightforward module here and yet it is failing to work. This module does curls to an API (The Foreman) to extract some data from it. Nothing fancy here.... Here are the most important bits:
package NCS::PuppetDB::Data;
use 5.010000;
use strict;
use warnings;
use JSON;
our $curl="/usr/bin/curl -G 'http://localhost:8080/v3";
our $VERSION = '0.5.2';
sub new {
my $self={};
bless $self,"NCS::PupptDB::Data";
return $self;
}
sub getHosts {
my $self = shift;
my $cmd=sprintf("%s/nodes 2>/dev/null",$curl);
my $json = JSON->new->allow_nonref;
my $jsonData=`$cmd`;
my $decoded = $json->decode($jsonData);
my $retval=[];
for my $entry(@$decoded){
push @$retval,$entry->{name};
}
return sort $retval;
}
sub getHostFacts {
my $self = shift;
my $host = shift;
my $cmd=sprintf("%s/nodes/%s/facts' 2>/dev/null",$curl,$host);
my $json = JSON->new->allow_nonref;
my $jsonData=`$cmd`;
my $decoded = $json->decode($jsonData);
my $retval = {};
for my $fact(@$decoded){
$retval->{$fact->{name}} = $fact->{value};
}
return $retval;
}
sub getFact {
my ($self,$host,$factname)=@_;
my $facts=getHostFacts($host);
return $facts->{$factname};
}
1;
The one and only script using it (so far) is complaining:
Can't locate object method "getHosts" via package "NCS::PupptDB::Data"
What am I missing?
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net;
Blog: http://blog.berghold.net Warning: No political correctness allowed.