run curl on a remote server and collect response

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
kellyangell
Posts: 18
Joined: Mon Aug 08, 2016 3:20 am

run curl on a remote server and collect response

Post 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$
}
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: run curl on a remote server and collect response

Post 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.
Former Nagios Employee
kellyangell
Posts: 18
Joined: Mon Aug 08, 2016 3:20 am

Re: run curl on a remote server and collect response

Post 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 ??
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: run curl on a remote server and collect response

Post 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
Former Nagios Employee
kellyangell
Posts: 18
Joined: Mon Aug 08, 2016 3:20 am

Re: run curl on a remote server and collect response

Post 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
Attachments
checkcurl .rtf
(13.46 KiB) Downloaded 754 times
kellyangell
Posts: 18
Joined: Mon Aug 08, 2016 3:20 am

Re: run curl on a remote server and collect response

Post 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";
avandemore
Posts: 1597
Joined: Tue Sep 27, 2016 4:57 pm

Re: run curl on a remote server and collect response

Post by avandemore »

Did you read the BestPractice.txt included with the plugin?

https://exchange.nagios.org/directory/P ... tp/details
Previous Nagios employee
kellyangell
Posts: 18
Joined: Mon Aug 08, 2016 3:20 am

Re: run curl on a remote server and collect response

Post 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
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: run curl on a remote server and collect response

Post by rkennedy »

Sounds good, feel free to post it on our Exchange for others to see! :)

https://exchange.nagios.org
Former Nagios Employee
Locked