NAME
Cluster::SSH::Helper - Poll machines in a cluster via SNMP and determine which to run a command on.
VERSION
Version 0.1.1
SYNOPSIS
use Cluster::SSH::Helper;
my $csh;
eval({
# config using...
# ~/.config/cluster-ssh-helper/hosts.ini
# ~/.config/cluster-ssh-helper/config.ini
$csh= Cluster::SSH::Helper->new_from_ini();
});
if ( $@ ){
die( 'Cluster::SSH::Helper->new_from_ini failed... '.$@ );
}
# Run the command on the machine with the lowest 1m load.
$csh->run({ command=>'uname -a' });
METHODS
new
Any initially obvious errors in the passed config or hosts config will result in this method dieing.
Tho hash references are required . The first is the general config and the second is the hosts config.
my $csh;
eval({
$csh= Cluster::SSH::Helper->new( \%config, %hosts );
});
if ( $@ ){
die( 'Cluster::SSH::Helper->new failed... '.$@ );
}
new_from_ini
Initiates the this object from a file contiaining the general config and host confg from two INI files.
There are two optional arguments. The first one is the path to the config INI and the second is the path to the hosts INI.
If not specifiedied, xdg_config_home.'/cluster-ssh-helper/config.ini' and xdg_config_home.'/cluster-ssh-helper/hosts.ini' are used.
my $csh;
eval({
$csh= Cluster::SSH::Helper->new_from_ini( $config_path, $hosts_path );
});
if ( $@ ){
die( 'Cluster::SSH::Helper->new_from_ini failed... '.$@ );
}
run
command
This is a array to use for building the command that will be run. Basically thinking of it as @ARGV where $ARGV[0] will be the command and the rest will the the various flags etc.
env
This is a alternative env value to use if not using the defaults.
method
This is the selector method to use if not using the default.
debug
If set to true, returns the command in question after figuring out what it is.
print_cmd
Prints the command before running it.
eval({
$csh->run({
command=>'uname -a',
});
});
lowest_load_1n
This returns the host with the lowest 1 minute load.
my $host = $csh->lowest_load_1m;
lowest_used_ram_percent
This returns the host with the lowest percent of used RAM.
my $host = $csh->lowest_used_ram_percent;
snmp_command
Generates the full gammand to be used with snmpget minus that OID to fetch.
One argument is taken and that is the host to generate it for.
As long as the host exists, this command will work.
my $cmd;
eval({
$cmd=$cshelper->snmp_command($host);
});
CONFIGURATOIN
GENERAL
The general configuration.
This is written to be easily loadable via Config::Tiny, hence why '_' is used.
_
This contains the default settings to use. Each of these may be over ridden on a per host basis.
If use SNMPv3, please see Net::SNMP for more information on the various session options.
method
This is default method to use for selecting the what host to run the command on. If not specified, 'load' is used.
load_1m , checks 1 minute load and uses the lowest
ram_used_percent , uses the host with the lowest used percent of RAM
ssh
The default command to use for SSH.
If not specified, just 'ssh' will be used.
This should not include either user or host.
ssh_user
If specified, this will be the default user to use for SSH.
If not specified, SSH is invoked with out specifying a user.
snmp
This is the default options to use with netsnmp. This should be like '-v 2c -c public' or the like.
If not specified, this defaults to '-v 2c -c public'.
env
If specified, '/usr/bin/env' will be inserted before the command to be ran.
The name=values pairs for this will be built using the hash key specified by this.
warn_on_poll
Issue a warn() on SNMP timeouts or other polling issues. This won't be a automatic failure. Simply timing out on SNMP means that host will be skipped and not considered.
This defaults to 1, true.
HOSTS
This contains the hosts to connect to.
Each key of this hash reference is name of the host in question. The value is a hash containing any desired over rides to the general config.
AUTHOR
Zane C. Bowers-Hadley, <vvelox at vvelox>
BUGS
Please report any bugs or feature requests to bug-cluster-ssh-helper at rt.cpan.org
, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cluster-SSH-Helper. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Cluster::SSH::Helper
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Cluster-SSH-Helper
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
Repository
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2020 by Zane C. Bowers-Hadley.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)