
#                                      Copyright 2024 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

package Whostmgr::360Monitoring::Agent::Plugins::Roles::Runnable;

use cPstrict;
use Whostmgr::360Monitoring::Moo;
use Types::Common::Numeric qw(PositiveInt);
use Moo::Role;

# Default 60 https://github.com/plesk/agent360/blob/master/agent360/agent360.py#L324
conf_has 'interval' => ( isa => PositiveInt, default => 60 );

conf_has 'ttl' => ( isa => PositiveInt, default => 60 );

sub agent360_run ($self) {
    require Cpanel::SafeRun::Errors;
    my $output = Cpanel::SafeRun::Errors::saferunallerrors( '/usr/local/bin/agent360', '--test', $self->name );
}

1;

__END__

=head1 NAME

Whostmgr::360Monitoring::Agent::Plugins::Roles::Runnable - A Moo::Role allowing basic config and operation of a plugin through agent360 binary.

=head1 SYNOPSIS

    # Create an an empty Agent
    my $agent  = Whostmgr::360Monitoring::Agent->new();

    # Add the plugin to the agent
    $agent->add_to_plugins( "fake", {enabled=>'yes' } );

    # Or, alternatively, create a plugin, which isn't added to the agent
    my $plugin = Whostmgr::360Monitoring::Agent::Plugins::httpd->new($agent, {enabled=>'yes'} );
    my $output = $plugin->agent360_run();

=head1 METHODS

=over 8

=item agent360_run

Returns JSON of data collected by the plugin.
Implements the "test" function of the agent360 CLI tool.

=back

=head1 ATTRIBUTES

=over 8

=item agent360_run

=item interval

An attribute representing interval as defined in the GitHub repo linked in the SEE ALSO. Sourced from INI. Serializes to INI.

=item ttl

An attribute representing interval as defined in the GitHub repo linked in the SEE ALSO. Sourced from INI. Serializes to INI.

=back
