Moving RRD file from 32bit to 64bit Architecture

August 23, 2016 Leave a comment
When we were working on a nagios monitoring system we were migrating from a 32bit nagios to a 64bit Architecture.
Most of the graphs are not working as the RRD was from an older 32bit architecture.
Location of perfdata on nagios server.
[root@nagios-server perfdata]# pwd 
/usr/local/nagios/share/perfdata
Error when we load the graph.
ERROR: This RRD was created on another architecture
This can re solved by converting the exsisting 32bit RRD to XML and then restoring into the new 64bit Architecture.

Creating a xml dump for rrd file.

rrdtool dump cpu_load.rrd > cpu_load.xml
Move the XML file to the new server (64bit)

Restore the XML file back.

rrdtool restore -f cpu_load.xml cpu_load.rrd
Testing if the RRD file is create fine, use below command.
rrdtool info cpu_load.rrd
Now you should be able to see all the graphs on the server.

from Blogger http://ift.tt/2bi1Ibz
via IFTTT

Categories: Others Tags: ,

Remove Old Files using find Command

August 23, 2016 Leave a comment
GNU find searches the directory tree rooted at each given file name by evaluating the given expression from left to right, according to the rules of precedence, until the outcome is known (the left hand side is false for and operations, true for or), at which point find moves on to the next file name.
Remove old files which are older than a specific time using find Command

Command

find /path/to/files* -mtime +5 -exec rm {} \;
Note that there are spaces between rm, {}, and \;

Command Explanation.

-mtime n 
    File's data was last modified n*24 hours ago. See the comments for -atime to  
    understand how rounding affects the interpretation of file modification times.  

-exec command {} + 
    This variant of the -exec action runs the specified command on the selected  
    files,     but the command line is built by appending each selected file name at  
    the end; the total number of invocations of the command will be much less than  
    the number of matched files.  

    The command line is built in much the same way that xargs builds its command lines.  
    Only one instance of '{}' is allowed within the command.  
    The command is executed in the starting directory.
Thats it.

from Blogger http://ift.tt/2bi1xNJ
via IFTTT

Categories: Others Tags: ,

Migrating Nagios XI to a New Server on Centos6.6

August 20, 2016 Leave a comment
Migrating an old Nagios backup to a new nagiosxi server. Migration is simple in Nagios XI, you a backup and restore it.
Once that is done we need to update/add the clients with IP of the new server, so that both Nagios get alerts. After a while once we are comfortable with the new server we can decommission the old one.
For example we will use two servers.
  • old_nagios (nagiosximon)
  • new_nagios (nagioserver)

Backup from Old Server.

Lets first take a backup from the old_nagios server.
[root@nagiosximon ~]# /usr/local/nagiosxi/scripts/backup_xi.sh 
Running configuration check...
Stopping nagios: done.
Starting nagios: done.
Backing up Core Config Manager (NagiosQL)...
tar: Removing leading `/' from member names
tar: Removing leading `/' from member names
Backing up Nagios Core...
tar: Removing leading `/' from member names
tar: /usr/local/nagios/var/rw/nagios.qh: socket ignored
tar: /usr/local/nagios/var/ndo.sock: socket ignored
Backing up Nagios XI...
tar: Removing leading `/' from member names
Backing up MRTG...
tar: Removing leading `/' from member names
Backing up NRDP...
tar: Removing leading `/' from member names
Backing up Nagvis...
tar: Removing leading `/' from member names
Backing up MySQL databases...
Backing up logrotate config files...
Backing up Apache config files...
Compressing backup...

===============
BACKUP COMPLETE
===============
Backup stored in /store/backups/nagiosxi/1471501361.tar.gz
[root@nagiosximon ~]# ls

Restoring backup to the new_nagios server.

IMPORTANT : But now most of the server will not be able to send notifications to the new server, so you will recieve notifications, better idea is to disable notifications till we are done with all the configuration.
[root@nagiosserver ahmed]# /usr/local/nagiosxi/scripts/restore_xi.sh /home/ahmed/Desktop/1471501361.tar.gz 
TS=1471501690
Extracting backup to /store/backups/nagiosxi/1471501690-restore...
In /store/backups/nagiosxi/1471501690-restore/1471501361...
Backup files look okay.  Preparing to restore...
Shutting down services...
Stopping nagios: done.
Stopping ndo2db: done.
NPCD Stopped.
Restoring directories to /...
Restoring Nagios Core...
Restoring Nagios XI...
Restoring NagiosQL...
Restoring NagiosQL backups...
Restoring NRDP backups...
Restoring MRTG...
Restoring Nagvis backups...
Restoring MySQL databases...
Restoring Nagios XI MySQL database...
Restarting database servers...
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
Restoring logrotate config files...
Restoring Apache config files...
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
NPCD started.
Starting ndo2db: done.
Starting nagios: done.

===============
RESTORE COMPLETE
===============

Linux Client Configuration [NRPE].

As the service is running on the server, and the inbound requests are handled by xinetd, so we need to add the new server information in the configuration.
  • Open file /etc/xinetd.d/nrpe
  • Added a new entry only_from += 172.3.2.0/24 after the only_from line. We have given a mask address, but this can be an IP as well. (This should be the IP Address or IP Range for new_nagios server)
  • Save, Close and Restart xinetd
Here is how the configuration file looks like.
root@nagiosxi-test-linux:~# cat /etc/xinetd.d/nrpe 
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
           flags           = REUSE
    socket_type     = stream    
    port        = 5666    
           wait            = no
    user            = nagios
    group        = nagios
           server          = /usr/local/nagios/bin/nrpe
    server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
           log_on_failure  += USERID
    disable         = no

    # Old server IP
    only_from    = 172.2.2.123

    # New Server IP
    only_from    += 172.3.2.123

    # Range of IPs using Masking.
    only_from     += 172.3.2.0/24        
}
Restart xinetd service.
root@nagiosxi-test-linux:~# service xinetd restart
xinetd stop/waiting
xinetd start/running, process 15883

Windows Client Configuration [NSClient++].

Here as well we have to update allowed hosts parameter in nsclient.ini
  • Open run -> services.msc
  • Stop the NSClient++ service.
  • Goto Location C:\Program Files\NSClient++
  • Now go to start -> notepad -> open notepad with Run as Administrator Option.
  • Now your notepad has admin permission.
  • Open the file nsclient.ini which is located in C:\Program Files\NSClient++
  • Added the new_nagios server IP in the allowed hosts list, its a comma separated values list.
Here is how part of the configuration looks like.
;Undocumented section
[/settings/default]

;Undocumented key
password = nagios123

;Undocumented key
allowed hosts = 127.0.0.1, 172.2.2.123, 172.3.2.123
  • Finally save, close and Start NSClient++ service.
We are done. Now you will start seeing updated service information on the new_nagios server.

from Blogger http://ift.tt/2b6SErs
via IFTTT

Categories: Others Tags: ,

Setting up ssl https On Nagios XI Server

August 19, 2016 Leave a comment
HTTPS is a protocol for secure communication over a computer network which is widely used on the Internet. HTTPS consists of communication over Hypertext Transfer Protocol (HTTP) within a connection encrypted by Transport Layer Security or its predecessor, Secure Sockets Layer. The main motivation for HTTPS is authentication of the visited website and protection of the privacy and integrity of the exchanged data. Intro Courtesy Wikipedia
Full SSL support requires Nagios XI version 2011R1.6 or later.

Before we start.

Check if the below packages are install, they should be if you are using latest Nagios XI, but check them anyways.
yum install mod_ssl openssl

Creating Key and Certificate

Lets generate the key for the server.
openssl genrsa -out ca.key 2048
Output for the command.
[ahmed@nagiosserver ~]$ openssl genrsa -out ca.key 2048
Generating RSA private key, 2048 bit long modulus
.................................................................................................................+++
.....................................+++
e is 65537 (0x10001)
Now we create the certificate.
openssl req -new -key ca.key -out ca.csr
Here is the output for the command.
[ahmed@nagiosserver ~]$ openssl req -new -key ca.key -out ca.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:TR
State or Province Name (full name) []:Istanbul
Locality Name (eg, city) [Default City]:Istanbul
Organization Name (eg, company) [Default Company Ltd]:Ahmed, Inc
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:nagiosserver.ahmed.com
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
We have not entered anything in the extra attributes, but this is fine.
Checking the certificate.
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt
Output.
[ahmed@nagiosserver ~]$ openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt
Signature ok
subject=/C=TR/ST=Istanbul/L=Istanbul/O=Ahmed, Inc/CN=nagiosserver.ahmed.com
Getting Private key
[ahmed@nagiosserver ~]$

Copy Key/Certificate to Specific Location.

Now we need to copy the certificate files to the correct location and set permissions:
cp ca.crt /etc/pki/tls/certs
cp ca.key ca.csr /etc/pki/tls/private/
Setting permissions.
chmod go-rwx /etc/pki/tls/certs/ca.crt
chmod go-rwx /etc/pki/tls/private/ca.key

Update Apache Configuration

Open the /etc/httpd/conf.d/ssl.conf, find the following lines and update path, this is similar to what we copied earlier.
SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key
Here is how the Configuration looks like.
ssl cert
In that same file add the below contents just before

tag:


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]

Here is how a part of the config looks like.
IfModule

Update httpd.conf Configuration.

Update /etc/httpd/conf/httpd.conf, Add the following lines to the end of the file:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Here how the file looks like.
httpd config

Next we restart httpd

sudo service httpd restart
Ouput.
[ahmed@nagiosserver ~]$ sudo service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for nagiosserver
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [  OK  ]
Now we can go to http://ift.tt/2b02wVs, you get a warning about self certified certificate, add it to exception and we are ready.

And we are done.

[Important] Now we update Nagios XI Configuration.

  • First update the config.inc.php file.
Here is the path to the file.
[ahmed@nagiosserver ~]# vim /usr/local/nagiosxi/html/config.inc.php
Update the below configuration in the file. (Currently $cfg['use_https'] = false;)
// force http/https
$cfg['use_https'] = true; // determines whether cron jobs and other scripts will force the use of HTTPS instead of HTTP
  • Next logon to Nagios XI server as nagiosadmin.
  • Go to Admin -> on the left pane System Config -> System Settings -> General.
  • Change the URL to https. Change http://172.2.2.23/nagiosxi/ to https://172.2.2.23/nagiosxi/
  • Next go to Configure on the top tab -> Core Config Manager -> On the left pane Config Manager Admin -> Core Manager Settings -> Change Server Protocol to HTTPS
Restart nagios, httpd.
NOTE : If you are using filewall make sure to add the entry to iptables
iptables -I INPUT -p tcp --dport 443 -j ACCEPT
service iptables save
Now logon to the server. https://nagiosserver.ahmed.com/
Categories: Others Tags: ,

Update hosts file in Windows 8

August 18, 2016 Leave a comment
Host file contains IP followed by the FQDN which can be used to reach that IP address. Host file takes precedence over your DNS servers. In Microsoft operating systems, the HOSTS file is located in the following location: C:\Windows\System32\Drivers\etc
You will see a file called host below are the contents.
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#    127.0.0.1       localhost
#    ::1             localhost

172.2.2.24  chefmgrserver.ahmed.com
NOTE this file cannot be updated without an admin permission.
Here is how you can update this file.
  • First go to start -> notepad -> open notepad with Run as Administrator Option.
  • Now your notepad has admin permission.
  • Open the host file in the notepad and update the contents as you like.
  • Update should be .
  • Save and close.
  • Now if you are running a webserver or some web application on the IP address mentioned above, then you can go to the browser and hit http:// you will reach the IP you had mentioned in the host file.

On Linux this is way too simple.

Host file is present in /etc/hosts, update using sudo privileges and you are done.

from Blogger http://ift.tt/2b53o8w
via IFTTT

Categories: Others Tags: ,

Creating Documents Using pandoc

August 17, 2016 Leave a comment
Pandoc is an opensource utility to create documents from markdown. We can create PDF, Doc, doc, html and other formats. And can be also used to convert html to doc, html to pdf, markdown to pdf and many more.
If you need to convert files from one markup format into another, pandoc is your swiss-army knife. Pandoc can convert documents in markdown, reStructuredText, textile, HTML, DocBook, LaTeX, MediaWiki markup, TWiki markup, OPML, Emacs Org-Mode, Txt2Tags, Microsoft Word docx, LibreOffice ODT, EPUB, or Haddock markup to
  • HTML formats: XHTML, HTML5, and HTML slide shows using Slidy, reveal.js, Slideous, S5, or DZSlides.
  • Word processor formats: Microsoft Word docx, OpenOffice/LibreOffice ODT, OpenDocument XML
  • Ebooks: EPUB version 2 or 3, FictionBook2
  • Documentation formats: DocBook, TEI Simple, GNU TexInfo, Groff man pages, Haddock markup
  • Page layout formats: InDesign ICML
  • Outline formats: OPML
  • TeX formats: LaTeX, ConTeXt, LaTeX Beamer slides
  • PDF via LaTeX
  • Lightweight markup formats: Markdown (including CommonMark), reStructuredText, AsciiDoc, MediaWiki markup, DokuWiki markup, Emacs Org-Mode, Textile
  • Custom formats: custom writers can be written in lua.
Pandoc understands a number of useful markdown syntax extensions, including document metadata (title, author, date); footnotes; tables; definition lists; superscript and subscript; strikeout; enhanced ordered lists (start number and numbering style are significant); running example lists; delimited code blocks with syntax highlighting; smart quotes, dashes, and ellipses; markdown inside HTML blocks; and inline LaTeX. If strict markdown compatibility is desired, all of these extensions can be turned off.

Installing pandoc on Centos / Ubuntu

On Centos/RHEL
[ahmed@mylaptop ~]# yum install pandoc
[ahmed@mylaptop ~]# sudo yum install texlive
On Ubuntu
[ahmed@mylaptop ~]# apt-get install pandoc
[ahmed@mylaptop ~]# apt-get install texlive     

Converting markdown to pdf format

Create a sample markdown file.
[ahmed@mylaptop ~]$ mkdir markdown pdf
[ahmed@mylaptop ~]$ cat markdown/2016-08-15-firstmarkdownfile.md

# How To Configure Swappiness

Swappiness is a Linux kernel parameter that controls the relative weight given to swapping out runtime memory, as opposed to dropping pages from the system page cache. Swappiness can be set to values between 0 and 100 inclusive. A low value causes the kernel to avoid swapping, a higher value causes the kernel to try to use swap space. The default value is 60, and for most desktop systems, setting it to 100 may affect the overall performance, whereas setting it lower (even 0) may decrease response latency.

    Value                    Strategy
    vm.swappiness = 0        The kernel will swap only to avoid an out of memory condition. 
                                See the "VM Sysctl documentation".
    vm.swappiness = 1        Kernel version 3.5 and over, as well as kernel version 2.6.32-303 
                                and over: Minimum amount of swapping without disabling it entirely.
    vm.swappiness = 10        This value is sometimes recommended to improve performance 
                                when sufficient memory exists in a system.
    vm.swappiness = 60        The default value.
    vm.swappiness = 100     The kernel will swap aggressively.

With kernel version `3.5` and over, as well as kernel version `2.6.32-303` and over, it is likely better to use `1` for cases where `0` used to be optimal.
To temporarily set the swappiness in Linux, write the desired value (e.g. 10) to `/proc/sys/vm/swappiness` using the following command, running as root user.   

    #  Set the swappiness value as root
    echo 10 > /proc/sys/vm/swappiness

    #  Alternatively, run this 
    sysctl -w vm.swappiness=10

    #  Verify the change
    cat /proc/sys/vm/swappiness
    10

    #  Alternatively, verify the change
    sysctl vm.swappiness
    vm.swappiness = 10

To find the current swappiness settings, type:

    cat /proc/sys/vm/swappiness
    60

Swapiness can be a value from 0 to 100. 

1. Swappiness near 100 means that the operating system will swap often and usually, too soon. 
2. Although swap provides extra resources, RAM is much faster than swap space. Any time something is moved from RAM to swap, it slows down.

A swappiness value of 0 means that the operating will only rely on swap when it absolutely needs to. We can adjust the swappiness with the sysctl command:

    sysctl vm.swappiness=10
    vm.swappiness=10

If we check the system swappiness again, we can confirm that the setting was applied:

    cat /proc/sys/vm/swappiness
    10

To make changes permanent, you can add the setting to the /etc/sysctl.conf file:

    sudo nano /etc/sysctl.conf

Add the below line.

#  Search for the vm.swappiness setting.  Uncomment and change it as necessary.
vm.swappiness=10
This is our sample markdown file above. Now we will convert it to PDF using the below script.
[ahmed@mylaptop ~]$ cd pdf
[ahmed@mylaptop ~]$ cat create_pdf_from_md.sh
#!/bin/bash

for markdown_file in `ls ../markdown/201*`; 
do
    input_file=$markdown_file 
    output_file=`echo $markdown_file | cut -d'/' -f3 | cut -d'.' -f1`.pdf

    #echo $input_file
    #echo $output_file

    if [ -f $output_file ];
    then
        echo "File '$output_file' Already Converted to PDF."
    else
        pandoc -f markdown -r markdown -t pdf -w pdf $input_file -t latex -o $output_file -V geometry:"left=2.0cm, right=2.0cm,top=1.0cm, bottom=1.0cm" --latex-engine=xelatex
    fi
done;
Now lets execute the script.
[ahmed@mylaptop ~]$ sh create_pdf_from_md.sh
We are done. Here is how the file looks like.
pdf generate demo

Converting html to doc format

Creating a document file using pandoc
pandoc -f html -t docx -o chef-server-setup.docx http://zubayr.github.io/chef-server-setup/
This will create a doc file from html link.
Categories: HOWTOs, Others

Setup/Configuration Nagios XI on Centos6.6

August 17, 2016 Leave a comment
Nagios monitors your entire IT infrastructure to ensure systems, applications, services, and business processes are functioning properly. In the event of a failure, Nagios can alert technical staff of the problem, allowing them to begin remediation processes before outages affect business processes, end-users, or customers.
Intro from : http://ift.tt/2bvNQuk

Installation Nagios XI

Here is the link to [Nagios XI 5.2.9](http://ift.tt/2bl5aFJ
Installation for Nagios for most of the cases is quite staight forward.
tar xzf xi*.tar.gz
cd nagiosxi
./fullinstall
And the script will do all the hardward and we are done.
Once install is complete, visit the URL displayed to complete the install
Running Full Install
Running full install
Installation Complete
Installation Complete
Initial Configuration
Initial configuration done

Configuration

Checking if NRDS is working fine.

Go to the URL http://nagios-server/nrdp on the nagios server. [NRDP – Nagios Remote Data processor.]
submit a query
This is the response from the server.
Response
These submitted parameters will show up in the Unconfigured Objects page, which can be added directly.
Unconfigured Objects

Creating an inbound configuration.

For servers to send-in their monitoring data, we need to create tokens so that the servers can authenticate themself.

Creating inbound config.

NRDP Configuration
Inbound NRDP Configuration
NSCA Configuration (Optional – Only if you are using this – Not recommended to use this as this is very old and not very reliable)
Inbound NSCA Configuration

Creating NRDP Configuration for Windows and Linux.

Creating Config for Linux
Config for Linux
Selecting Token and add config name
setting up info
Configuration Complete
Config Complete
Now we are ready to setup the Clients.
Once the client starts sending results, if the host/service has not been configured yet it will be found in Unconfigured Objects and can easily be added to the monitoring config.

Monitoring using NRDS on Linux.

Config Complete
The following commands can be run as root on all clients that will use the new_linux_config config.
The install process will perform the following operations:
  • Install NRDS client
  • Add a nagios user and group
  • Add cron job to process checks
  • Download plugins from the NRDP server
There are 2 items you need to modify below, HOSTNAME and INTERVAL.
  • HOSTNAME – The name the client will send to the Nagios server as the host.
  • INTERVAL – The frequency in minutes that you want the checks to be run. (1-59)
Below are the commands.
cd /tmp
Get the tar file from the server.
wget -O new_linux_config.tar.gz "http:///nrdp/?cmd=nrdsgetclient&token=hardtoguess&configname=new_linux_config"
Unzip and install.
gunzip -c new_linux_config.tar.gz | tar xf -
cd clients
./installnrds [HOSTNAME] [INTERVAL_IN_MINUTES]
Command
./installnrds linux-server 5
This install the client and setup a crontab to send the parameters to the server.
When the client linux-server sends the data you will see the details on the Unconfigured Objects page.
Select the parameters and add it to the nagios monitoring.
It would look similar to the page below.
nrds_testing

Monitoring using NRDS on windows.

Download the executable from the link in the image
Config Complete
Agreement
Agreement
Configure Server Name and Interval to send the data
Config
Create ini file and and setup scheduler task
ini file
Install
Install
Once the client starts sending results, if the host/service has not been configured yet it will be found in Unconfigured Objects and can easily be added to the monitoring config. Example below.
testing
Select the parameters and add it to the nagios monitoring.
It would look similar to the page below.

Creating Groups for user to monitor specific servers.

Below are the steps to create a user groups.
  1. Create a contact file in /usr/local/nagios/etc/static
  2. Create a contactgroup file in /usr/local/nagios/etc/static
  3. Create a host file which binds the contact group.
  4. And restart nagios service.
What are we trying to do.
  1. On the nagios server we have 2 server which we monitor, A linux server and a windows server.
  2. We want to make sure that the windows server is monitored by the windows admin team.
  3. We will create a group and a user which can only see window server on the monitoring console.
  4. This will help create set of groups, who can monitor only their servers which they are responsible for.
Location of all the files on the server.
┌─[zahmed][localhost][~]
└─▪ cd /usr/local/nagios/etc/
┌─[zahmed][localhost][/usr/local/nagios/etc]
└─▪ ls
cgi.cfg               hosttemplates.cfg  servicedependencies.cfg
commands.cfg          import             serviceescalations.cfg
contactgroups.cfg     nagios.cfg         serviceextinfo.cfg
contacts.cfg          ndo2db.cfg         servicegroups.cfg
contacttemplates.cfg  ndomod.cfg         services
hostdependencies.cfg  nrpe.cfg           servicetemplates.cfg
hostescalations.cfg   nsca.cfg           static
hostextinfo.cfg       pnp                timeperiods.cfg
hostgroups.cfg        resource.cfg
hosts                 send_nsca.cfg
┌─[zahmed][localhost][/usr/local/nagios/etc]
└─▪
Creating a contact with windowsnagiosadmin user.
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ cat windows-server-contact.cfg
define contact {
        contact_name                            windowsnagiosadmin
        alias                                   Windows Nagios Administrator
        host_notification_period                nagiosadmin_notification_times
        service_notification_period             nagiosadmin_notification_times
        host_notification_options               d,u,r,f,s
        service_notification_options            w,u,c,r,f,s
        host_notification_commands              xi_host_notification_handler
        service_notification_commands           xi_service_notification_handler
        email                                   ahmed@gmail.com
        #use                                     xi_contact_generic
}
Create a contactgroup and add the above windowsnagiosadmin user as a member.
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ cat windows-server-contactgroup.cfg
define contactgroup {
    contactgroup_name                   windowsadmins
    alias                               Windows Nagios Admin Group
    members                             windowsnagiosadmin
}
Now finally create a host configuration which is tied to the windowsadmins contact group above.
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ cat nagios-test-windows.cfg
define host {
        host_name                       nagios-test-wındows
        use                             xiwizard_passive_host
        address                         nagios-test-wındows
        max_check_attempts              5
        check_interval                  5
        retry_interval                  1
        check_period                    xi_timeperiod_24x7
        contact_groups                 windowsadmins
        notification_interval           60
        notification_period             xi_timeperiod_24x7
        stalking_options                n
        icon_image                      passiveobject.png
        statusmap_image                 passiveobject.png
        _xiwizard                       passiveobject
        register                        1
        }
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪
Files in static directory.
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ ls -l
total 24
-rwxrwxr-x 1 apache nagios  661 Aug 12 11:27 windows-server-contact.cfg
-rwxrwxr-x 1 apache nagios  211 Aug 12 11:57 windows-server-contactgroup.cfg
-rwxrwxr-x 1 apache nagios  802 Aug 12 11:39 nagios-test-windows.cfg
-rwxrwxr-x 1 apache nagios  878 Jun 14 20:43 xiobjects.cfg
-rwxrwxr-x 1 apache nagios 4002 Jun 14 20:43 xitemplates.cfg
-rwxrwxr-x 1 apache nagios    0 Jun 14 20:43 xitest.cfg
-rwxr-xr-x 1 root   nagios  649 Aug 12 11:59 zahmedcontact.cfg
Check Nagios config.
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ sudo service nagios checkconfig
[sudo] password for zahmed:
Running configuration check...
 OK.
All OK, then restart nagios
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ sudo service nagios restart
Running configuration check...
Stopping nagios:. done.
Starting nagios: done.
Finally create a user on nagios which matches our configuration windowsnagiosadmin.
Creating a windowsnagiosadmin user.
windows_user
Host when we login as nagiosadmin
login
Hosts when we login as windowsnagiosadmin
loggedin

Installation and Configuring NSClient++ for Windows.

Download and install NSClient++ on the windows server. http://ift.tt/2bl4Vuh
First Installing NSClient++
install
Configure NSClient
Update the allowed_hosts and password. And make sure to use check_nt
config
Install Complete
complete
Check service is running
service check

Configuring on the nagios server.

We need to create couple of configurations for the first time a windows machine is setup. After that all we have to do is add the hosts configuration. Everything else will be the same. (Unless we change the password on few of the windows machine then we have to update / create new command configuration)
  1. Create a host configuration.
  2. Add services configuration which will define what we want to monitor.
  3. Create a command configuration.
First lets create a file new-windows-test.cfg in /usr/local/nagios/etc/static directory.
We will be adding the host and service configuration into the same file.
NOTE : check_command in the service definitions should be same as the command_name in commands configuration. Example: check_nt_test
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ cat new-windows-test.cfg
define host{
    use                    windows-server    ; Inherit default values from a Windows server template (make sure you keep this line!)
    host_name            winservertest
    alias                My Windows Server
    address                172.2.2.35
    max_check_attempts  10
    check_interval      5
    retry_interval      1
    check_period        24x7
    contacts            nagiosadmin
    notification_interval   30
    notification_period     24x7
    notification_options    d,r
    register                1
    }

define service{
    use                    generic-service
    host_name            winserver
    service_description    NSClient++ Version
    check_command        check_nt_test!CLIENTVERSION
    }

define service{
    use                    generic-service
    host_name            winserver
    service_description    Uptime
    check_command        check_nt_test!UPTIME
    }

define service{
    use                    generic-service
    host_name            winserver
    service_description    CPU Load
    check_command        check_nt_test!CPULOAD!-l 5,80,90
    }

define service{
    use                    generic-service
    host_name            winserver
    service_description    Memory Usage
    check_command        check_nt_test!MEMUSE!-w 80 -c 90
    }

define service{
    use                    generic-service
    host_name            winserver
    service_description    C:\ Drive Space
    check_command        check_nt_test!USEDDISKSPACE!-l c -w 80 -c 90
    }

define service{
    use                    generic-service
    host_name            winserver
    service_description    W3SVC
    check_command        check_nt_test!SERVICESTATE!-d SHOWALL -l W3SVC
    }

define service{
    use                    generic-service
    host_name            winserver
    service_description    Explorer
    check_command        check_nt_test!PROCSTATE!-d SHOWALL -l Explorer.exe
    }
First lets create a file new-windows-test-command.cfg, update the password -s below with the password we created on the windows machine. [Check image above]
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ cat new-windows-test-command.cfg
define command{
        command_name    check_nt_test
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s nagios123 -v $ARG1$ $ARG2$
        }
After we have configured new files.
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ ls -l new*
-rw-r--r-- 1 apache nagios 1301 Aug 15 11:07 new-windows-test.cfg
-rw-r--r-- 1 apache nagios  134 Aug 15 10:57 new-windows-test-command.cfg
Check if our configuration is fine.
┌─[zahmed][localhost][/usr/local/nagios/etc/static]
└─▪ sudo service nagios checkconfig
[sudo] password for zahmed:
Running configuration check...
 OK.
Great!!, we have not errors, now we can restart nagios.
┌─[zahmed][localhost][/usr/local/nagios/etc]
└─▪ sudo service nagios restart
Running configuration check...
Stopping nagios:. done.
Starting nagios: done.
Restart complete and we are done.

Checking the new host on the dashboard.

New host winservertest is added to the dashboard.
service check
We are receiving monitoring data as well.
service check
Performance data.
service check

from Blogger http://ift.tt/2bl5i8f
via IFTTT

Categories: Others Tags: ,
Follow

Get every new post delivered to your Inbox.