Tag Archives: Open Source

Playing around with Nagios

I have been playing around with Nagios lately. This is the most widely used monitoring tool. I’m not going to write another howto, but clarify some things I found missing in the configuration manuals I used.

First you need the PHP module on the apache server for Nagios to work. Else you will find yourself downloading a phtml file to some directory in your box. This is because of the following files in the nagios directory.

xavi@server:~$ sudo find /nagios/ -type f -name "*.php"
/nagios/share/side.php
/nagios/share/includes/utils.inc.php
/nagios/share/main.php
/nagios/share/config.inc.php
/nagios/share/index.php
xavi@server:~$ 

Another issue I found was the with nrpe plugin. This plugin allows us to run commands on remote hosts. Issue is that default compilation values don’t allow us to pass arguments. To pass arguments from the server to the monitored host it must be compiled with the –enable-command-args argument when compiling the nrpe source. Another thing that must be done is setting the dont_blame_nrpe to 1 in the nrpe.cfg file.

dont_blame_nrpe=1

This changes allows us to run checks with arguments remotely. Example:

server:/nagios/libexec# ./check_nrpe -H 212.34.95.23 -c check_procs -a 100 120
PROCS OK: 96 processes
server:/nagios/libexec#

Questions and suggestions are always welcome. 🙂

Restoring IPtables when box reboots

Todays post is also going to be short.
I have a VPS server running and the other day they had to reboot my host because of maintenance. Things is I lost my running iptables when the box was rebooted. So how do we get this fixed? You can create a script and us update-rc.d and make it run on the default runlevel. However, we are going to do it different. We will use /etc/network/interfaces and iptables-restore.
Continue reading

Useful sed

This is going to be a really small post. Sometimes there are a lot of comments on files. How do we clean it up a little? Using sed. Lets show an example.

[14:21:55] xavi@NewYork:/tmp $ sed -e '/^#/d' /etc/ssh/sshd_config | sed -e '/^$/d'
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
[14:22:06] xavi@NewYork:/tmp $

First sed removes lines starting with a #. Our input file is the sshd config file, but it can be any other. The output is then piped to remove the empty lines leaving us with a clean configuration file.

Comments are always welcome. Yes, I know there are some security flaws in the config file, but that is not what we are dealing with in this howto. 🙂
References:

  1. http://www.grymoire.com/Unix/Sed.html
  2. http://en.wikipedia.org/wiki/Sed

Apache MySQL authentication

Lets explain how to configure Apache MySQL authentication. We will suppose apache web server is already up and running on the server.
First we need to install auth_mysql module.

$ sudo aptitude search libapache2-mod-auth-mysql
p   libapache2-mod-auth-mysql       - Apache 2 module for MySQL authentication  
$ sudo aptitude install libapache2-mod-auth-mysql

Continue reading

Controlling CPU frequency

We can control the CPU frequency with the cpufrequtils package. Installation is quite easy.

$ sudo aptitude install  cpufrequtils

To check to see if it’s installed.

[06:41:32] xavi@debian: ~ $ lsmod | grep -i cpu
acpi_cpufreq            6796  1 
cpufreq_powersave       1856  0 
cpufreq_stats           3776  0 
cpufreq_ondemand        6476  1 
freq_table              4224  3 acpi_cpufreq,cpufreq_stats,cpufreq_ondemand
cpufreq_userspace       3172  0 
cpufreq_conservative     5960  0 
processor              32576  4 acpi_cpufreq,thermal
[06:45:26] xavi@debian: ~ $ 

Continue reading