curl --silent http://www.theurl.com/thefiles/ | egrep -o "<a href=[^>]*>*.csv.gz"
| sed 's/<a href=\"\([^"]*\).*/\1/g'
The --silent flag in curl supresses the progress information and any error messages
curl --silent http://www.theurl.com/thefiles/ | egrep -o "<a href=[^>]*>*.csv.gz"
| sed 's/<a href=\"\([^"]*\).*/\1/g'
require 'socket'
The code here below can be used to see if linux is listening on a particular port.
def port_open?(ip, port, timeout)
start_time = Time.now
current_time = start_time
while (current_time - start_time) <= timeout
begin
TCPSocket.new(ip, port)
return true
rescue Errno::ECONNREFUSED
sleep 0.1
end
current_time = Time.now
end
return false
end
This can be called with the following:-
port_open?(Socket.gethostname, 80, 10)
def make_dir(dir_path)
directory dir_path do
owner username
group usergroup
mode "0755"
recursive true
action :create
end
end
make_dir("/tmp/foo")
make_dir("/tmp/foo/bar")
/usr/local/nagios/libexec
Write the script in your language of choice and ensure it is runable by the nagios user. echo "The check has passed"
exit 0
The script could also be written in other languages for example the same above in Python:- import sys
print 'The check has passed'
sys.exit(0)
The same above in Ruby:- puts "The check has passed"
exit 0
Once the script is thoroughly tested it needs to be linked to nagios. You should be aiming for a script which takes a short amount of time to run. i.e. under 10 seconds, although the timeout can be extended if neccessary. Since this is a local check a config file needs to be put in the nrpe_local directory. The contents of this file could be something like the following:- cat /usr/local/nagios/etc/nrpe_local/new_check.sh
The service will now need restarting. -H $HOSTADDRESS$ -c new_check
Note that this can be tested via on the host with the following:- /usr/local/nagios/libexec/check_nrpe -H `hostname` -c new_check