Hello
This question is probably for someone who know how the whole centreon plugin works, probably someone from centreon
I’m working on a plugin for a SAN appliance with Rest, I did all the groundwork, followed the guidelines etc.. and I’m now tying up all the command line parameters and trying to have “correct” plugin
in practice I managed to get my data selection working, and for example I use this in the loop for “manage_selection”
$self->{filesystem}->{ $filesystem->{'NAME'} } = {
name => $filesystem->{'NAME'},
storage_pool => $filesystem->{'PARENTNAME'},
space => {
total_space => $total,
used_space => $used,
free_space => $free,
prot_space => $prot,
prct_used_space => $prct
}
I have a custom “space usage output” and some standard long output/prefix output
sub custom_space_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space});
my ($total_prot_value, $total_prot_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{prot_space});
return sprintf(
"size: %s used: %s (%.2f%%) protection: %s",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit,
$self->{result_values}->{prct_used_space},
$total_prot_value . " " . $total_prot_unit
);
}
sub filesystem_long_output {
my ($self, %options) = @_;
return sprintf(
"checking FileSystem '%s' gsp: %s]",
$options{instance_value}->{name},
$options{instance_value}->{storage_pool}
);
}
sub prefix_filesystem_output {
my ($self, %options) = @_;
return sprintf(
"FileSystem '%s' sp: %s] ",
$options{instance_value}->{name},
$options{instance_value}->{storage_pool}
);
}
nothing fancy, I took idea from existing plugin.
then I have the “set_counter” headache
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = t
{ name => 'filesystem', type => 3, cb_prefix_output => 'prefix_filesystem_output', cb_long_output => 'filesystem_long_output',
indent_long_output => ' ', message_multiple => 'All FileSystems are ok',
group => >
{ name => 'space', type => 0, skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{space} = _
{ label => 'space-usage', nlabel => 'filesystem.space.usage.bytes', set => {
key_values => { name => 'used_space' }, { name => 'total_space' },{ name => 'prct_used_space' }, { name => 'prot_space' }],
closure_custom_output => $self->can('custom_space_usage_output'),
perfdatas =>
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'space-usage-prot', nlabel => 'filesystem.space.prot.bytes', set => {
key_values => { name => 'prot_space' }, { name => 'total_space' }, { name => 'used_space' }, { name => 'prct_used_space' } ],
closure_custom_output => $self->can('custom_space_usage_output'),
perfdatas =>
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'space-usage-prct', nlabel => 'filesystem.space.usage.percentage', set => {
key_values => { name => 'prct_used_space' }, { name => 'total_space' }, { name => 'used_space' }, { name => 'prot_space' } ],
closure_custom_output => $self->can('custom_space_usage_output'),
perfdatas =>
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
}
}
];
}
so, here is the plugin output, it’s almost what I want :
OK: FileSystem 'Repository-TCO' sp: StoragePool001] size: 1650.00 TB used: 1232.29 TB (74.68%) protection: 393.57 TB, size: 1650.00 TB used: 1232.29 TB (74.68%) protection: 393.57 TB, size: 1650.00 TB used: 1232.29 TB (74.68%) protection: 393.57 TB | 'Repository-TCO#filesystem.space.usage.bytes'=1354921323116032B;;;0;1814194185830400 'Repository-TCO#filesystem.space.prot.bytes'=432735102616064B;;;0;1814194185830400 'Repository-TCO#filesystem.space.usage.percentage'=74.68%;;;0;100
checking FileSystem 'Repository-TCO' sp: StoragePool001]
size: 1650.00 TB used: 1232.29 TB (74.68%) protection: 393.57 TB, size: 1650.00 TB used: 1232.29 TB (74.68%) protection: 393.57 TB, size: 1650.00 TB used: 1232.29 TB (74.68%) protection: 393.57 TB
I want to be able to have multiple counter alarm
--warning-space-usage
--warning-space-usage-protection
--warning-space-usage-prct
but I don’t want to have 3 time the short long output
if I want a --warning-XXX I couldn’t fin a way to have it work I didn’t put a counter with the name XXX
if I put a counter with the name XXX , I couldn’t find a way to “hide” it
ideally I want to have threshold in %, but metric in bytes
(and the possibility to disply metric in % instead of byte, like the option you see sometime “--unit=’%’ ”, with “--unit=’B’ ” by default, but this is more a cosmetic need, if I put the plugin on the community, you will always have someone asking for the option, or asking to display free space instead of used space, etc… just thinking ahead here, I don’t need it for me.)
I couldn’t find a way to setup this as I couldn’t find more documentation than whats on the documentation page and I’m not sure how to approach the settings in the
$self->{maps_counters_type} call
and
$self->{maps_counters}->{space}
I think it’s probably somewhere in here, maybe I shouldn’t have used a “group”, no idea really
there are ‘type’ and lots of sub options to pass here but I couldn’t find more explanation
so : is there a documentation explaining both map_counters_type and map_counter somewhere?
or can someone guide me on how to create threshold without ouput?
thanks in advance
edit : here is the doc I was refering to : Develop with centreon-plugins | Centreon Documentation