Skip to main content
Solved

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

  • June 27, 2024
  • 2 replies
  • 229 views

Forum|alt.badge.img+1

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":\[\],"links":\[\]\}

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

 

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

 

Status information

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

 

 

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

 

[centreon-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.

Best answer by cb58

Hi,

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

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

Regards

2 replies

Forum|alt.badge.img+7
  • Steward *
  • Answer
  • June 27, 2024

Hi,

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

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

Regards


Forum|alt.badge.img+1
  • Author
  • Steward *
  • June 27, 2024

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 !