Here we are going to discuss about Operating system, Networking and open source tools issues.
Thursday, April 17, 2014
Wednesday, April 16, 2014
Nagios : Add services into service group : Shell script
#!/bin/bash
#Author : Ranjith Kumar R
#Date : 16th April 2014
#Purpose : Add services into the nagios service group.
echo "Please enter service group name"
read svcgroup
while read server
do
servername=`echo $server | cut -d';' -f1`
OUTPUT=`find /usr/local/nagios -name "$servername"_DB.cfg | grep -i $servername`
RESULT=`echo $?`
if [ "$RESULT" -eq "0" ]; then
OUTPUT1=`cat $OUTPUT | grep -i "$svcgroup" | grep "service_description" | awk '{print $2}' > /tmp/svcgroup.txt`
RESULT1=`echo $?`
if [ "$RESULT1" -eq "0" ]; then
echo "success" > /dev/null
fi
fi
while read service
do
startlinenum=`grep -nr -A 2 -B 14 """$service""" "$OUTPUT" | grep "servicegroups" | cut -d'-' -f1 | head -1`
if [ "$startlinenum" == "" ]; then
continue
fi
format=`echo "$startlinenum"s/DBservices/DBservices,$svcgroup/`
sed "$format" $OUTPUT > "$OUTPUT".temp
mv "$OUTPUT".temp "$OUTPUT"
done < /tmp/svcgroup.txt
done < /usr/local/nagios/libexec/tools/devicelist
rm -rf /tmp/svcgroup.txt
#Author : Ranjith Kumar R
#Date : 16th April 2014
#Purpose : Add services into the nagios service group.
echo "Please enter service group name"
read svcgroup
while read server
do
servername=`echo $server | cut -d';' -f1`
OUTPUT=`find /usr/local/nagios -name "$servername"_DB.cfg | grep -i $servername`
RESULT=`echo $?`
if [ "$RESULT" -eq "0" ]; then
OUTPUT1=`cat $OUTPUT | grep -i "$svcgroup" | grep "service_description" | awk '{print $2}' > /tmp/svcgroup.txt`
RESULT1=`echo $?`
if [ "$RESULT1" -eq "0" ]; then
echo "success" > /dev/null
fi
fi
while read service
do
startlinenum=`grep -nr -A 2 -B 14 """$service""" "$OUTPUT" | grep "servicegroups" | cut -d'-' -f1 | head -1`
if [ "$startlinenum" == "" ]; then
continue
fi
format=`echo "$startlinenum"s/DBservices/DBservices,$svcgroup/`
sed "$format" $OUTPUT > "$OUTPUT".temp
mv "$OUTPUT".temp "$OUTPUT"
done < /tmp/svcgroup.txt
done < /usr/local/nagios/libexec/tools/devicelist
rm -rf /tmp/svcgroup.txt
Tuesday, April 15, 2014
To Send an e-mail for the active account in AD users to reset there Password every 14th, 7th and 1st day of password expiry or password age.
'Account used to run script needs read access to Domain.
'Any standard Domain User account should work.
'Set the following variables
MyDomain = "domain.com"
'MyDN = "OU=xyz Users,DC=domain,DC=com"
OutputFile = "C:\Passwordnotify\passAge.csv"
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
MyDN = strDNSDomain
'Wscript.Echo MyDN
'Do not modify below this line
Const SEC_IN_DAY = 86400
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Const ADS_SCOPE_SUBTREE = 2
Set objDomainNT = GetObject("WinNT://" & MyDomain)
intMaxPwdAge = objDomainNT.Get("MaxPasswordAge") / SEC_IN_DAY
'Wscript.Echo "Max password age:" & intMaxPwdAge
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, distinguishedName from 'LDAP://" & MyDN & _
"' Where objectClass='user' AND objectClass <> 'computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
'Set oFile=fso.GetFile(OutputFile)
'If Err.Number = 0 Then
' Set AFileStream = FSO.OpenTextFile(OutputFile,2)
'Else
Set AFileStream = FSO.CreateTextFile(OutputFile,2)
'End If
AFileStream.WriteLine "Name" & VbTab & "Password Status" & VbTab & "Last Change" & _
VbTab & "Expiration Date"
Do Until objRecordSet.EOF
If (InStr(objRecordSet.Fields("Name").Value, "SystemMailbox") = 1) Then
objRecordSet.MoveNext
Else
ldapStr = "LDAP://" & objRecordSet.Fields("distinguishedName").Value
'Wscript.Echo "Ldap String:" & ldapStr
Set objUserLDAP = GetObject(ldapStr)
intCurrentValue = objUserLDAP.Get("userAccountControl")
If intCurrentValue and ADS_UF_DONT_EXPIRE_PASSWD Then
'Do nothing
Else
dtmValue = objUserLDAP.PasswordLastChanged
'Wscript.Echo "Last Password Cahange:" & dtmValue
intTimeInterval = int(now - dtmValue)
If intTimeInterval >= intMaxPwdAge Then
PassExpStatus = "Expired"
Else
PassExpStatus = "Active"
IntTimeIntervalDiff = intMaxPwdAge - intTimeInterval
'Set a message string to on how to reset the password.
'Send an e-mail to reset the password for 14,7 and 1 day respectively.
mailbody = "Password expiry Notification" & VbNewline _
& "This email was auto generated by a Domain.COM exchange organization to alert you on your password expiry. Please follow one of the below procedures to change your password on time." & vbNewLine _
& "=============================instructions=====================" & vbNewLine _
& "The steps to change are as follows." & VbNewline _
& "Method1:Computer" & VbNewLine _
& "Step1: Once logged into the computer, press Ctrl+Alt+Del simultaneously(Ensure no programs are opened after logged in to computer)." & vbnewline _
& "Step2:Click on Change a Password." & VbNewline _
& "Step3: Enter the old password and type new password and confirm it again." & VbNewline _
& "Step4 :Click OK and logoff and login to the computer with the new password" & VbNewline & vbNewLine _
& "OR Method2: Webmail Step1:Login to webmail https://mail.domain.com/owa" & VbNewline _
& "Step2:In Outlook Web App, click Options > See All Options" & VbNewline _
& "Step3:click on Change your password Enter old password, new password and confirm it again" & VbNewline _
& "Step4:Click on Save Step5:Logout and login with the new password to webmail" & vbNewLine _
& "==========================end of details==================" & vbNewLine
If IntTimeIntervalDiff = 14 then
Set objMessage = CreateObject("CDO.Message")
objMessage.From = "noreply.PwdNotification@domain.com"
objMessage.To = objUserLDAP.mail
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 8181
objMessage.Configuration.Fields.Update
objMessage.Subject = "your windows password will expire in "& intTimeInterval & "days."
objMessage.TextBody = mailbody
objMessage.Send
End If
If intTimeIntervalDiff = 7 then
Set objMessage = CreateObject("CDO.Message")
objMessage.From = "noreply.PwdNotification@domain.com"
objMessage.To = objUserLDAP.mail
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 8181
objMessage.Configuration.Fields.Update
objMessage.Subject = "your windows password will expire in "& intTimeInterval & "days."
mailbody = str
objMessage.Send
End If
If intTimeIntervalDiff = 99 then
Set objMessage = CreateObject("CDO.Message")
objMessage.From = "noreply.PwdNotification@domain.com"
objMessage.To = objUserLDAP.mail
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 8181
objMessage.Configuration.Fields.Update
objMessage.Subject = "your windows password will expire in "& intTimeInterval & "days."
objMessage.TextBody = mailbody
objMessage.Send
End If
End If
PassLastChangeDate = DateValue(dtmValue)
PassExpDate = DateValue(dtmValue + intMaxPwdAge)
AFileStream.WriteLine objRecordSet.Fields("Name").Value & VbTab & PassExpStatus & _
VbTab & PassLastChangeDate & VbTab & PassExpDate &VbTab & objUserLDAP.mail &VbTab & intTimeIntervalDiff
'Wscript.Echo objUserLDAP.mail
End If
objRecordSet.MoveNext
End If
Loop
AFileStream.Close
'Any standard Domain User account should work.
'Set the following variables
MyDomain = "domain.com"
'MyDN = "OU=xyz Users,DC=domain,DC=com"
OutputFile = "C:\Passwordnotify\passAge.csv"
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
MyDN = strDNSDomain
'Wscript.Echo MyDN
'Do not modify below this line
Const SEC_IN_DAY = 86400
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Const ADS_SCOPE_SUBTREE = 2
Set objDomainNT = GetObject("WinNT://" & MyDomain)
intMaxPwdAge = objDomainNT.Get("MaxPasswordAge") / SEC_IN_DAY
'Wscript.Echo "Max password age:" & intMaxPwdAge
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, distinguishedName from 'LDAP://" & MyDN & _
"' Where objectClass='user' AND objectClass <> 'computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
'Set oFile=fso.GetFile(OutputFile)
'If Err.Number = 0 Then
' Set AFileStream = FSO.OpenTextFile(OutputFile,2)
'Else
Set AFileStream = FSO.CreateTextFile(OutputFile,2)
'End If
AFileStream.WriteLine "Name" & VbTab & "Password Status" & VbTab & "Last Change" & _
VbTab & "Expiration Date"
Do Until objRecordSet.EOF
If (InStr(objRecordSet.Fields("Name").Value, "SystemMailbox") = 1) Then
objRecordSet.MoveNext
Else
ldapStr = "LDAP://" & objRecordSet.Fields("distinguishedName").Value
'Wscript.Echo "Ldap String:" & ldapStr
Set objUserLDAP = GetObject(ldapStr)
intCurrentValue = objUserLDAP.Get("userAccountControl")
If intCurrentValue and ADS_UF_DONT_EXPIRE_PASSWD Then
'Do nothing
Else
dtmValue = objUserLDAP.PasswordLastChanged
'Wscript.Echo "Last Password Cahange:" & dtmValue
intTimeInterval = int(now - dtmValue)
If intTimeInterval >= intMaxPwdAge Then
PassExpStatus = "Expired"
Else
PassExpStatus = "Active"
IntTimeIntervalDiff = intMaxPwdAge - intTimeInterval
'Set a message string to on how to reset the password.
'Send an e-mail to reset the password for 14,7 and 1 day respectively.
mailbody = "Password expiry Notification" & VbNewline _
& "This email was auto generated by a Domain.COM exchange organization to alert you on your password expiry. Please follow one of the below procedures to change your password on time." & vbNewLine _
& "=============================instructions=====================" & vbNewLine _
& "The steps to change are as follows." & VbNewline _
& "Method1:Computer" & VbNewLine _
& "Step1: Once logged into the computer, press Ctrl+Alt+Del simultaneously(Ensure no programs are opened after logged in to computer)." & vbnewline _
& "Step2:Click on Change a Password." & VbNewline _
& "Step3: Enter the old password and type new password and confirm it again." & VbNewline _
& "Step4 :Click OK and logoff and login to the computer with the new password" & VbNewline & vbNewLine _
& "OR Method2: Webmail Step1:Login to webmail https://mail.domain.com/owa" & VbNewline _
& "Step2:In Outlook Web App, click Options > See All Options" & VbNewline _
& "Step3:click on Change your password Enter old password, new password and confirm it again" & VbNewline _
& "Step4:Click on Save Step5:Logout and login with the new password to webmail" & vbNewLine _
& "==========================end of details==================" & vbNewLine
If IntTimeIntervalDiff = 14 then
Set objMessage = CreateObject("CDO.Message")
objMessage.From = "noreply.PwdNotification@domain.com"
objMessage.To = objUserLDAP.mail
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 8181
objMessage.Configuration.Fields.Update
objMessage.Subject = "your windows password will expire in "& intTimeInterval & "days."
objMessage.TextBody = mailbody
objMessage.Send
End If
If intTimeIntervalDiff = 7 then
Set objMessage = CreateObject("CDO.Message")
objMessage.From = "noreply.PwdNotification@domain.com"
objMessage.To = objUserLDAP.mail
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 8181
objMessage.Configuration.Fields.Update
objMessage.Subject = "your windows password will expire in "& intTimeInterval & "days."
mailbody = str
objMessage.Send
End If
If intTimeIntervalDiff = 99 then
Set objMessage = CreateObject("CDO.Message")
objMessage.From = "noreply.PwdNotification@domain.com"
objMessage.To = objUserLDAP.mail
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 8181
objMessage.Configuration.Fields.Update
objMessage.Subject = "your windows password will expire in "& intTimeInterval & "days."
objMessage.TextBody = mailbody
objMessage.Send
End If
End If
PassLastChangeDate = DateValue(dtmValue)
PassExpDate = DateValue(dtmValue + intMaxPwdAge)
AFileStream.WriteLine objRecordSet.Fields("Name").Value & VbTab & PassExpStatus & _
VbTab & PassLastChangeDate & VbTab & PassExpDate &VbTab & objUserLDAP.mail &VbTab & intTimeIntervalDiff
'Wscript.Echo objUserLDAP.mail
End If
objRecordSet.MoveNext
End If
Loop
AFileStream.Close
Subscribe to:
Posts (Atom)