Nagios Core – How inheritance works in Nagios. A basic example.

The material below just illustrates the logic behind adding a remote host for monitoring under Nagios. It does not do a step by step account on how to add a remote host. Reason being is because one must understand the basic logic behind these configuration files. If the logic is not grasped then big miss configurations are bound to happen.

There are several configuration files that need consideration. If you have performed a manual install of NAGIOS Core the configuration files will reside under /usr/local/nagios/etc/

The main configuration file for Nagios is /usr/local/nagios/etc/nagios.cfg Under that file the location of the OBJECT Configuration files is defined. Below is the default structure of these configuration files.

# OBJECT CONFIGURATION FILE(S)
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg
cfg_file=/usr/local/nagios/etc/objects/switch.cfg
cfg_file=/usr/local/nagios/etc/objects/printer.cfg

Continue reading

Share Button

Python – Dice game. Count frequency of throws and face of dice.

Script loops six thousand times and generates a random number on each loop between 1 and six. Then it shows how many times those numbers came up.

 

#!/usr/bin/python
import random

freq_1 = 0
freq_2 = 0
freq_3 = 0
freq_4 = 0
freq_5 = 0
freq_6 = 0

for dice_loop in range ( 1, 6001 ):
face = random.randrange( 1, 7 )

if face == 1:
freq_1 += 1
if face == 2:
freq_2 += 1
if face == 3:
freq_3 += 1
if face == 4:
freq_4 += 1
if face == 5:
freq_5 += 1
if face == 6:
freq_6 += 1

print "Frequency of number 1 is: ", freq_1
print "Frequency of number 2 is: ", freq_2
print "Frequency of number 3 is: ", freq_3
print "Frequency of number 4 is: ", freq_4
print "Frequency of number 5 is: ", freq_5
print "Frequency of number 6 is: ", freq_6
sum = freq_1 + freq_2 + freq_3 + freq_4 + freq_5 + freq_6
print "------"
print "Toral frequency of random generated throws ", sum
Share Button

NAGIOS – How to do a WHOIS and SSL expiration check

Two plugins will be installed in order to do the WHOIS and SSL expiration checks. The directories of interest for NAGIOS for this case are:

Plugin Config files
/usr/local/nagios/etc/objects/
|–commands.cfg (This is where we do the definition for the service)
|–localhost.cfg (This is where we will define the thresholds)

Plugin files location
/usr/local/nagios/libexec/
|–nagios-check-crt.sh (The script that will check the SSL expirations)
|–nagios-check-dns-exp.tcl (The script that will check the WHOIS expiration)

 

Continue reading

Share Button

NAGIOS – How to setup Nagios v4 from source on Centos 6.5

The following commands will install all the required packcages to have NAGIOS up and running. Make sure to install the latest package of NAGIOS. In the “wget” command enter the latest release.

 

yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp
useradd nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
mkdir /root/nagios
cd /root/nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-X.X.X.tar.gz
wget https://www.nagios-plugins.org/download/nagios-plugins-X.X.tar.gz
tar –xvf nagios-X.X.X.tar.gz
tar –xvf nagios-plugins-X.X.tar.gz
cd nagios-X.X.X
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
service httpd start
cd /root/nagios
cd nagios-plugins-X.X
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
chkconfig --add nagios
chkconfig --level 35 nagios on
chkconfig --add httpd
chkconfig --level 35 httpd on
service nagios start 
Share Button

Python – argv and random number generator game

This script takes the value entered upon execution and compares it against a random number that is being generated.

#!/usr/bin/python
from sys import argv
import random
script, guess_number = argv

random_number = random.randint(1, 20)

print "Will generate random numbers"

if random_number > guess_number:
        print "Enter a lower number"
elif random_number < guess_number:
        print "Enter a larger number"
elif random_number == guess_number:
        print "Correct"
print random_number
print guess_number
Share Button

Python – KB to MB and MB to GB converter

A simple silly program that converts KBs to MBs and MBs to GBs.

 

#!/usr/bin/python

def conv_KB_to_MB(input_kilobyte):
        megabyte = float(0.000976562)
        convert_mb = megabyte * input_kilobyte
        return convert_mb
def conv_MB_to_GB(input_megabyte):
        gigabyte = float(9.5367431640625E-7)
        convert_gb = gigabyte * input_megabyte
        return convert_gb
#Create the menu


print "Enter 1 to convert from KBs to MBs"
print "Enter 2 to convert from MBs to GBs"


try:
        menu_choice = (raw_input("Enter a selection"))
except ValueError:
        print "This is not a number"
except NameError:
        print "Name Error"
except SystenError:
        print "Syntax Error"

if menu_choice == '1':
        kb_input = float(input("Enter KBs"))
        megabytes = conv_KB_to_MB(kb_input)
        print megabytes

elif menu_choice == '2':
        mb_input = float(input("Enter MBs"))
        gigabytes = conv_MB_to_GB(mb_input)
        print gigabytes
else:
        print "exiting"
Share Button

Python – argv module examples

Scripts that use the argv module which pass values to a script.

#!/usr/bin/python
from sys import argv
print " First argv ", first
print " Second argv ", second
print " Third argv ", third
print " Fourth argv ", fourth
Share Button

Python – Connect, Query a Postgresql database

The following code, will connect to a Postgresql database and execute a query. It will also throw and error in case the connection cannot be made.

 

#!/usr/bin/python
import psycopg2
con = None
try:
        con = psycopg2.connect(dbname = 'dvdrental', user = 'postgres')
        cursor = con.cursor()
        cursor.execute('SELECT * from actor')
        result = cursor.fetchall()
        for data in result:
                print(data[0], data[1])
#       print data
                cursor.close()
                con.close()

except psycopg2.DatabaseError, e:
                print "I am unable to connect to the database"
                sys.exit(1)

finally:
        if con:
                con.close()
Share Button

Python – A guessing number game with error exception handlers

The script below asks you to enter a number between 1 and 20. It generates a random number and the goal is to guess it. The script will prompt you to either a higher or lowe number. It also uses error handler in case you enter a character instead of a number.

Continue reading

Share Button

CentOS: MySQL-VSFTP authentication – Plus use this FTP directory as your YUM FTP repository.

This how to shows how to use VSFTPD with virtual users that authenticate against a MySQL database. This solution does not scale well because as far as I can tell you cannot have the MySQL database on an isolated server while other several FTP servers use it to authenticate user logins. My understanding is that both VSFTP and MySQL need to reside on the same machine in order for this work.If I am wrong please let me know.  In addition this how-to shows you how to setup this same VSFTP server as a FTP YUM repository.

Continue reading

Share Button