Skip to main content
Solved

HTTP Content check with regex : difference between IHM and command line

  • 27 June 2024
  • 2 replies
  • 39 views

Hi

I have to monitor a GPU status via a web page content.
When OK, the content is

{"gpuResources":[],"links":[]}

When KO, the content is like

{"gpuResources":[{"idGpu":"667bd79be7f1603f261a585c","core":{"name":"PRD.EGPU.A02","shortName":"E.A02",………..……...,"links":.]}

 

I have configured a chek with the plugin centreon_protocol_http.pl (Centreon 24.04) with the option --expected-string.

As this option uses regex, I use some \ to protect the special characters, such as {} ], so my filter expression is

\{"gpuResources":\e\],"links":\]\]\}

I also tried with
^\{"gpuResources":\e\],"links":\]\]\}$

 

On the IHM (Ressources), I always get a CRITICAL

 

Status information

CRITICAL: Content test Cfilter: '%{content} !~ /^{"gpuResources":p],"links":"]}$/mi']

 

 

but with the command (copied form the IHM), I get a OK

 

ccentreon-engine@CENTREON ~]$ /usr/lib/centreon/plugins//centreon_protocol_http.pl --plugin=apps::protocols::http::plugin --mode=expected-content --hostname=<MYHOSTNAME> --proto='https' --port='<MYPORT>' --urlpath='/MY/PATH/KO' --expected-string='\{"gpuResources":\"\],"links":\"\]\}' --warning-time='5' --critical-time='20'
OK: HTTP test(s) | 'size'=30B;;;0; 'time'=0.151s;0:5;0:20;0;

 

I don’t understand the different results between the IHM and the command line.

Do you suggestions of better regex ?

 

I’ve also tired another way, with regex to exclude the unexpected content, for example to exclude "idGpu" (that appear in the page whe the situation is KO) :

--expected-string='(?!(idGpu.*))'
--expected-string='(?!(idGpu))'
--expected-string='(?!(idGpu))'

I also get a good result with the command line and a wrong result in the IHM.

 

I have a lot of other HTTP checks (without special characters in the content), they don’t have this problem.

2 replies

Userlevel 1
Badge +4

Hi,

You can replace each special characters by the regexp dot. You can try :

"gpuResources":..,"links":...$

Regards

Badge +1

Yes, indeed, it works for both situation, the IHM and command line have the same status.

It doen’t explain why there was a difference before 🤔 but at least I have a solution. Thx !

Reply