'On Error Resume Next
Const ForReading = 1
today = now()
Set objMessage = CreateObject("CDO.Message")
objMessage.From = "babu.dhinakaran@jda.com"
objMessage.To = "babu.dhinakaran@jda.com"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\filelist.txt", ForReading)
Do Until objTextFile.AtEndOfStream
folderspec = objTextFile.Readline
'Wscript.Echo "File in the Folder:" & folderspec
objMessage.Subject = folderspec
Agecount = 0
Set folder = objFSO.GetFolder(folderspec)
Set fc = folder.Files
For Each f1 in fc
file = f1.name
filespec = folderspec & file
Set file = objFSO.GetFile(filespec)
ShowDateCreated = file.DateCreated
'Wscript.Echo "FileName: " & filespec
'Wscript.Echo "ShowDateCreated:" & ShowDateCreated
difference = DateDiff("n",ShowDateCreated,today)
If difference > 30 Then
Agecount = Agecount + 1
End If
'Wscript.Echo "File Age in minutes is:" & difference
Next
'Wscript.Echo "Total file older than 30 minutes at: " & folderspec & " are:" & Agecount
'mailbody = "Total file older than 30 minutes at: " & folderspec & " are:" & Agecount
'objMessage.TextBody = mailbody
'Wscript.Echo "-----------------------------------------------"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "indiamailrelay.jda.corp.local"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
If Agecount > 0 Then
mailbody = "Total file older than 30 minutes at: " & folderspec & " are:" & Agecount
objMessage.TextBody = mailbody
objMessage.Send
'Wscript.Echo "Total file older than 30 minutes at: " & folderspec & " are:" & Agecount
End If
Loop
------------------------------------------------------------------------------------
The above code basically, check for a fileage > 30 minutes and send an email if it is true.
It uses a text file as a input to read folder path where files exists
eg:- c:\temp\
Note: Make sure to provide full path as said above, if provided c:\temp this will generate an error.
Here we are going to discuss about Operating system, Networking and open source tools issues.
Monday, November 7, 2011
Friday, September 16, 2011
diskinfo from the Domain using LDAP to query AD for Servers
on error resume next
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
'wscript.echo "defaultNamingContext (Domain Name System)" & strDNSDomain
' Use ADO to search Active Directory for all computers.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "ADs Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire domain.
strBase = ""
' Filter on computer objects with server operating system.
strFilter = "(&(objectCategory=computer)(operatingSystem=*server*))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "cn"
' Construct 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
Set adoRecordset = adoCommand.Execute
strComputerDN = Array()
'arrSortOut = Array()
' cnsd = Array()
Dim cnsdstring
counter = 0
'step = 0
count = 0
' Enumerate computer objects with server operating systems.
Do Until adoRecordset.EOF
ReDim Preserve strComputerDN(counter)
strComputerDN(counter) = adoRecordset.Fields("cn").value
'Wscript.Echo strComputerDN(counter)
adoRecordset.MoveNext
counter = counter + 1
Loop
'wscript.echo "defaultNamingContext" & strDNSDomain
'wscript.echo counter
'Clean up.
adoRecordset.Close
adoConnection.Close
Wscript.Echo "Disk Info"
for each strComputer in strComputerDN
'wscript.echo strComputer
cnsdstring = ""
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk where DriveType=3")
For Each objDisk in colDisks
ReDim Preserve cnsd(count)
cnsd(count) = objDisk.DeviceID
cnsdstring = cnsdstring &"," &cnsd(count)
count=count+1
'wscript.echo cnsd(count)
'wscript.echo objDisk.DeviceID
next
wscript.echo "" &strComputer &","&cnsdstring
count = 0
Next
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
'wscript.echo "defaultNamingContext (Domain Name System)" & strDNSDomain
' Use ADO to search Active Directory for all computers.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "ADs Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire domain.
strBase = "
' Filter on computer objects with server operating system.
strFilter = "(&(objectCategory=computer)(operatingSystem=*server*))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "cn"
' Construct 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
Set adoRecordset = adoCommand.Execute
strComputerDN = Array()
'arrSortOut = Array()
' cnsd = Array()
Dim cnsdstring
counter = 0
'step = 0
count = 0
' Enumerate computer objects with server operating systems.
Do Until adoRecordset.EOF
ReDim Preserve strComputerDN(counter)
strComputerDN(counter) = adoRecordset.Fields("cn").value
'Wscript.Echo strComputerDN(counter)
adoRecordset.MoveNext
counter = counter + 1
Loop
'wscript.echo "defaultNamingContext" & strDNSDomain
'wscript.echo counter
'Clean up.
adoRecordset.Close
adoConnection.Close
Wscript.Echo "Disk Info"
for each strComputer in strComputerDN
'wscript.echo strComputer
cnsdstring = ""
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk where DriveType=3")
For Each objDisk in colDisks
ReDim Preserve cnsd(count)
cnsd(count) = objDisk.DeviceID
cnsdstring = cnsdstring &"," &cnsd(count)
count=count+1
'wscript.echo cnsd(count)
'wscript.echo objDisk.DeviceID
next
wscript.echo "" &strComputer &","&cnsdstring
count = 0
Next
Tuesday, September 6, 2011
Linux using DBD::Sybase to access MSSQL
Recently, I made yet another attempt to get Perl to access Microsoft SQL Server using DBD. Usually, when I want to connect to a Microsoft SQL Server, it is from Perl on Windows. So I take the easy route and use DBD::ODBC and use an ODBC connection. This time though, I wanted to connect to Microsoft SQL Server 2000 from a Linux box. Having no ODBC to fall back on, I looked for native DBD driver of some sort.
It took me several hours of struggling to make it work. I almost gave up several times, so I am writing outline to help anyone else trying to accomplish this same task.
In the end, we will use the DBD::Sybase perl module from CPAN to access the Microsoft SQL Server. Before we can do that however, we must first compile the freetds library.Note: From now on I will refer to Microsoft SQL Server as SQL Server. Please do not confuse this with a generic sql server. We can all now pause to gripe about the lack of imagination in product naming at Microsoft.
Compiling Freetds
Download and compile freetds from http://www.freetds.org/.once you unzip and untar it, enter the directory and run:
./configure --prefix=/usr/local/freetds --with-tdsver=7.0makemake install
Configuring Freetds
Now we have the freetds compiled, but we still have configure it. This is the part that threw me off and is so different from other DBD drivers. The DBD::Sybase driver will ultimately be affected by the contents of the /usr/local/freetds/etc/freetds.conf file. If that file is not configured correctly, your DBD::Sybase connection will fail.
Okay, now that we have established there is a relationship between the freetds.conf file and the DBD::Sybase module, let's edit the freetds.conf file.
The strategic modifications I made to the freetds.conf file were:
1) uncomment the following lines and modify if necessary:
try server login = yestry domain login = no
Note: this forces the module to attempt a database login instead of a domain login. I could not get domain login to work, though I will admit I did not try very hard.
2) uncomment the following line and modify if necessary:
tds version = 7.0
This supposedly sets the default tds version to establish a connection with. I have only SQL Server 2000 servers, and they won't talk at any lower version. So I set it to 7.0. If for some reason you had older SQL Servers, you might leave it at the default 4.2.
3) create a server entry for my server sql1:
[sql1]
host = sql1
port = 1433
tds version = 8.0
[download]
Note: My server here is sql1. Ping sql1 worked, so I am sure I can resolve it using DNS. You can also specifcy an ip address instead of the host name. The sql1 in the brackets is just a descriptor. It could be 'superduperserver' and it would still work as long as my 'host =' is set correctly. I tried 'tds version 7.0' for my SQL Sever 2000 and it worked. Version 5.0 though resulted in an error. You might want to verify your SQL Server is listening on port 1433 with a 'netstat -a -n' run from the command line on the SQL Server.
At this point you can verify your configuration.
/usr/local/freetds/bin/tsql -S sql1 -U sqluser
You will then be prompted for a password and if everything is well, you will see a '1)' waiting for you to enter a command. If you can't get the 1) using tsql, I doubt your DBD::Sybase perl code is going to work. Please note that sqluser is not an Active Directory/Windows Domain user, but an SQL Server user.
Compiling DBD::Sybase
Now that we have the freetds library prerequisite for DBD::Sybase installed and configured, we can compile the DBD::Sybase perl module. Obtain it from http://www.cpan.org/ if you haven't already.
once you have untarred it and are in the directory, run:
export SYBASE=/usr/local/freetdsperl Makefile.PLmakemake install
Note: The export line is to let the compilation process know where to find the freetds libraries.Using DBD::Sybase
You are now ready to test your DBD::Sybase module.
#!/usr/bin/perluse DBI;$dsn = 'DBI:Sybase:server=sql1';my $dbh = DBI->connect($dsn, "sqluser", 'password');die "unable to connect to server $DBI::errstr" unless $dbh;$dbh->do("use mydatabase");$query = "SELECT * FROM MYTABLE";$sth = $dbh->prepare ($query) or die "prepare failed\n";$sth->execute( ) or die "unable to execute query $query error $DBI::errstr";$rows = $sth->rows ;print "$row rows returned by query\n";while ( @first = $sth->fetchrow_array ) { foreach $field (@first) { print "field: $field\n"; }}
Content extracted from: http://www.perlmonks.org/?node_id=392385
It took me several hours of struggling to make it work. I almost gave up several times, so I am writing outline to help anyone else trying to accomplish this same task.
In the end, we will use the DBD::Sybase perl module from CPAN to access the Microsoft SQL Server. Before we can do that however, we must first compile the freetds library.Note: From now on I will refer to Microsoft SQL Server as SQL Server. Please do not confuse this with a generic sql server. We can all now pause to gripe about the lack of imagination in product naming at Microsoft.
Compiling Freetds
Download and compile freetds from http://www.freetds.org/.once you unzip and untar it, enter the directory and run:
./configure --prefix=/usr/local/freetds --with-tdsver=7.0makemake install
Configuring Freetds
Now we have the freetds compiled, but we still have configure it. This is the part that threw me off and is so different from other DBD drivers. The DBD::Sybase driver will ultimately be affected by the contents of the /usr/local/freetds/etc/freetds.conf file. If that file is not configured correctly, your DBD::Sybase connection will fail.
Okay, now that we have established there is a relationship between the freetds.conf file and the DBD::Sybase module, let's edit the freetds.conf file.
The strategic modifications I made to the freetds.conf file were:
1) uncomment the following lines and modify if necessary:
try server login = yestry domain login = no
Note: this forces the module to attempt a database login instead of a domain login. I could not get domain login to work, though I will admit I did not try very hard.
2) uncomment the following line and modify if necessary:
tds version = 7.0
This supposedly sets the default tds version to establish a connection with. I have only SQL Server 2000 servers, and they won't talk at any lower version. So I set it to 7.0. If for some reason you had older SQL Servers, you might leave it at the default 4.2.
3) create a server entry for my server sql1:
[sql1]
host = sql1
port = 1433
tds version = 8.0
[download]
Note: My server here is sql1. Ping sql1 worked, so I am sure I can resolve it using DNS. You can also specifcy an ip address instead of the host name. The sql1 in the brackets is just a descriptor. It could be 'superduperserver' and it would still work as long as my 'host =' is set correctly. I tried 'tds version 7.0' for my SQL Sever 2000 and it worked. Version 5.0 though resulted in an error. You might want to verify your SQL Server is listening on port 1433 with a 'netstat -a -n' run from the command line on the SQL Server.
At this point you can verify your configuration.
/usr/local/freetds/bin/tsql -S sql1 -U sqluser
You will then be prompted for a password and if everything is well, you will see a '1)' waiting for you to enter a command. If you can't get the 1) using tsql, I doubt your DBD::Sybase perl code is going to work. Please note that sqluser is not an Active Directory/Windows Domain user, but an SQL Server user.
Compiling DBD::Sybase
Now that we have the freetds library prerequisite for DBD::Sybase installed and configured, we can compile the DBD::Sybase perl module. Obtain it from http://www.cpan.org/ if you haven't already.
once you have untarred it and are in the directory, run:
export SYBASE=/usr/local/freetdsperl Makefile.PLmakemake install
Note: The export line is to let the compilation process know where to find the freetds libraries.Using DBD::Sybase
You are now ready to test your DBD::Sybase module.
#!/usr/bin/perluse DBI;$dsn = 'DBI:Sybase:server=sql1';my $dbh = DBI->connect($dsn, "sqluser", 'password');die "unable to connect to server $DBI::errstr" unless $dbh;$dbh->do("use mydatabase");$query = "SELECT * FROM MYTABLE";$sth = $dbh->prepare ($query) or die "prepare failed\n";$sth->execute( ) or die "unable to execute query $query error $DBI::errstr";$rows = $sth->rows ;print "$row rows returned by query\n";while ( @first = $sth->fetchrow_array ) { foreach $field (@first) { print "field: $field\n"; }}
Content extracted from: http://www.perlmonks.org/?node_id=392385
Monday, August 8, 2011
How to Reset Nagiosadmin Password?
Login as a root user and execute the below command
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Incase of sudo user, execute the below command
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Incase of sudo user, execute the below command
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Friday, April 8, 2011
how to pass arguments for check_db in nagios
File Download
|
Description
|
Shell Script wrapper
| |
Compiled DbCheck Class
| |
DbCheck java source code
| |
JSAP java command line parser
|
Remote oracle database check using JDBC drivers. Supports custom SQL queries and regular expression match. Provides similar funcationality as sitescope Db monitor.
This plugin can check almost every aspect of oracle database, written in java for portability.
Compiled with JDK 1.5.0_06
Uses JSAP command line parser http://www.martiansoftware.com/jsap/
to compile : copy DbCheck.java JSAP-2.0a.jar in a directory, expand JSAP-2.0a.jar in the same directory using command jar xvf JSAP-2.0a.jar
Use : javac -cp .:com/martiansoftware/jsap/JSAP.* DbCheck.java
this should generate DbCheck.class file
Setup Nagios Environment:
Copy DbCheck.class, check_db to /usr/local/nagios/libexec
create /usr/local/nagios/libexec/lib directory
Copy JSAP-2.0a.jar, classes12.jar (Take from $ORACLE_HOME/jdbc/lib), sql files to /usr/local/nagios/libexec/lib directory
Nagios plugin to check output of a sql query, matched with a regular expression. Currently supports numeric data checks only.
--help
Print help message
-H
Hostname/ip address of database server.
-p
Listener port, default is 1521. (default: 1521)
-s
Oracle database SID.
-l
Oracle database user to connect.
-x
Oracle database user password.
-f
Full path of sql file to be executed.
-r
PERL style Regular Expression to match in SQL output. Check value must
be enclosed between (), should match only one field and must be enclosed
between single quotes. Example 'SYSTEM.*,.*,(.*)'
-w
Warning value for matched expression. Normally warning < critical value.
If your check want to alert when result < warning , set critical less
than warning
-c
Critical value for matched expression. Should be more than Warning
1. If not check behaviour is reversed, see warning help text above.
-L
Label for matched regex value i.e FieldName.
Usage: DbCheck --help -H -p -s -l -x -f -r -w -c -L
CHECK_NRPE: Received 0 bytes from daemon
Verify the check_nrpe error message
Just
for testing purpose, let us assume that you are execuing the following
check_nrpe command that displays the “CHECK_NRPE:
Received 0 bytes from daemon.” error message.
$ /usr/local/nagios/libexec/check_nrpe -H 192.168.1.20 -c check_disk -a 60 80 /dev/sdb1
CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.
If
you view the /var/log/messages on the remote host, (in the above example, that
is 192.168.1.20), you’ll see the nrpe error “Error: Request contained command arguments!”
as shown below, indicating that check_nrpe is not enabled to take the command
arguments.
$ tail -f /var/log/messages
Dec 5 11:11:52 dev-db xinetd[2536]: START: nrpe pid=24187 from=192.168.101.108
Dec 5 11:11:52 dev-db nrpe[24187]: Error: Request contained command arguments!
Dec 5 11:11:52 dev-db nrpe[24187]: Client request was invalid, bailing out...
Dec 5 11:11:52 dev-db xinetd[2536]: EXIT: nrpe status=0 pid=24187 duration=0(sec)
Enable check_nrpe command arguments
To
enable command arguments in NRPE, you should do the following two things
Verify the check_nrpe error message
Just
for testing purpose, let us assume that you are execuing the following
check_nrpe command that displays the “CHECK_NRPE:
Received 0 bytes from daemon.” error message.
CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.
If
you view the /var/log/messages on the remote host, (in the above example, that
is 192.168.1.20), you’ll see the nrpe error “Error: Request contained command arguments!”
as shown below, indicating that check_nrpe is not enabled to take the command
arguments.
Dec 5 11:11:52 dev-db xinetd[2536]: START: nrpe pid=24187 from=192.168.101.108
Dec 5 11:11:52 dev-db nrpe[24187]: Error: Request contained command arguments!
Dec 5 11:11:52 dev-db nrpe[24187]: Client request was invalid, bailing out...
Dec 5 11:11:52 dev-db xinetd[2536]: EXIT: nrpe status=0 pid=24187 duration=0(sec)
Enable check_nrpe command arguments
To
enable command arguments in NRPE, you should do the following two things
1.
Configure NRPE with –enable-command-args
Typically
when you install NRPE on the remote host, you’ll do
./configure without any arguments. To enable support for command arguments in
the NRPE daemon, you should install it with –enable-command-args as shown
below.
[remotehost]# tar xvfz nrpe-2.12.tar.gz
[remotehost]# cd nrpe-2.12
[remotehost]# ./configure --enable-command-args
[remotehost]# make all
[remotehost]# make install-plugin
[remotehost]# make install-daemon
[remotehost]# make install-daemon-config
[remotehost]# make install-xinetd
2.
Modify nrpe.cfg and set dont_blame_nrpe
Modify the /usr/local/nagios/etc/nrpe.cfg on the remote server
and set the dont_blame_nrpe directive to 1 as shown below.
$ /usr/local/nagios/etc/nrpe.cfg
dont_blame_nrpe=1 Execute check_nrpe with command
arguments
Typically
when you install NRPE on the remote host, you’ll do
./configure without any arguments. To enable support for command arguments in
the NRPE daemon, you should install it with –enable-command-args as shown
below.
[remotehost]# cd nrpe-2.12
[remotehost]# ./configure --enable-command-args
[remotehost]# make all
[remotehost]# make install-plugin
[remotehost]# make install-daemon
[remotehost]# make install-daemon-config
[remotehost]# make install-xinetd
2.
Modify nrpe.cfg and set dont_blame_nrpe
Modify the /usr/local/nagios/etc/nrpe.cfg on the remote server
and set the dont_blame_nrpe directive to 1 as shown below.
$ /usr/local/nagios/etc/nrpe.cfgdont_blame_nrpe=1
After the above two changes, if you execute the check_nrpe for this particular remote host, you’ll not see the error message anymore as shown below.
How to pass arguments to CHECK_NRPE?
$ /usr/local/nagios/libexec/check_nrpe -H 192.168.1.20 -c check_disk -a 60 80 /dev/sdb1
DISK OK - free space: / 111199 MB (92% inode=99%);| /=9319MB;101662;114370;0;127078
Security Warning
Enabling NRPE command line arguments is a security risk. If you
don’t know what you are doing, don’t enable this.
Probably by now you’ve already figured out that you can’t blame
NRPE if something goes wrong. After all you did set dont_blame_nrpe to 1.
DISK OK - free space: / 111199 MB (92% inode=99%);| /=9319MB;101662;114370;0;127078
Security Warning
Enabling NRPE command line arguments is a security risk. If you
don’t know what you are doing, don’t enable this.
Probably by now you’ve already figured out that you can’t blame
NRPE if something goes wrong. After all you did set dont_blame_nrpe to 1.
Monday, April 4, 2011
Traceroute shell script for linux/unix
Before you run the below script you need to save server list in /tmp/servlist. The below mentioned bash script you need to put in crontab to run as per the schedule. This script will send the traceroute whenever node/server is down. Please comment if this script is useful for you.
#!/bin/bash
#Author : Ranjith Kumar R
#Purpose : To send the traceroute whenever server/node is down.
#Version : V1.0
#Date :April 05, 2011
Trace="/bin/traceroute -I"
for i in `cat /tmp/servlist`
do
test=`fping $i | grep unreachable | awk '{print $1'}`
echo $test
if [ -z "$test" ]; then
sleep 1
else
$Trace $test | mail -s "$test is Down!!! Traceroute from $Hostname to $test" youremailid@domain.com &
fi
done
Subscribe to:
Posts (Atom)