152 lines
4.4 KiB
Perl
152 lines
4.4 KiB
Perl
|
################################################################################
|
||
|
# Copyright 2005-2013 MERETHIS
|
||
|
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||
|
# GPL Licence 2.0.
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or modify it under
|
||
|
# the terms of the GNU General Public License as published by the Free Software
|
||
|
# Foundation ; either version 2 of the License.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||
|
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License along with
|
||
|
# this program; if not, see <http://www.gnu.org/licenses>.
|
||
|
#
|
||
|
# Linking this program statically or dynamically with other modules is making a
|
||
|
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||
|
# General Public License cover the whole combination.
|
||
|
#
|
||
|
# As a special exception, the copyright holders of this program give MERETHIS
|
||
|
# permission to link this program with independent modules to produce an executable,
|
||
|
# regardless of the license terms of these independent modules, and to copy and
|
||
|
# distribute the resulting executable under terms of MERETHIS choice, provided that
|
||
|
# MERETHIS also meet, for each linked independent module, the terms and conditions
|
||
|
# of the license of that module. An independent module is a module which is not
|
||
|
# derived from this program. If you modify this program, you may extend this
|
||
|
# exception to your version of the program, but you are not obliged to do so. If you
|
||
|
# do not wish to do so, delete this exception statement from your version.
|
||
|
#
|
||
|
# For more information : contact@centreon.com
|
||
|
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||
|
#
|
||
|
####################################################################################
|
||
|
|
||
|
package example::custommode::simple;
|
||
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
|
||
|
sub new {
|
||
|
my ($class, %options) = @_;
|
||
|
my $self = {};
|
||
|
bless $self, $class;
|
||
|
# $options{options} = options object
|
||
|
# $options{output} = output object
|
||
|
# $options{exit_value} = integer
|
||
|
# $options{noptions} = integer
|
||
|
|
||
|
if (!defined($options{output})) {
|
||
|
print "Class Custom: Need to specify 'output' argument.\n";
|
||
|
exit 3;
|
||
|
}
|
||
|
if (!defined($options{options})) {
|
||
|
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||
|
$options{output}->option_exit();
|
||
|
}
|
||
|
|
||
|
if (!defined($options{noptions})) {
|
||
|
$options{options}->add_options(arguments =>
|
||
|
{ "customarg:s@" => { name => 'customarg' },
|
||
|
});
|
||
|
}
|
||
|
$options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM OPTIONS', once => 1);
|
||
|
|
||
|
$self->{output} = $options{output};
|
||
|
$self->{mode} = $options{mode};
|
||
|
|
||
|
$self->{customarg} = undef;
|
||
|
|
||
|
return $self;
|
||
|
}
|
||
|
|
||
|
# Method to manage multiples
|
||
|
sub set_options {
|
||
|
my ($self, %options) = @_;
|
||
|
# options{options_result}
|
||
|
|
||
|
$self->{option_results} = $options{option_results};
|
||
|
}
|
||
|
|
||
|
# Method to manage multiples
|
||
|
sub set_defaults {
|
||
|
my ($self, %options) = @_;
|
||
|
# options{default}
|
||
|
|
||
|
# Manage default value
|
||
|
foreach (keys %{$options{default}}) {
|
||
|
if ($_ eq $self->{mode}) {
|
||
|
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||
|
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||
|
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||
|
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub check_options {
|
||
|
my ($self, %options) = @_;
|
||
|
# return 1 = ok still customarg
|
||
|
# return 0 = no customarg left
|
||
|
|
||
|
$self->{customarg} = (defined($self->{option_results}->{customarg})) ? shift(@{$self->{option_results}->{customarg}}) : undef;
|
||
|
|
||
|
if (!defined($self->{customarg}) ||
|
||
|
scalar(@{$self->{option_results}->{customarg}}) == 0) {
|
||
|
return 0;
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
##############
|
||
|
# Specific methods
|
||
|
##############
|
||
|
sub test {
|
||
|
my ($self, %options) = @_;
|
||
|
|
||
|
use Data::Dumper;
|
||
|
print Data::Dumper::Dumper($self);
|
||
|
}
|
||
|
|
||
|
1;
|
||
|
|
||
|
__END__
|
||
|
|
||
|
=head1 NAME
|
||
|
|
||
|
My Custom global
|
||
|
|
||
|
=head1 SYNOPSIS
|
||
|
|
||
|
my custom class example
|
||
|
|
||
|
=head1 CUSTOM OPTIONS
|
||
|
|
||
|
=over 8
|
||
|
|
||
|
=item B<--customarg>
|
||
|
|
||
|
Argument test.
|
||
|
|
||
|
=back
|
||
|
|
||
|
=head1 DESCRIPTION
|
||
|
|
||
|
B<custom>.
|
||
|
|
||
|
=cut
|