Check a Website Availability from the Linux Command Line

You can easily test a a website availability from the Linux command line and get the status codes from the web-server using commands like TELNET or CURL.

Check a website availability with CURL

Execute the following command to check whether a web site is up, and what status message the web server is showing:

$ curl -Is http://www.shellhacks.com | head -1
HTTP/1.1 200 OK

Status code ‘200 OK’ means that the request has succeeded and a website is reachable.

Here is an another example that shows you how curl displays different status codes.

$ curl -Is http://shellhacks.com | head -n 1
HTTP/1.1 301 Moved Permanently

You’ll notice that if you visit: http://shellhacks.com you are redirected to http://www.shellhacks.com, because I prefer to have www in my site’s URL. I do this by implementing a 301 Redirect (Permanently moved) for any visitor who goes to http://shellhacks.com.

You can also check the availability of a particular page on the site:

$ curl -Is http://www.shellhacks.com/Bash-Colors | head -n 1
HTTP/1.1 200 OK

Read more: Status Code Definitions

Check a website availability with TELNET

You can also test website availability and get the response code using telnet command:

$ telnet www.shellhacks.com 80
Trying 91.206.200.119...
Connected to www.shellhacks.com.
Escape character is '^]'.
HEAD / HTTP/1.0
HOST: www.shellhacks.com
<PRESS ENTER>
<PRESS ENTER>

You will get the output as follows:

HTTP/1.1 200 OK
Server: nginx/1.1.10
Date: Sun, 26 May 2013 19:29:46 GMT
***

That also means that the website is OK.

Installing the OCS Inventory Agent 1.x on CentOS/RHEL

Open Computer and Software Inventory (OCS-Inventory) – is a free software that enables users to inventory their IT assets.

OCS collects information about the hardware and software of networked machines running the OCS client program (“OCS Inventory Agent”).

This guide describes how to install OCS-Inventory Client (ocsinventory-agent) Series 1.x on CentOS/RHEL.

Adding EPEL Repository

There is no OCS Inventory Agent package in the standard repositories, so we will take it from EPEL repository.

If you need, you can use the guide that describes the installation process of EPEL repository.

The example of EPEL installation on CentOS 6.4 – 64bit:

# wget http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6
# rpm --import RPM-GPG-KEY-EPEL-6
# rm -f RPM-GPG-KEY-EPEL-6
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
# rm -f epel-release-6-8.noarch.rpm

Installing OCS Inventory Agent

Install the OCS Inventory Agent 1.x with the following command:

# yum install ocsinventory-agent

Configuring OCS Inventory Agent

Open the configuration file.

# vi /etc/ocsinventory/ocsinventory-agent.cfg

Uncomment the following lines. Set a tag for the current server and the address of your OCS server.

server = http://your.ocs.server/ocsinventory
tag = your_tag

Change the line local = /var/lib/ocsinventory-agent to basevardir = /var/lib/ocsinventory-agent. Save and close the file.

Forcing the Inventory

By default, the ‘ocsinventory-agent’ script was added to ‘cron.hourly’ and it will send the inventory to your OCS server every hour.

I advice you to move the script to ‘cron.daily’, to send the inventory once a day. In most cases it will be enough.

# mv /etc/cron.hourly/ocsinventory-agent /etc/cron.daily/

To force the sending of inventory execute the following:

# /usr/sbin/ocsinventory-agent

Troubleshooting

The problems I have encountered.

Packages perl-XML-Simple and perl-Net-IP not available

I had the following errors on RHEL 6.4 x86_64 system.

Error: Package: ocsinventory-agent-1.1.2.1-1.el6.noarch (epel)
           Requires: perl(XML::Simple)
Error: Package: ocsinventory-agent-1.1.2.1-1.el6.noarch (epel)
           Requires: perl(Net::IP)
# yum install perl-XML-Simple perl-Net-IP
***
No package perl-XML-Simple available.
No package perl-Net-IP available.

It means that your system is not subscribed to the RHEL ‘optional’ channel.

You can manually subscribe your system or install the required packages from rpm.

Search for perl-XML-Simple and perl-Net-IP on rpmfind.net and install them manually.

Example:

# rpm -ivh ftp://rpmfind.net/linux/centos/6.4/os/x86_64/Packages/perl-XML-Simple-2.18-6.el6.noarch.rpm
# rpm -ivh ftp://rpmfind.net/linux/centos/6.4/os/x86_64/Packages/perl-Net-IP-1.25-13.el6.noarch.rpm

500 Can’t connect to your.ocs.server:80 (connect: Connection timed out)

The following error in ocsinventory-agent.log means that OCS server is not reachable.

Test the connection with ping and telnet.

# telnet your.ocs.server 80
Trying your.ocs.server ...
telnet: connect to address your.ocs.server: Connection timed out

Check your firewall.

Installing the Check_MK Agent on CentOS/RHEL — Manual Install

Step 1: Download and uncompress the latest version of check_mk agent.

The check_mk agent for Linux consists of only two files: a shell script called ‘check_mk_agent.linux’ and a configuration file for ‘xinetd.conf’. They both can be found in the downloaded archive.

Example:

# cd /tmp
# wget http://mathias-kettner.de/download/check_mk-1.1.12p7.tar.gz
# tar -xvzf check_mk-1.1.12p7.tar.gz

Step 2: Installing ‘xinetd’.

Make sure ‘xinetd’ is installed

# rpm -qa | grep -i xinetd

If ‘xinetd’ is not installed then install it.

# yum install xinetd

Step 3: Copy the files and give the execute permissions for ‘check_mk_agent’.

# cd /tmp/check_mk-x.x.x
# tar -xvzf agents.tar.gz
# cp check_mk_agent.linux /usr/bin/check_mk_agent
# cp xinetd.conf /etc/xinetd.d/check_mk
# chmod +x /usr/bin/check_mk_agent

Step 4: Set the IP address of the monitoring server.

Set the IP in ‘/etc/xinetd.d/check_mk’ file.

"only from = IP_OF_MONITORING_SERVER"

Add the IP to ‘/etc/hosts.allow’.

"check_mk_agent : IP_OF_MONITORING_SERVER"

Step 5: Reload ‘xinetd’.

# service xinetd reload

In case if ‘xinetd’ has just been installed:

# service xinetd stop && service xinetd start

Step 6: Set the ‘xinetd’ to start at boot.

# chkconfig xinetd on

Step 7: Check that ‘xinetd’ is listening to port 6556.

# netstat -lpn | grep 6556

Example:

# netstat -lpn | grep 6556
tcp        0      0:::6556                    :::*                        LISTEN      28273/xinetd

Step 8: Add the rule to IPTABLES, if you use the firewall.

# vi /etc/sysconfig/iptables

Append the following line before the REJECT line, to open port 6556.

# iptables -I INPUT -p tcp --dport 6556 -j ACCEPT

Save and close the file. Restart the firewall.

# service iptables restart

Step 9: Test the connection.

If the agent is running properly, you should be able to connect to your Linux host.

Test the connection locally.

# telnet localhost 6556
<<<check_mk>>>
Version: 1.1.12p7
AgentOS: linux
***

Test the connection remotely from your monitoring server.

# telnet your.server.com 6556
<<<check_mk>>>
Version: 1.1.12p7
AgentOS: linux
***