Posts Tagged ‘smtp’

Fix NetApp AutoSupport

November 20, 2015

I come across this issue too often. You need to fetch some information for the customer from the My AutoSupport web-site and can’t because the last AutoSupport message is from half a year ago.

Check AutoSupport State

When you list the AutoSupport history on the target system you see something similar to this:

# autosupport history show

autosupport

Mail Server Configuration

If AutoSupport is configured to use SMTP as in this case, then the first place to check is obviously the mail server. The most common cause of the issue is blocked relay.

There are two things you need to make sure are configured: NetApp controllers management IPs are whitelisted on the mail server and authentication is disabled.

To set this up on a Exchange server go to Exchange Management Console > Server Configuration > Hub Transport, select a Receive Connector (or create it if you don’t have one for whitelisting already), go to properties and add NetApp IPs on the network tab.

exchange.png

Then make sure to enable Externally Secured authentication type on the Authentication tab.

receiveconnector

Confirm AutoSupport is Working

To confirm that the issue is fixed send an AutoSupport message either from OnCommand System Manager or right from the console and make sure that status shows “sent-successfull”.

# options autosupport.doit Test

# autosupport history show

autosupport2

 

Advertisements

PowerShell script for disk space

November 3, 2011

I’ve written simple PowerShell script for monitoring of free space on one of our important volumes. As well as inserting it as plaint text below, for the sake of convenience I uploaded the script as a text file on FileDen file hosting service. Here is the link to the file.

$path = "F:\script\dspace.txt"
Clear-Content $path
$server = "SERVERNAME"
$recps = "qwe@contoso.com", "wer@contoso.com", "ert@contoso.com"
$sender = "alerts@contoso.com"
$user = "alerts"
$passw = "123456"
$thold = 3
$drives = Get-WmiObject -ComputerName $server Win32_LogicalDisk | `
Where-Object {$_.DriveType -eq 3}
$i = 0

echo "This message is to inform you that server $server is low on disk space.
Please carry out corrective actions. Find details below. `n" >> $path

foreach($drive in $drives) {
	$size_gb = $drive.size / 1GB
	$size_gb_fmt = "{0:N2}" -f $size_gb
	$free_gb = $drive.freespace / 1GB
	$free_gb_fmt = "{0:N2}" -f $free_gb
	$ID = $drive.DeviceID
	$pct = $free_gb / $size_gb * 100
	$pct_fmt = "{0:N0}" -f $pct

	if (($ID -eq "F:") -and ($free_gb -lt $thold)) {
		echo "Server Name: $server" >> $path
		echo "Drive Letter: $ID" >> $path
		echo "Drive Size: $size_gb_fmt GB" >> $path
		echo "Free Space: $free_gb_fmt GB" >> $path
		echo "Percent Free: $pct_fmt%" >> $path
		$i++
        }
}

if ($i -gt 0) {
	$smtpServer = "mail.contoso.com"
	$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
	$smtp.Credentials = New-Object System.Net.NetworkCredential($user, $passw)
	$msg = new-object Net.Mail.MailMessage
	$msg.From = $sender
	foreach ($recp in $recps) {
		$msg.To.Add($recp)
	}
	$subject = "Disk space on $server is under $thold GB"
	$msg.Subject = $subject
	foreach ($line in Get-Content $path) {
		$body += "$line `n"
	}
	$msg.Body = $body
	$smtp.Send($msg)
}

To run this script from scheduler just write another simple .bat file with following line inside:

powershell -command “& ‘.\dspace.ps1′”

Postfixadmin. Removing old mailboxes.

September 21, 2011

Our organization mail server hosts several domains with more than 750 mailboxes. We use commercial antispam and antivirus software. License value is calculated from the number of mailboxes. Therefore it’s important to keep mailbox database actual and remove unused accounts.

Mail server setup is based upon postfix mail server daemon and Postfixadmin web-based administration interface which uses MySQL to store configuration data. I wrote simple shell script to find and delete mailboxes which were not used for more than 1 year:

#!/bin/sh

YEAR=31536000
MYSQL="/usr/bin/mysql -D postfix -u postfix -ppassword -e"
DOMAIN=your.domain

cd /var/spool/vmail/$DOMAIN
for i in *; do
    MDATE=`stat --format=%y $i/cur`
    MUTDATE=`stat --format=%Y $i/cur`
    CTIME=`date +%s`
    if [ `expr $CTIME - $MUTDATE` -ge $YEAR ]; then
        echo "Removing $i@$DOMAIN mailbox. Last pop3 delivery was on $MDATE"
        $MYSQL "DELETE FROM alias WHERE address = '$i@$DOMAIN'"
        $MYSQL "DELETE FROM alias WHERE goto = '$i@$DOMAIN'"
        $MYSQL "DELETE FROM mailbox WHERE username = '$i@$DOMAIN'"
        /bin/rm -rf $i
    fi
done

Date comparison is pain in bash scripting. Idea here was to use Unix time to avoid separate comparison of year, month and day. Thank stat can output time in different formats. YEAR is 1 year in seconds.

Each time user receives his mail from mail server letters are moved from new to cur dir. After mail has been received postfix deletes letters from cur. This script determine if user hasn’t been receiving mail for more than 1 year by checking modification time of cur dir of his mailbox. Script removes metadata from MySQL database and actual maildir of old box.

Using this script I found and removed more than 250 abandoned mailboxes.