Skip to main content
Solved

Service format


Forum|alt.badge.img+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 !

Best answer by StanislasR

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).

View original
Did this topic help you find an answer to your question?

Forum|alt.badge.img+6

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


Fabrix
Centreonian
Forum|alt.badge.img+11
  • Centreonian
  • January 10, 2023

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


Forum|alt.badge.img+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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings