Page 1 of 1
run curl on a remote server and collect response
Posted: Fri Nov 04, 2016 5:20 am
by kellyangell
Hello
I am trying to run a command "curl (web address)" on a remote machine to see if it can connect to the BE machine. can you please send me some instructions or maybe a link to a plugin so i can do this. the check_curl plugin is running it from the nagios machine , but i don't want that , i want nagios to connect to the remote machine and run the curl command from there. using NRPE .
I hope you can help
Thanks
This is the command definition i am running and i am getting back , check_curl not defined but it is defined !
define service {
use generic-service
host_name iceLIVEfe02
service_description FE to BE via NGINX
check_command check_nrpe!check_curl!
http://localhost:1080/iceserver/rest/apiv1/booking/info
# 'check_curl' command definition
define command{
command_name check_curl
command_line $USERS1$/check_nrpe -H $HOSTADDRESS$ check_curl -U $ARG1$
}
Re: run curl on a remote server and collect response
Posted: Fri Nov 04, 2016 10:20 am
by rkennedy
Code: Select all
# 'check_curl' command definition
define command{
command_name check_curl
command_line $USERS1$/check_nrpe -H $HOSTADDRESS$ check_curl -U $ARG1$
}
You actually want to turn this into a NRPE command definition on the CLIENT machine since we're calling, in your case -
Code: Select all
command[check_curl]=/path/to/your/plugin/check_curl $ARG1$
(usually this file is in /usr/local/nagios/etc/nrpe.cfg)
Then restart xinetd or nrpe depending on how you installed it on the client machine, and try once again.
Re: run curl on a remote server and collect response
Posted: Fri Nov 04, 2016 10:44 am
by kellyangell
great thanks , that works . next question , when i run this command on the server directly , this is the response we get to know that its working
"Booking with Spring 4.2.4.RELEASE"
how can i get nagios to monitor its OK if we get this "Booking with Spring 4.2.4.RELEASE" and if we don't the service is CRITICAL ??
Re: run curl on a remote server and collect response
Posted: Fri Nov 04, 2016 1:02 pm
by rkennedy
Could you post check_curl for us to look at? If it doesn't have the feature built in then you're a bit limited, but you could probably create your own wrapper around it.
Something like this -
Code: Select all
#!/bin/bash
myvar=$(/usr/local/nagios/libexec/check_curl yourvars | grep 'Booking with Spring' | wc -l)
...
...
This would set it to 1 if it detected the word, and 0 if not. Just define the logic.
check_http has this built in using the -r,-R, or -s flags.
Code: Select all
-s, --string=STRING
String to expect in the content
-r, --regex, --ereg=STRING
Search page for regex STRING
-R, --eregi=STRING
Search page for case-insensitive regex STRING
Re: run curl on a remote server and collect response
Posted: Sat Nov 05, 2016 9:45 am
by kellyangell
hello
i downloaded this from your nagios website , thanks for your great response , have a look and see what you think
thanks kelly
Re: run curl on a remote server and collect response
Posted: Mon Nov 07, 2016 3:48 am
by kellyangell
EDIT: Please wrap in code blocks
hi
the check_curl does have the search string included , but i have tried some variations , not too sure how to define it
Code: Select all
--------- check_curl_http.php v1.0, 06.06.2012 ---------
\n
Syntax:
-U URL
-A Agent (default: Mozilla/5.0 ... )
-a authentication [user]:[password]
-G Grep page on STRING (can be set multiple times for searching different strings)
-L Show page
-F Follow redirects
-I Ignore SSL certificate errors
-X Exclude performance data (default: include)
-Tc Ccritical page return time (seconds)
-Tw Warning page return time (seconds)
-Sbc Critical page size below SIZE (bytes)
-Soc Critical page size over SIZE (bytes)
-Sbw Warning page size below SIZE (bytes)
-Sow Warning page size over SIZE (bytes)
-S Find string between ARG1 and ARG2, return first match (s s) (example: value=\" \" )
-T Timeout (seconds)(default: 10sec)
-O Output Driven Check - Page Should respond with \"Status: OK\" or otherwise
-P HTTP proxy to tunnel request through [proxyname]:[port]
-Pu Authentication credentials for proxy [username]:[password]
-Pa Authentication method used for proxy connection. Either CURLAUTH_BASIC or CURLAUTH_NTLM
-Pt Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5
-C Specify OK http status code. By default, this is 200
\n\n Examples:
check_curl_http.php -U http://test.example.net
check_curl_http.php -U https://test.example.net -P myproxy.company.com:8080 -Pu proxyuser:password -F -G somesearchstring\n\n";
Re: run curl on a remote server and collect response
Posted: Mon Nov 07, 2016 2:32 pm
by avandemore
Did you read the BestPractice.txt included with the plugin?
https://exchange.nagios.org/directory/P ... tp/details
Re: run curl on a remote server and collect response
Posted: Tue Nov 08, 2016 4:17 am
by kellyangell
i have solved the issue by writing my own plugin, wasn't sure it would work at first , but sometimes the simple way around is the best one. its working , thanks for your help ,with this issue. you can close this as solved .
kelly
Re: run curl on a remote server and collect response
Posted: Tue Nov 08, 2016 10:27 am
by rkennedy
Sounds good, feel free to post it on our Exchange for others to see!
https://exchange.nagios.org