#!/usr/bin/perl

use strict;
use warnings;

use Asterisk::AMI::Common ();

my ( $ami_user, $ami_pass ) = @ARGV;

my $ami = Asterisk::AMI::Common->new( PeerAddr => '127.0.0.1', PeerPort => '5038', Username => $ami_user, Secret => $ami_pass );

if ( $ami ) {
    my $resp = $ami->action({ Action => 'CoreStatus' });

    if ( ref( $resp ) eq 'HASH' && $resp->{'Response'} && $resp->{'Response'} eq 'Success' ) {
        if ( ref( $resp->{'PARSED'} ) eq 'HASH' ) {
            my $p = $resp->{'PARSED'};

            for my $k ( keys %$p ) {
                print "$k: $p->{$k}\n";
            }
        }
        else {
            print "Unable to parse CoreStatus response\n";
        }
    }
    else {
        print "CoreStatus failed\n";
    }
}
else {
    print "AMI connection failed\n";
}


