Ist mein Code so richtig???

#1
Meine Frage: Wie wichtig ist es, das bei plugin_output und check_source nicht in Gänsefüßchen stehen? Hat das dann eine andere Bedeutung?

Danke für eure Hilfe


Folgende Ausgabe muss ich erhalten:


curl -k -s -u apiuser:sekrit \
-H 'Accept: application/json' \
-X POST 'https://localhost:5665/v1/actions/process-check-result?service=icinga2!Backup' \
-d '{ "exit_status":2, "plugin_output": "error message", "check_source": "icinga2" }' | python -m json.tool

das wirft mir mein Code heraus:

Command would be executed like this:
/usr/bin/curl -k -s -u apiuser:sekrit -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/process-check-result?service=icinga2!Backup' -d '{ "exit_status":2 plugin_output:error_message, check_source:icinga2 }' | python -m json.tool

das ist mein Code:

#!/usr/bin/perl

my $command_curl = '/usr/bin/curl';
my $exit_status = '1';
my $plugin_output = 'error_message';
my $hostname = 'server-backup-n';
my $password = 'apiuser:sekrit';
my $check_source = 'icinga2';
my $url = 'https://localhost:5665/v1/actions/process-check-result?service=icinga2!Backup';


my $complete_command_string = $command_curl;
$complete_command_string .= " -k -s -u ";
$complete_command_string .= $password;
$complete_command_string .= " -H 'Accept: application/json' -X POST '$url' ";
$complete_command_string .= " -d '{ \"exit_status\":",;
$complete_command_string .= $exit_status;
$complete_command_string .= " plugin_output:error_message, ";
$complete_command_string .= " check_source:icinga2 }'";

#$complete_command_string .= " \"plugin_output\":",;
#$complete_command_string .= $plugin_output;
#$complete_command_string .= " \"check_source\":";
#$complete_command_string .= $check_source;
$complete_command_string .= " | python -m json.tool";



print "Command would be executed like this: \n";

print $complete_command_string;
print "\n";
 

lano

Well-Known Member
c-b Experte
#2
Perl:
#!/usr/bin/perl

my $command_curl = 'curl';
my $exit_status = '2';
my $plugin_output = 'error_message';
my $hostname = 'server-backup-n';
my $password = 'apiuser:sekrit';
my $check_source = 'icinga2';
my $url = 'https://localhost:5665/v1/actions/process-check-result?service=icinga2!Backup';


my $complete_command_string = $command_curl;
$complete_command_string .= " -k -s -u ";
$complete_command_string .= $password." \\ \n";
$complete_command_string .= "-H 'Accept: application/json' \\\n-X POST '$url' "."\\ \n";
$complete_command_string .= "-d '{ \"exit_status\":";
$complete_command_string .= $exit_status.", ";
$complete_command_string .= "\"plugin_output\":\"error_message\", ";
$complete_command_string .= "\"check_source\":\"icinga2\" }' ";

$complete_command_string .= "| python -m json.tool";



print "Command would be executed like this: \n";

print $complete_command_string;
print "\n";
 
Oben