Search Windows and Linux Networking

Thursday, December 22, 2011

VBScript for Map share folder as Z: drive

VBScript for Map share folder as Z: drive 


'VBScript to Map folder as Z: Drive
Option Explicit
Dim objNetwork

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "Z:" , "\\Server.domainname.com\Share\"

Friday, December 9, 2011

Step by Step How to: Uninstalling Zabbix Agent from Windows system.

Step by Step How to: Uninstalling Zabbix Agent from Windows system.

Suppose you have installed Zabbix Agent in C:\Program Files\Zabbix with following method :-

Echo Server=192.168.73.142 > "c:\Program Files\zabbix\zabbix_agentd.conf"
Echo Hostname=%COMPUTERNAME% >> "c:\Program Files\zabbix\zabbix_agentd.conf"
"C:\Program Files\zabbix\zabbix_agentd.exe" -c "c:\Program Files\zabbix\zabbix_agentd.conf" –i
"C:\Program Files\zabbix\zabbix_agentd.exe" -c "c:\Program Files\zabbix\zabbix_agentd.conf" –s


And you want to uninstall it now to do fire the following command from command prompt:

Note:- It is always good option to backup our configuration file want to use later.

C:\Program Files\Zabbix>zabbix_agentd.exe -x -c"C:\Program Files\Zabbix\zabbix_agentd.Conf"
C:\Program Files\Zabbix>zabbix_agentd.exe -d -c"C:\Program Files\Zabbix\zabbix_agentd.Conf"
rmdir /s "C:\Program Files\Zabbix"


This will uninstall windows zabbix agnet from your system. 1st command stop zabbix agent service , 2nd uninstalled zabbix agent and last one do cleanup by deleting Zabbix directory with all constant from it. 

Thursday, December 8, 2011

Using Split Function in VBScript

Using Split Function in VBScript to get needed value

'Using Split Function with delimited with ://

Dim strOutPut ,i, strMngrDn
Dim strValue

strOutPut = "LDAP://cn=Sandeep Kapadane,OU=Pune,DC=Domainname,DC=com"
strValue = Split(strOutPut,"://")

For i = 0 to Ubound(strValue)
    strmngrDn=strValue(1)
Next
Msgbox strMngrDN


OUT PUT OF strMngrDN will be:-
cn=Sandeep Kapadane,OU=Pune,DC=Domainname,DC=com



Tuesday, December 6, 2011

Excel Function to split text from one cell to other two cells

Excel Function (formula) to split text from one cell to other two Cells

Suppose you have excel file with User name in same cell like shown in following screen shot.


and If you want to split cell in other column cell for First name and Last Name.Then write the function MID

=MID(A2,1,SEARCH(" ",A2)) 

To get First Name of (Sandeep Kapadane) result will be Sandeep.

And to get Last name in other cell then write the function as:-

=MID(A2,SEARCH(" ",A2)+1,20)

To get Last Name of (Sandeep Kapadane) result will be Kapadane

Now drag the formula to apply to all you result will be look like




Friday, December 2, 2011

Simple C program asking user to press ENTER Key and ignore other all keys before continue

Simple C program asking user to press ENTER Key and ignore other keys before continue

 /* Simple program asking user to press ENTER Key and ignore other */
/* Author: Sandeep           Date: 1 DEC 2011 */

#include<stdio.h>
#include<conio.h>
main()
{  char name[80];
   printf("Enter your Name:");
   scanf("%s",&name);
   printf("\nPress \"ENTER\" Key to Continue...");
  
   while(getch()!=0x0d);   /* This is the statement  checking input key with value 0x0d hex value of Enter */
  
   printf("\nHello %s how are you?",name);
   printf("\nPress Any key to Exit");
   getch();
   return(0);
}

VBScript for Search for all users in Windows Active Directory and export it in to well formatted Excel file

Search for all users in Windows Active Directory and export it in to well formatted  Excel file using VBScript.

If Your boss want all users Email address in excel file from you and your Active Directory having more than 50 to 100 user then it is boring job to type or copy and pest all users details in excel file to do job easy write VBScript file that do what you want within 3 to 5 min. and your boss also happy on your work for quick response. so if  you want t  export active directory user full name and email address in to MS-Excel file copy it into text file and save it as ADUserInExcel.vbs.

Option Explicit
Dim adocommand, adoconnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN , strGivenNAme ,strSN, strmail
Dim objExcel, objwb, objrange, x

Set objExcel = createObject("Excel.Application")
set objwb = objExcel.Workbooks.add
set objwb = objExcel.activeWorkBook.Worksheets(1)
objwb.Name = "User Information "

ObjExcel.Visible = True
objwb.Activate
objwb.Cells(1,1).Value = "First Name"
objwb.Cells(1,2).value = "Last Name"
objwb.Cells(1,3).value = "Dispaly Name"
objwb.Cells(1,4).value = "Login Name"
objwb.Cells(1,5).value = "Email Address"
set objrange = objExcel.Range("A1","E1")
objRange.Interior.ColorIndex = 15
objRange.font.Bold = True

x= 2


'Setup ADO Objects.
Set adocommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOobject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory Domain
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"

'Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,cn,givenName,sn,mail"

'Constuct the LDAP syntax query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adocommand.commandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("TimeOut") = 30
adoCommand.properties("Cache Results") = False

' Run the query

Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
  ' Retrieve values and display.
   strName = adoRecordset.Fields("sAMAccountName").Value
   strCN = adoRecordset.Fields("cn").Value
   strGivenName = adoRecordset.Fields("givenName")
   strSN = adoRecordset.Fields("sn").Value
   strmail = adoRecordset.Fields("mail").Value
  
   ' Write data in Excel file

   objwb.Cells(x,1).Value = strGivenName
   objwb.Cells(x,2).value = strSN
   objwb.Cells(x,3).value = strCN
   objwb.Cells(x,4).value = strName
   objwb.Cells(x,5).value = strmail

   'Move to the Next Record in the recordset.
   adoRecordSet.MoveNext
   x = x + 1
Loop

'autofit the output
 Set objRange = objwb.UsedRange
 objRange.EntireColumn.Autofit()


'Clean up.
adoRecordSet.Close
adoConnection.Close

' Display Massage All Done

MsgBox "Done"

It will open excel file and write all user information in to excel file the format it. Time Saving Job.:-)

Tuesday, November 29, 2011

Windows Active directory integration with Nagios using LDAP and assign different permission to users in Nagios

Active directory integration with Nagios using LDAP and assign different permission to users in Nagios

To integrate Active directory for user Authentication for nagios front end we required to make changes in httpd.conf  and cgi.cfg file before that we required one normal user in active directory to access and bind with windows active directory.  ldap module for apache by default it installed and enabled.

Suppose:- 
  1. we have windows Active Directory domain domainname.com.
  2. we have created on normal user in active directory as nagios with password P@55w0rd and password set as never expire. 
  3. we want to give three different user sandeep , atul  and ramesh at Pune organization unit in active directory  with different levels of permission like full access to all host, services, command , limited access to only services and command,and read only access.

Integrate Active directory with ldap module in apache for nagios:-

check if ldap module in installed and enabled in apache by cat command

# cat /etc/httpd/conf/httpd.conf | grep ldap
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so


(If you see result as above then in enabled. and if not see anything then may be ldap modue not installed in your system)

write the directive in httpd.conf file to active directory configuration information.

# vi /etc/httpd/conf/httpd.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    AuthBasicProvider ldap
    AuthType Basic
    AuthzLDAPAuthoritative off
    AuthName "Active Directory Login"
    AuthLDAPURL "ldap://192.168.100.1:3268/dc=domainname,dc=com?sAMAccountName?sub" NONE
    AuthLDAPBindDN "nagios@domainname.com"
    AuthLDAPBindPassword "P@55w0rd"

    require ldap-user "CN=Atul Chaudhari,OU=Pune,DC=domainname,DC=com"
    require ldap-user "CN=Sandeep Kapadane,OU=Pune,DC=domainname,DC=com"
   require ldap-user "CN=Ramesh Jadhav,OU=Pune,DC=domainname,DC=com"

</Directory>

Now restart nagios and httpd conft for changes take effect.
# service nagios restart
# service httpd restart

Now try to access nagios in your browser when it ask for authentication give Active directory user credential that you just mention in httpd.conf file. it will allow you login into nagios but you don't have permission to see any host or service or configuration information. as shown in screenshot



for that you have to make some changes in cgi.cfg file for user permission.
(note that user name are case sensitive for permission for eg you have to use same case that are given in this file for authenticating other wise it not show you any host, services or command )
there are diffrent set of permission in cgi file as :-
  1. SYSTEM/PROCESS INFORMATION ACCESS.
  2. CONFIGURATION INFORMATION ACCESS.
  3. SYSTEM/PROCESS COMMAND ACCESS.
  4. GLOBAL HOST/SERVICE VIEW ACCESS.
  5. GLOBAL HOST/SERVICE COMMAND ACCESS.
  6. READ-ONLY USERS
just add user login name for permission do you want. 

Set Permission to users:-

# vi /etc/nagios/cgi.cfg

 # SYSTEM/PROCESS COMMAND ACCESS
authorized_for_system_commands=nagiosadmin,sandeepk
# GLOBAL HOST/SERVICE VIEW ACCESS
authorized_for_all_services=nagiosadmin,sandeepk,atulc,rameshj
authorized_for_all_hosts=nagiosadmin,sandeepk,atulc,rameshj
# GLOBAL HOST/SERVICE COMMAND ACCESS
authorized_for_all_service_commands=nagiosadmin,sandeepk,atulc
authorized_for_all_host_commands=nagiosadmin,sandeepk
# READ-ONLY USERS
authorized_for_read_only=rameshj


Now restart nagios and httpd conft for changes take effect.
# service nagios restart
# service httpd restart

Now as per cgi configuration file different user get different set for permission in nagios front end. 

Wednesday, November 23, 2011

Quick overview Nagios (Open Source Monitoring system)


Nagios Documentation
================================================================
Nagios Server Basic information:-
================================================================
Nagios Binaries: -/opt/nagios
Nagios server Configuration: - /etc/Nagios
Nagios data: /var/Nagios
Nagios plugins: - /opt/nagios/plugins/
User for Nagios : Nagios
Nagios user password: Nagios
Nagios group: nagioscmd
================================================================
Configuration files:-
================================================================
/etc/nagios/hosts.cfg :-  File to define host
/etc/nagios/services.cfg:- File to define services
/etc/nagios/hostgroups.cfg:- File to define host groups  or add host in to group
/etc/nagios/servicegroups.cfg:- File to define service group or add service in to group
/etc/nagios/contacts.cfg:- File to define contact and contact group
/etc/nagios/service_dependencies.cfg:- file to define Service dependencies
/etc/nagios/escalationservices.cfg:- File to define service escalation template
/etc/nagios/escalationhost.cfg:- File to define host escalation template
/etc/nagios/serviceescalation/:-  Directory  to define service escalation
/etc/nagios/hostescalation/ :- Directory  to define host escalation
/etc/nagios/notification/notifications.cfg : File to define notification command
===================================================================
Adding new host for monitoring
===================================================================
  1. Two templates are created for Servers and network devices as core-server for server and core-network for network devices. 
  2. To add new host in Nagios we required host name and IP address of system.
  3. To add host for monitoring we have to modify and append /etc/nagios/hosts.cfg  at the bottom of the file define host information a:-
 define host{
        use                                 core-server
        host_name                 sandeep.domainname.com
        alias                               sandeep
        address                        192.168.1.115
         parents                        Router_Pune
        statusmap_image     win40.gd2
}






=====================================================================
Add new host group or adding host in to group.
=====================================================================
we have to modify and append /etc/nagios/hostgroups.cfg this file when we required to add new host group  or to add other group into other host group or to add host in to existing group.

define hostgroup{
hostgroup_name             All_Server
alias                                All_Server
hostgroup_members      Mumbai_Win_Server,Pune_Win_Server
members                      Sandeep.domainname.com,Linux05.domainname.com
        }
define hostgroup{
 hostgroup_name            Mumbai_Win_Server
alias                                Mumbai_Win_Server
members                         File_Server01.domainname.com,AD_Pri.domainname.com
}



========================================================================
Add services in to Nagios for monitoring.
========================================================================
  1. We have to modify or append /etc/nagios/services.cfg file for adding new services in to nagios or monitoring services for the host.
  2. Created templates for comman setting for services and latter use that template for monitoring services and adding host information to monitor services.
         For example:- we have created one common template as services for all services and latter we create new separate template for each service and then use that template and add host by separated by " , "  .

define service{
        name                              services
       active_checks_enabled             1
        passive_checks_enabled            1
        parallelize_check                 1
        obsess_over_service               1
        check_freshness                   0
        notifications_enabled             1
        event_handler_enabled             1
        flap_detection_enabled            1
        failure_prediction_enabled        1
        process_perf_data                 1
        retain_status_information         1
        retain_nonstatus_information      1
        is_volatile                       0
        check_period                      24x7
        max_check_attempts                3
        normal_check_interval             10
        retry_check_interval              2
        contact_groups                    admins
        notification_options              w,u,c,r
#        notification_interval            60
        notification_period               24x7
         register                         0
        }



For example monitoring ping for all host:-

 define service{
        use                             services,graphed-service,srv-pnp
        name                            ping
        check_command                   check_ping!1000.0,20%!2000.0,60%
        register                        0
        }
define service{
        use                             ping
        service_description             PING
        contact_groups                 admins
        hostgroup_name                  all_hosts
        }


One more example  for monitoring C drive :-

define service{
        use                             services
        name                            Disk space on c
        check_command                   check_nt!USEDDISKSPACE!-l c -w 80 -c 90
        register                       0
        }

define service{
        use                             Disk space on c
        service_description             C: Drive Space
       host_name         File_Server01.domainname.com, AD_Pri.domainname.com, Sandeep.domainname.com
#        hostgroup_name                  Domain Controllers
}






========================================================================
Add Service group in to Nagios.
========================================================================
To add service group we have to modify or append  /etc/nagios/servicegroups.cfg file . Service group are same as host group only instead of hostgroup_name . We have to use servicegroup_name. and one more thing to conceder is that when adding member syntax for this is < hostname,service_description>   

define servicegroup{
        servicegroup_name          dns-server
        alias                   DNS Servers
        members                 DC-01.domainname.com,Dns,DC01-MUMBAI.domainname.com,Dns,
}             

define servicegroup{
        servicegroup_name       C: Drive
        alias                   C: Drive
        members                 File_Server01.domainname.com,C: Drive Space,AD_Pri.domainname.com,C: Drive Space
}


========================================================================
Create new contact or contact group in to Nagios.
=========================================================================
We define contact or contact group in nagios. by modify or append /etc/nagios/contacts.cfg file.

define contact{
        contact_name            sandeep
        use                             generic-contact
        alias                           sandeep kapadane
        email                          sandeepk@email.com
        }
define contact{
        contact_name             yourname
        use                             generic-contact
        alias                           Your Name
        email                          yourname@email.com
        }

To create contact group same like servicegroup_name and hostgroup_name:-

define contactgroup{
        contactgroup_name     IT_Team_Pune
        alias                              IT Team Pune Administrators
        members                      sandeep,yourname
        }


========================================================================
Configure Service dependencies in  Nagios.
========================================================================
We have to modify or append  /etc/nagios/service_dependencies.cfg  for configure service dependences in nagios.

define servicedependency{
        host_name                                              File_Server01.domainname.com
        service_description                             NSClient++ Version
        dependent_host_name                     File_Server01.domainname.com
        dependent_service_description     UP TIME ,C: Drive Space,CPU Load,Memory Usage,Server Service,DNS Server Service
        notification_failure_criteria            o,c,w,u,p
        execution_failure_criteria              n
        }


define servicedependency{
        host_name                                              File_Server01.domainname.com
        service_description                            
UP TIME
        dependent_host_name                     File_Server01.domainname.com
        dependent_service_description     C: Drive Space,CPU Load,Memory Usage,Server Service,DNS Server Service
        notification_failure_criteria            o,c,w,u,p
        execution_failure_criteria              n
        }




=========================================================================
Define service escalation template
=========================================================================
Service escalation template will define in /etc/nagios/escalationservices.cfg file  latter we use this template for every service escalation .

# First three notification sent to every 60 min interval (one mail per 1hr in a day )
define serviceescalation{
        name                    1stnotification
        first_notification      1
        last_notification       3
        notification_interval   60
        register                        0
        }
# After 3rd notification 4th and 5th every 300 min (one mail per 5hr )
define serviceescalation{
        name                    2ndnotification
        first_notification      4
        last_notification       5
        notification_interval   300
        register                        0
        }
# After 5th notification 6th and 7th notification every 12 hr 
define serviceescalation{
        name                    3rdnotification
        first_notification      6
        last_notification       7
        notification_interval   720
        register                        0
        }
# After 7th notification 8th to 14th notification  every 24hr (one mail per day)
define serviceescalation{
        name                    4thnotification
        first_notification      8
        last_notification       14
        notification_interval   1440
        register                        0
        } 
# After 14th notification one mail every 7200 min (one mail per week) till fix the problem
define serviceescalation{

       name                    5thnotification
        first_notification      15

        last_notification       0

        notification_interval   7200
        register                        0

        }         




=====================================================================
Define host escalation template
======================================================================
Host escalation template define in file /etc/nagios/escalationhost.cfg and it same as service escalation only we have to change serviceeescalation with hostescalation for example:-
define hostescalation{
        name                         1stnotification
        first_notification       1
        last_notification        3
        notification_interval   60
        register                        0
        }

define hostescalation{
        name                    2ndnotification
        first_notification      4
        last_notification       5
        notification_interval   300
        register                0
        }



========================================================================
Define service escalation
========================================================================
To define service escalation for services we need to create new file for each services in /etc/nagios/serviceescalation/ directory with file extension with .cfg file for example service escalation for ping service we have to create new file name as ping.cfg and add notification option and contact name.
Ping.cfg”-

# For Defining service escalation  nagios required at list host_name And/or hostgroup_name , contacts and/or contact_groups and service_description  along with our template :- 

define serviceescalation{
        use                     1stnotification
#       host_name               sandeep.domainname.com
        hostgroup_name          all_hosts
        service_description     PING
#       contact_groups          admins
        contacts                sandeep
        }

define serviceescalation{
        use                     2ndnotification
#       host_name               sandeep.domainname.com
        hostgroup_name          all_hosts
        service_description     PING
#       contact_groups          admins
        contacts                sandeep,yourname
        }

define serviceescalation{
        use                     3rdnotification
#       host_name               sandeep.domainname.com
        hostgroup_name          all_hosts
        service_description     PING
#       contact_groups          admins
        contacts                sandeep,yourname,help
        }

define serviceescalation{
        use                     4thnotification
#       host_name               sandeep.domainname.com
        hostgroup_name          all_hosts
        service_description     PING
#       contact_groups          admins
        contacts                sandeep,yourname,help
        }

define serviceescalation{
        use                     5thnotification
#       host_name               sandeep.domainname.com
        hostgroup_name          all_hosts
        service_description     PING
#       contact_groups          admins
        contacts                sandeep,yourname,help
        }



========================================================================
Define host escalation
========================================================================
Configuring host escalation is same as service escalation just we have to create new file in /etc/nagios/hostescalation/ directory. For example host escallaion for all_host group

# For Defining host escalation  nagios required at list host_name And/or hostgroup_name , contacts and/or contact_groups along with our template   :- 

define hostescalation{
        use                     1stnotification
#       host_name               sandeep.domainname.com
        hostgroup_name          all_hosts
#       contact_groups          admins
        contacts                sandeep
        }