enh(plugin): Slack REST API metricsv2 (#2822)
This commit is contained in:
parent
b3d9191f2c
commit
85382a9b7b
|
@ -31,43 +31,12 @@ sub prefix_output {
|
||||||
return "Channel '" . $options{instance_value}->{name} . "' ";
|
return "Channel '" . $options{instance_value}->{name} . "' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub set_counters {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
|
||||||
{ name => 'global', type => 0 },
|
|
||||||
{ name => 'channels', type => 1, cb_prefix_output => 'prefix_output' },
|
|
||||||
];
|
|
||||||
|
|
||||||
$self->{maps_counters}->{global} = [
|
|
||||||
{ label => 'count', set => {
|
|
||||||
key_values => [ { name => 'count' } ],
|
|
||||||
output_template => 'Number of channels : %d',
|
|
||||||
perfdatas => [
|
|
||||||
{ label => 'count', value => 'count', template => '%d',
|
|
||||||
min => 0 },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
$self->{maps_counters}->{channels} = [
|
|
||||||
{ label => 'members', set => {
|
|
||||||
key_values => [ { name => 'id' }, { name => 'name' }, { name => 'num_members' } ],
|
|
||||||
closure_custom_calc => $self->can('custom_info_calc'),
|
|
||||||
closure_custom_output => $self->can('custom_info_output'),
|
|
||||||
closure_custom_perfdata => $self->can('custom_info_perfdata'),
|
|
||||||
closure_custom_threshold_check => $self->can('custom_info_threshold'),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
sub custom_info_perfdata {
|
sub custom_info_perfdata {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{output}->perfdata_add(
|
$self->{output}->perfdata_add(
|
||||||
label => 'members',
|
label => 'members',
|
||||||
|
nlabel => 'channels.members.count',
|
||||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||||
value => $self->{result_values}->{num_members},
|
value => $self->{result_values}->{num_members},
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
|
||||||
|
@ -102,6 +71,37 @@ sub custom_info_calc {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub set_counters {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{maps_counters_type} = [
|
||||||
|
{ name => 'global', type => 0 },
|
||||||
|
{ name => 'channels', type => 1, cb_prefix_output => 'prefix_output' }
|
||||||
|
];
|
||||||
|
|
||||||
|
$self->{maps_counters}->{global} = [
|
||||||
|
{ label => 'count', nlabel => 'channels.count', set => {
|
||||||
|
key_values => [ { name => 'count' } ],
|
||||||
|
output_template => 'Number of channels : %d',
|
||||||
|
perfdatas => [
|
||||||
|
{ label => 'count', template => '%d', min => 0 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
$self->{maps_counters}->{channels} = [
|
||||||
|
{ label => 'members', set => {
|
||||||
|
key_values => [ { name => 'id' }, { name => 'name' }, { name => 'num_members' } ],
|
||||||
|
closure_custom_calc => $self->can('custom_info_calc'),
|
||||||
|
closure_custom_output => $self->can('custom_info_output'),
|
||||||
|
closure_custom_perfdata => $self->can('custom_info_perfdata'),
|
||||||
|
closure_custom_threshold_check => $self->can('custom_info_threshold')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
|
|
|
@ -36,19 +36,18 @@ sub set_counters {
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'global', type => 0 },
|
{ name => 'global', type => 0 },
|
||||||
{ name => 'members', type => 1, cb_prefix_output => 'prefix_output' },
|
{ name => 'members', type => 1, cb_prefix_output => 'prefix_output' }
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{global} = [
|
$self->{maps_counters}->{global} = [
|
||||||
{ label => 'count', set => {
|
{ label => 'count', nlabel => 'members.count', set => {
|
||||||
key_values => [ { name => 'count' } ],
|
key_values => [ { name => 'count' } ],
|
||||||
output_template => 'Number of members : %d',
|
output_template => 'Number of members : %d',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'count', value => 'count', template => '%d',
|
{ label => 'count', template => '%d', min => 0 }
|
||||||
min => 0 },
|
]
|
||||||
],
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{members} = [
|
$self->{maps_counters}->{members} = [
|
||||||
|
@ -56,9 +55,9 @@ sub set_counters {
|
||||||
key_values => [ { name => 'id' }, { name => 'real_name' }, { name => 'display_name' } ],
|
key_values => [ { name => 'id' }, { name => 'real_name' }, { name => 'display_name' } ],
|
||||||
closure_custom_calc => $self->can('custom_info_calc'),
|
closure_custom_calc => $self->can('custom_info_calc'),
|
||||||
closure_custom_output => $self->can('custom_info_output'),
|
closure_custom_output => $self->can('custom_info_output'),
|
||||||
closure_custom_perfdata => sub { return 0; },
|
closure_custom_perfdata => sub { return 0; }
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
sub custom_info_output {
|
sub custom_info_output {
|
||||||
|
|
|
@ -30,10 +30,10 @@ sub new {
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$self->{version} = '1.0';
|
$self->{version} = '1.0';
|
||||||
%{$self->{modes}} = (
|
%{$self->{modes} => {
|
||||||
'count-channels' => 'apps::slack::restapi::mode::countchannels',
|
'count-channels' => 'apps::slack::restapi::mode::countchannels',
|
||||||
'count-members' => 'apps::slack::restapi::mode::countmembers',
|
'count-members' => 'apps::slack::restapi::mode::countmembers'
|
||||||
);
|
};
|
||||||
|
|
||||||
$self->{custom_modes}{restapi} = 'apps::slack::restapi::custom::api';
|
$self->{custom_modes}{restapi} = 'apps::slack::restapi::custom::api';
|
||||||
return $self;
|
return $self;
|
||||||
|
|
Loading…
Reference in New Issue