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)
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.
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 "Toral frequency of random generated throws ", sum
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
|–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
|–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)
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
usermod -G nagcmd nagios
usermod -G nagcmd apache
tar –xvf nagios-X.X.X.tar.gz
tar –xvf nagios-plugins-X.X.tar.gz
htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
service httpd start
./configure --with-nagios-user=nagios --with-nagios-group=nagios
/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
This script takes the value entered upon execution and compares it against a random number that is being generated.
from sys import argv
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:
A simple silly program that converts KBs to MBs and MBs to GBs.
megabyte = float(0.000976562)
convert_mb = megabyte * input_kilobyte
gigabyte = float(9.5367431640625E-7)
convert_gb = gigabyte * input_megabyte
#Create the menu
print "Enter 1 to convert from KBs to MBs"
print "Enter 2 to convert from MBs to GBs"
menu_choice = (raw_input("Enter a selection"))
print "This is not a number"
print "Name Error"
print "Syntax Error"
if menu_choice == '1':
kb_input = float(input("Enter KBs"))
megabytes = conv_KB_to_MB(kb_input)
elif menu_choice == '2':
mb_input = float(input("Enter MBs"))
gigabytes = conv_MB_to_GB(mb_input)
Scripts that use the argv module which pass values to a script.
from sys import argv
print " First argv ", first
print " Second argv ", second
print " Third argv ", third
print " Fourth argv ", fourth
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.
con = None
con = psycopg2.connect(dbname = 'dvdrental', user = 'postgres')
cursor = con.cursor()
cursor.execute('SELECT * from actor')
result = cursor.fetchall()
for data in result:
# print data
except psycopg2.DatabaseError, e:
print "I am unable to connect to the database"
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.
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.