Solved

Service format

  • 9 January 2023
  • 3 replies
  • 67 views

Userlevel 1
Badge +6

Hello,

 

I’m configuring services for my Centreon and I wanted to change format of my storage service.

I’ve already change something but I would like to make it better.

I’ve found in the linux plugin configuration where lines which display the result are.

My current conf for that :

 

15428   sub custom_usage_output {
15429       my ($self, %options) = @_;
15430       my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
15431       my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
15432       my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
15433       return sprintf(
15434           'Usage : %s / %s (%.2f%%)',
15435           $total_size_value . " " . $total_size_unit,
15436           $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
15437           $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
15438       );
15439   }
 

 

My main problem is that I would like to change my values order, I would like to have total used before total size (with %s).

I would also like to know if I can lined up that like an array.

Currently, it looks like that :

Thanks and have a nice day !

icon

Best answer by StanislasR 11 January 2023, 08:56

View original

3 replies

Userlevel 1
Badge +6

I’ve found a solution, if anyone want to know don’t hesitate.

Userlevel 5
Badge +11

Hi @StanislasR you could share it directly with everyone, I'm sure it will help someone in the future. Thanks in advance : ) 

Userlevel 1
Badge +6

Ok, I’m a beginner so that’s probably easy for many people, but I’ve searched “Usage Total” with ctrl+W on the file, to find where format was configured.

 

I’ve found that format was depending on the order of next lines

First %s is for the line : $total_size_value . " " . $total_size_unit,

Second %s for : $total_used_value . " " . $total_used_unit, $self,

(%.2f%%) is for : $self->{result_values}->{prct_used},

 

Default config :

if ($self->{result_values}->{total} != -1) {

   my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self→ {result_values}->{total});
   my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
   my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
    $msg = sprintf(
       'Usage: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
       $total_size_value . " " . $total_size_unit,
       $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
       $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}

   );

}
 

So with following lines instead of default’s :

'Usage: %s / %s (%.2f%%)',
$total_used_value . " " . $total_used_unit,
$total_size_value . " " . $total_size_unit,
$self->{result_values}->{prct_used},
 

I can obtain something more readable for me :

 

And that’s the same thing for plugins of other devices, and for other modes (I’ve tried on Linux, Windows, Cisco, and Cisco ASA for RAM and Hard Disk).

Reply