Centreon/Nagios optional arguments in commands - nagios

Is there a way to put optional arguments in centreon/nagios
A simple example. In Centreon:
$USER1$/check_http -H $ARG1$ -p $ARG2$ -w $ARG3$
Host (-H) and port (-p) arguments as required and warning argument (-w) set it as optional

You could just do
$USER1$/check_http -H $ARG1$ -p $ARG2$ $ARG3$
And set $ARG3$ if you need it.

Related

How to encode a query in CURL Command Line when passing a query as a sql parameter

I am trying to query via CURL command line but I believe I need to encode it.
Example:
curl -X GET -H "Authorization:c02c66a4531a43c5a0971d16c2823e1a" 'http://127.0.0.1:8050/api/core/query?sql=select n return n limit 10' -i
I don't ever see why this is a good idea, but here is a curl with an encoded match(n) return n limit 10' -i:
curl -X GET \
http://127.0.0.1:8085/api/core/query \
-H 'Authorization: c02c66a4531a43c5a0971d16c2823e1a' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'sql=match(n)%20return%20n%20limit%2010'\''%20-i'

Problem with executing only first element into array [duplicate]

This question already has answers here:
While loop stops reading after the first line in Bash
(5 answers)
Closed 1 year ago.
I thought that my problem is trivial, but I cannot figure out, why my scripts only performing once in array.
I have a jenkins job (bash script). This job gathering hostnames and sends ssh commands, through script, using gathered info:
rm /tmp/hosts
docker exec -t tmgnt_consul_1 consul members -status=alive | grep -v Node | awk '{print $1}' | cut -d : -f1 >> /tmp/hosts
sed -i '/someunnecessaryinfo/d' /tmp/hosts
echo >> /tmp/hosts
shopt -s lastpipe
while IFS= read -r line; do
echo "host is >>$line<<";
url="http://111.111.111.111:8500/v1/catalog/nodes"
term_IP=`curl -s $url | jq -r --arg Node "${line}" '.[] | select(.Node == "'${line}'" )|.Address' --raw-output`
echo $term_IP
sudo bash -x /home/rtm/t_mgnt/check_fw $term_IP
done < /tmp/hosts
Second script:
#!/bin/bash
term_IP=$1
sudo sshpass -p 'some.pass' ssh -o StrictHostKeyChecking=no user#$term_IP "sudo test -d /root/nv9"
if [ $? != 0 ]; then
sudo sshpass -p 'some.pass' \
scp -n -o StrictHostKeyChecking=no -r /home/rtm/t_mgnt/nv9 user#$term_IP:
sudo sshpass -p 'some.pass' \
ssh -n -o StrictHostKeyChecking=no user#$term_IP "sudo mv nv9 /root/"
sudo sshpass -p 'some.pass' \
ssh -n -o StrictHostKeyChecking=no user#$term_IP "sudo dpkg -i /root/nv9/libudev0_175-0ubuntu9_amd64.deb"
sudo sshpass -p 'some.pass' \
ssh -n -o StrictHostKeyChecking=no user#$term_IP "sudo /root/nv9/DetectValidator"
else
sudo sshpass -p 'some.pass' \
ssh -n -o StrictHostKeyChecking=no user#$term_IP "sudo /root/nv9/DetectValidator"
fi
The job is working fine, and returns correct values, but only for the first element of array.
PS - I already searched through this and other sites, and - following answer didn't help me - Shell script while read line loop stops after the first line (already "ssh -n -o").
Perhaps you can point me, what I missed.
Possibly this ssh call eats your input:
sudo sshpass -p 'some.pass' ssh -o StrictHostKeyChecking=no user#$term_IP "sudo test -d /root/nv9"
^^^
Try adding -n.

Post datas from distant file

I know how to post data from a local file with curl :
curl -i -X POST -H 'Content-Type: text/plain' -d #foo.txt http://bar.com/foobar
But I would like to do the same, but from a distant file, for example :
curl -i -X POST -H 'Content-Type: text/plain' -d #http://www.google.fr/robots.txt http://bar.com/foobar
If I try this command, I have warnings : Couldn't read data from file, this makes an empty POST.
Is is possible to do that?
I suppose that my answer is not new for you, but why you can't do this:
curl http://www.google.fr/robots.txt > /tmp/foo.txt
curl -i -X POST -H 'Content-Type: text/plain' -d #/tmp/foo.txt http://bar.com/foobar

Regex for parsing function command line arguments

How i can parse the following function command line:
The separtor is (\s-\w\s) like -c or -d or -n
C:/my app/bin/Reader.dll -n Proc_20ms -c C:/Users/Braun/Desktop/test.csv -t Continue the simulation from the first line of the csv-file -j none -V errors and warnings (default) -d ,
to:
Match1: C:/my app/bin/Reader.dll
Match2: -n
Match3: Proc_20ms
Match4: -c
Match5: C:/Users/Braun/Desktop/test.csv
Match6: -t
Match7: Continue the simulation from the first line of the csv-file
Match8: -j
Match9: none
Match10: -V
Match11: errors and warnings (default)
Match12: -d
Match13: ,
Thanks.
Just put -\w inside a capturing group and then use this regex in re.split function. capturing group is necessary, so that it would keep the delimiter (ie, only the chars present inside the capturing group).
>>> s = 'C:/my app/bin/Reader.dll -n Proc_20ms -c C:/Users/Braun/Desktop/test.csv -t Continue the simulation from the first line of the csv-file -j none -V errors and warnings (default) -d ,'
>>> for i in re.split(r'\s(-\w)\s', s):
print(i)
C:/my app/bin/Reader.dll
-n
Proc_20ms
-c
C:/Users/Braun/Desktop/test.csv
-t
Continue the simulation from the first line of the csv-file
-j
none
-V
errors and warnings (default)
-d
,

Using cmake variable in execute_process command in cmake file

I am using execute_process() function in cmake.
message(" FLAGS = ${FLAGS}")
message(" SCATTERFILE = ${SCATTERFILE}")
set ( EXECUTE_COMMAND "arm-none-eabi-gcc ${FLAGS} -E -P -x c-header ${SCATTERFILE} -o ~/ttt.ld" )
message("EXECUTE_COMMAND = ${EXECUTE_COMMAND}")
execute_process(COMMAND ${EXECUTE_COMMAND} RESULT_VARIABLE rv )
Everything is displayed perfectly as a result of message() command, but it causes errors when it is run while parsing cmake. I think the FLAGS variable is not expanding as expected while parsing. When I run the same EXECUTE_COMMAND which is displayed as a result of message command in the terminal it runs perfectly. what could be the issue ?
Edit:
I have removed ${FLAGS} from
set ( EXECUTE_COMMAND "arm-none-eabi-gcc ${FLAGS} -E -P -x c-header ${SCATTERFILE} -o ~/ttt.ld" )`
now I am using
set ( EXECUTE_COMMAND "arm-none-eabi-gcc -E -P -x c-header ${SCATTERFILE} " )
The output is:
EXECUTE_COMMAND arm-none-eabi-gcc -E -P -x c-header ~/scatterFile.scatter rv: No such File or directory.
If I simply enter this command on the terminal,
arm-none-eabi-gcc -E -P -x c-header ~/scatterFile.scatter
it executes and gives the expected results.
The problem is you're trying to execute a program named "arm-none-eabi-gcc -E -P -x c-header ~/scatterFile.scatter rv". Notice the syntax of execute_process():
COMMAND <cmd1> [args1...]
To make it even clearer, the documentatin could actually write it as:
COMMAND cmd1 [arg1 [arg1 ...]]
CMake expects the command name as one CMake argument and each command-line argument as another separate CMake argument. You're enclosing everything in quotes, however, which turns it into one CMake argument (containing lots of spaces). Change your code as follows:
set (EXECUTE_COMMAND arm-none-eabi-gcc ${FLAGS} -E -P -x c-header ${SCATTERFILE} -o ~/ttt.ld)
execute_process(COMMAND ${EXECUTE_COMMAND} RESULT_VARIABLE rv)

Resources