Page 1 of 1

macro in cmd line

Posted: Fri Oct 01, 2021 4:19 am
by dimsum
Hi,

I need to use macro $HOSTDISPLAYNAME$ in the cmd line look like below.
Screen Shot 2564-10-01 at 16.36.41.png
But when I test the command I found $HOSTDISPLAYNAME$ not resolve to real value. Can I work with macro in cmd?
Screen Shot 2564-10-01 at 16.14.01.png
Thanks.

Re: macro in cmd line

Posted: Mon Oct 04, 2021 9:04 am
by gsmith
Hi

Could you please provide the check_rrdtraf_ruijie.php file?

Thanks

Re: macro in cmd line

Posted: Mon Oct 04, 2021 6:35 pm
by dimsum

Code: Select all

#!/usr/bin/php
<?php

define( "OK",       0);
define( "WARNING",  1);
define( "CRITICAL", 2);
define( "UNKNOWN",  3);


$on_warning = false;
$on_critical = false;

$opciones = getopt("a:A:");


if( isset($opciones['a']) )
    $host_display_name = $opciones['a'];
else if( isset($opciones['A']) )
    $host_display_name = $opciones['A'];

$host_display_name = trim($host_display_name);

if($host_display_name == ""){
    printf("Please fill Host Display Name\n");
    exit(UNKNOWN);
}

printf("OK - ".$host_display_name." Current BW in: 0Mbps Out: .01Mbps|in=0Mb/s;15;20 out=0Mb/s;5;8");

exit(OK);

?>

Re: macro in cmd line

Posted: Tue Oct 05, 2021 5:17 pm
by benjaminsmith
Hi,
Thanks for sharing the script. We're are currently working on your issue. We are going to do a bit of research on it and get back to you within 24 hours.

Thanks,
Benjamin

Re: macro in cmd line

Posted: Wed Oct 06, 2021 11:36 am
by gsmith
Hi

There is no $HOSTDISPLAYNAME$ macro.

Please try using $HOSTNAME$

for example:

gregtest.php file:

Code: Select all

#!/usr/bin/php
<?php

define( "OK",       0);
define( "WARNING",  1);
define( "CRITICAL", 2);
define( "UNKNOWN",  3);


$on_warning = false;
$on_critical = false;
$opciones = getopt("a:A:");

if( isset($opciones['a']) )
    $host_display_name = $opciones['a'];
else if( isset($opciones['A']) )
    $host_display_name = $opciones['A'];

var_dump($host_display_name);
$host_display_name = trim($host_display_name);
printf($host_display_name);

if($host_display_name == ""){
    printf("Please fill Host Display Name\n");
    exit(UNKNOWN);
}

printf("OK - ".$host_display_name." Current BW in: 0Mbps Out: .01Mbps|in=0Mb/s;15;20 out=0Mb/s;5;8");

exit(OK);

?>
command definition:
Image3.jpg
service definition:
Image4.jpg
run command check:
Image5.jpg
Please let me know how you make out.

Thanks