Openvpn nagios pluging

You can use Nagios to monitor all sorts of hardware and software. The opportunity to write your own plug-ins makes it possible to monitor everything that your Nagios server can communicate with. As you can use any computing language that manages command-line arguments and exit status.
Here you find a nagios pluging developed with python.
The pluging named check_openvpn, it connects to the management OpenVPN server checks for actives connection and return the amount connected OpenVPN clients. it’s forked from openvpn-status scripts.

First of all download the check_openvpn script into your pluging directory on debian it’s /usr/lib/nagios/plugins/.

To use the new plug-in, you have to register it first, create the file command called openvpn.cfg with contents as below:

$ sudo cat > /etc/nagios-plugins/config/openvpn.cfg

define command {
command_name check_openvpn
command_line /usr/lib/nagios/plugins/check_openvpn -t $ARG1$ -p $ARG2$ -n $ARG3$

Let’s create some hostgroups – say openvpn-server

$ sudo cat >> /etc/nagios3/conf.d/hostgroups_nagios2.cfg

define hostgroup {
hostgroup_name openvpn-server
alias openvpn servers
members myhost

replace by your openvpn server address, and myhost by the openvpn server name.
Now let’s define those hosts:

$ sudo cat >> /etc/nagios3/conf.d/hosts.cfg

define host {
use generic-host;
host_name myhost;

Now we can define services that run in the new hostgroups

$ sudo cat >> /etc/nagios3/conf.d/services_nagios2.cfg

define service {
hostgroup_name opevpn
service_description OPENVPN
check_command check_openvpn!host!port!passwd
use generic-service
notification_interval 0

replace “host” by the address of your openvpn server, “port” by the openvpn management server port and “passwd” by the openvpn nanagement server password.

Don’t forget to check your configuration
$ sudo nagios3 -v /etc/nagios3/nagios.cfg

Then restart the daemon
$ sudo /etc/init.d/nagios3 restart

If all that went well, you should be able to go back to the Hostgroup Overview page on your Nagios install and see the new hostgroups and hosts.

Openvpn nagios pluging

How to repair Grub loader

GNU GRUB (“GRUB” for short) is a boot loader package from the GNU Project. GRUB is the reference implementation of the Multiboot Specification, which allows a user to have several different operating systems on their computer at once, and to choose which one to run when the computer starts. GRUB can be used to select from different kernel images available on a particular operating system’s partitions, as well as to pass boot-time parameters to such kernels.

Every once in a while windows may have the inclination to overwrite your bootloader with its own. This will make accessing your system impossible.
Well, there is a solution to override the 512 Kb of your drive that represent the MBR.
In the fact you can follow these steps to repair your GRUB loader:
Boot your PC with a Live CD in the drive, after run fdisk to display list of your partitions system.

$ sudo /sbin/fdisk -l

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa588e9cb

Device Boot Start End Blocks Id System
/dev/sda1 * 1 30071 241545276 83 Linux
/dev/sda2 30072 30401 2650725 5 Extended
/dev/sda5 30072 30401 2650693+ 82 Linux swap / Solaris

In that fdisk example, the root linux partition reside in /dev/sda1
Create a directory /mnt/root and mount the linux partition.

$ sudo mkdir /mnt/root
$ sudo mount /dev/sda1 /mnt/root

Change the root “/” directory to our old root directory the /mnt/root
$ sudo chroot /mnt/root /bin/bash

Execute the grub command
$ sudo grub –config-file=/boot/grub/menbu.lst

GNU GRUB version 0.97 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For
the first word, TAB lists possible command
completions. Anywhere else TAB lists the possible
completions of a device/filename. ]

Now we need to tell grub where are the grub files:
If you don’t know where they are, type:
grub> find /boot/grub/stage1

Now type the following, replacing hd0 with the physical drive linux is installed
grub> root (hd0,0)

Remember that for grub (hd0,0) means hda (primary controller master), first partition.
Let’s install the grub on hd0
grub> setup (hd0,0)
grub> quit

$ sudo reboot
Now you can reboot safely, with your linux system.

How to repair Grub loader

How to look up domain names and addresses.

To resolve host names and addresses in the domain name system or the local hosts, there are many functions defined as well as the function gethostbyname.

The gethostbyname() is a function that returns a structure of type hostent for the given host name.
Here name is either a host name, or an IPv4 address in standard dot notation.
You can find here an example of using gethostbyname(3).

#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>

struct hostent *ptr;

/* The hostent structure is defined in as follows:
struct hostent {
char *h_name; //official name of host
char **h_aliases; //alias list
int h_addrtype; //host address type
int h_length; // length of address
char **h_addr_list; //list of addresses
#define h_addr h_addr_list[0]

main(int argc, char **argv)

// two arguments are permitted
// the second one is the hostname

if (argc != 2) {
fprintf(stderr,”Usage: %s hostname\n”,argv[0]);

ptr = gethostbyname(argv[1]);
int i=0;

// gethostbyname() returns NULL pointer if failed.
if (ptr == NULL) {
fprintf(stderr,”gethostbyname() failed\n”);
} else {

// If the host name, has many translation address so, until there are addresses loop

// we will only use the s_addr field in the in_addr structure
// which records the host address number as an uint32_t

while(ptr -> h_addr_list[i]) {
if ( ptr -> h_addr_list[i] != NULL)
printf(“%s\n”, inet_ntoa( *( struct in_addr*)( ptr -> h_addr_list[i])));
return 0;


How to look up domain names and addresses.

How to add applications to sourceforge

Here i’ve marked the steps that i followed to share cwhois and how i upload it to sourceforge.
First of all, i prepared the code source of cwhois application, i archived it and i compressed it with bzip2.
Sourceforge provides a file management service to ease the process of uploading files.
The file management service allows upload via web form, WebDAV, SFTP, SCP, and rsync over SSH.

I used a WebDAV linux client named cadaver. You can installed with aptitude
$ sudo aptitude install cadaver

After, i run cadaver like this:
$ cadaver
Authentication required for File Release System on server `’:
Username: handrix
dav:/h/ha/handrix/uploads/> put cwhois.tar.bz2
Uploading cwhois.tar.bz2 to `/h/ha/handrix/uploads/cwhois.tar.bz2′:
Progress: [=============================>] 100,0% of 92456 bytes succeeded.

Note that the upload url is in this form
where ‘u’ is the first occurence in your username, ‘us’ is the first and the second character,
and ‘user’ have also to be remplaced with your username.
So, i put the application.

Well everything seems to be ok, i went to > Projects > cwhois > Admin > File Releases
and i added a release 0.1, also i added the uploaded File cwhois.tar.bz2 To This Release.

In the next step i configured the project’s Git repository.

$ git init
$ git config –global “MEZGANI ali”
$ git config –global “”
$ git add .
$ git commit -u
$ git remote add origin ssh://
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
$ git push origin master

Once that is done, i was able to browse my newly-committed content via gitweb.

Lastly, for backupping we can use rsync as well as :
$ rsync -av* cwhois

How to add applications to sourceforge

mkdir and cd

Many times, i find myself making and moving to a directory quite a bit, normally I use something like this
$ mkdir ~/dir && cd ~/dir
$ mkdir -p create/new/dir && cd create/new/dir
You can’t have a simple BASH script that reads “mkdir $1 && cd $1” because it would only switch to the directory while running as a child process instead of actually switching to the directory.
However there is a quick and easy way to combine the tasks, add a function mkcd() to your .bashrc.
$ cat >> ~/bashrc
function mkcd(){
[ -n “$1” ] && mkdir -p “$@” && cd “$1”;

mkdir and cd

An introduction to what's new in Linux kernel version 2.6.29

The 2.6.29 release contain an amazing amount of new functionality :

Kernel based graphic mode setting:
This feature allows the kernel to control the graphics hardware after the required components are initialized (such as the PCI bus and graphics card).
In this way, the kernel can enter the desired screen resolution much earlier in the boot process.

Networking changes:
WiMAX support,
Worldwide Inter-operability for Microwave Access, a telecommunication technology that provides
wireless transmission of data using a variety of transmission modes.
It provides up to 75 Mbit/s symmetric broadband speed without the need for cables.
The technology is based on the IEEE 802.16 standard (also called Broadband Wireless Access).
The stack has been provided by Intel, and it includes a driver for the Intel Wireless WiMAX/Wi-Fi Link
5×50 USB/SDIO devices.

Access Point support in the wifi stack,
Wireless access points (APs or WAPs) are specially configured nodes on wireless local area
networks (WLANs).
Access points act as a central transmitter and receiver of WLAN radio signals.

Btrfs is a new filesystem developed from scratch following the design principles of filesystems like ZFS, WAFL, etc.
It was created by Oracle. btrfs is licensed under GPL.
The main Btrfs features include:

  • Extent based file storage (2^64 max file size)
  • Space efficient packing of small files
  • Space efficient indexed directories
  • Dynamic inode allocation
  • Writable snapshots
  • Subvolumes (separate internal filesystem roots)
  • Compression

… more information about btrfs can be found in the btrfs wiki page.

Squashfs is a compressed read-only filesystem for Linux. Squashfs is intended for general read-only filesystem use,
for archival use, and in constrained block device/memory systems (e.g. embedded systems) where low overhead is needed.
It is used by the Live CD versions of Debian, Fedora, Gentoo Linux, GParted, Ubuntu, … and on embedded distributions such as
the OpenWRT and DD-WRT router firmware.
Squashfs is also free software (licensed under the GPL) for accessing Squashfs filesystems.
Some squashfs overview:

  • Data, inodes and directories are compressed.
  • Squashfs stores full uid/gids (32 bits), and file creation time.
  • Files up to 2^64 bytes are supported. Filesystems can be up to 2^64 bytes.
  • Inode and directory data are highly compacted, and packed on byte boundaries.
  • Squashfs can use block sizes up to 1 024 kbytes.
  • File duplicates are detected and removed.
  • Both big and little endian architectures are supported

And many others functionalties are included :

  • ecryptfs filename encryption,
  • ext4 no journaling mode,
  • ocfs2 metadata checksums,
  • a more scalable RCU implementation,
  • filesystem freeze support,
  • swap management in the memory controller,
  • many new drivers and many other improvements.
An introduction to what's new in Linux kernel version 2.6.29