Saturday, October 24, 2009

script for fmadm alerting

source: http://prefetch.net/code/fmadmnotifier

From above site I found the following script
#!/bin/bash
#
# Program: E-mail fault manager errors
#
# Author: Matty < matty91 at gmail dot com >
#
# Current Version: 1.1
#
# Revision History:
#
# Version 1.1
# Avoid the use of temporary files -- Michael Shon
#
# Version 1.0
# Initial Release
#
# Last Updated: 08-18-2006
#
# Purpose:
# Fmadm.sh queries the fault manager to see if errors have been
# generated. If an error is detected, the script will email the
# admininstrator defined in the ADMIN vairable with the error
# details.
#
# License:
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Installation:
# Copy the shell script to a suitable location
#
# Usage:
# To check for events once per hour, add a cron job similar to the following:
#
# $ crontab -l | grep fmadmnotifier.sh
# 0 * * * * /etc/scripts/fmadmnotifier.sh
#

PATH=/usr/bin:/sbin:/usr/sbin:/usr/sfw/bin

# Who to E-mail with new updates
ADMIN="root"

# Location of binaries
AWK=$(which awk)
FMADM=$(which fmadm)
HOSTNAME=$(which hostname)
MAIL=$(which mailx)
MKTEMP=$(which mktemp)

# Check to make sure the mail binary exists
if [ ! -f ${MAIL} ]
then
echo "Cannot find ${MAIL}"
exit 1
fi

# Check to make sure the fmadm utility exists
if [ ! -f ${FMADM} ]
then
echo "Cannot find ${FMADM}"
exit 1
fi

# Verify that mktemp exists
if [ ! -f ${MKTEMP} ]
then
echo "Cannot find ${MKTEMP}"
exit 1
fi

# Run fmadm faulty to check for hardware errors
FMADMOUTPUT=$(${FMADM} faulty | ${AWK} '$0 !~ /STATE/ && $0 !~ /^----/ { print $0 }')

if [ -n "${FMADMOUTPUT}" ]
then
(
echo "The fault manager detected a problem with the system hardware."
echo "The fmadm and fmdump utilities can be run to retrieve additional"
echo "details on the faults and recommended next course of action. "

echo ""
echo "fmadm faulty output:"
echo ""

${FMADM} faulty
echo ""
) | ${MAIL} -s "Hardware fault on $($HOSTNAME)" ${ADMIN}
fi

And some fmadm details:
The fmadm utilities "config" option can be used to view the list of diagnosis engines and agents that are active on a system:
i $ fmadm config
MODULE cpumem-retire disk-transport eft fmd-self-diagnosis io-retire snmp-trapgen sysevent-transport syslog-msgs zfs-diagnosis zfs-retire VERSION 1.1 1.0 1.16 1.0 2.0 1.0 1.0 1.0 1.0 1.0 STATUS active active active active active active active active active active DESCRIPTION CPU/Memory Retire Agent Disk Transport Agent eft diagnosis engine Fault Manager Self-Diagnosis I/O Retire Agent SNMP Trap Generation Agent SysEvent Transport Agent Syslog Messaging Agent ZFS Diagnosis Engine ZFS Retire Agent Fault manager logs
· The fault manager maintains two log files: ­ The error log contains a list of errors events that have been sent to the fault manager daemon ­ The fault log contains a list of problems that have been diagnosed and repaired · The fault log can be viewed by running fmdump:
$ fmdump · The error log can be viewed with fmdump's "-e" option:
$ fmdump -e · Fmdump also has a "-u" option to limit the output to a specific UUID, a "-T" option to display events that occurred during a specific timeframe, and "-v" and "-V" options to display verbose output Viewing faulty components

Monday, October 5, 2009

zpool monitoring

The second script checks the current state of the zpools, looking for degraded arrays (caused by failed drives), unavailable spares and unrecovered errors. Because it keeps a state file in /etc/zfs, it would need to be run as root. I run this hourly. It should be possible to update this script to also check for ZFS checksum errors, but I haven't taken the time to do it. The reminder code hasn't been tested, as I haven't had a failure since the code was put in place.

#! /bin/sh

STATEFILE="/etc/zfs/chk.state"
ALARMUSER="root@localhost"

zpool status 2>&1 | \
egrep -i '(degraded|unavail|unrecover)' > /dev/null

STATE=$?

if [ -f $STATEFILE ]
then
LASTSTATE=`cat $STATEFILE`
else
LASTSTATE=1
echo $STATE > $STATEFILE
fi

#
# Error is currently set.
#
if [ $STATE = 0 ]
then

#
# Error wasn't set previously. Send out the error message.
#
if [ $LASTSTATE = 1 ]
then
HOSTNAME=`uname -n`
zpool status -x | \
mailx -s "ZFS.error.on.$HOSTNAME" $ALARMUSER
echo $STATE > $STATEFILE
exit
fi

#
# Send out a reminder every other day.
#
FOUND=`find $STATEFILE -mtime -2`
if [ -z $FOUND ]
then
exit
fi
HOSTNAME=`uname -n`
zpool status -x | \
mailx -s "ZFS.error.reminder.on.$HOSTNAME" $ALARMUSER
echo $STATE > $STATEFILE
exit
fi

#
# Error was set, but is no longer. Send out the fixed message.
#
if [ $STATE = 1 -a $LASTSTATE = 0 ]
then
HOSTNAME=`uname -n`
zpool status -x | \
mailx -s "ZFS.error.fixed.on.$HOSTNAME" $ALARMUSER
echo $STATE > $STATEFILE
exit
fi


EDIT: Updated above script to look for unrecovered errors, thanks to information in this post by nhamilto40. To reset the error counts, the "zpool clear pool" command can be used.

I scanned this thread, and see no scripts. Perhaps this will be more useful than I thought.

ZFS tutorial using files instead of disks

Using Files
To use files on an existing filesystem, create four 128 MB files, eg.:

# mkfile 128m /home/ocean/disk1
# mkfile 128m /home/ocean/disk2
# mkfile 128m /home/ocean/disk3
# mkfile 128m /home/ocean/disk4

# ls -lh /home/ocean
total 1049152
-rw------T 1 root root 128M Mar 7 19:48 disk1
-rw------T 1 root root 128M Mar 7 19:48 disk2
-rw------T 1 root root 128M Mar 7 19:48 disk3
-rw------T 1 root root 128M Mar 7 19:48 disk4

This is easy for testing you don't need real disks or partitions
(source: http://flux.org.uk/howto/solaris/zfs_tutorial_01)

Saturday, October 3, 2009

Remote powerdown from Windows with plink.exe

Because I am using a private network without connection to the outside world,
I am not concerned about security.
Usink plink.exe as part of the puTTY package I managed a remote shutdown:
Create a shortcut on windows with the following command:
(I use the user admin for logon)

plink.exe -ssh admin@hostname -pw password -m shutdown

The tricky bit is the remote command with the option -m,
(you have to use the full path because no profile is loaded)
so my "shutdown" saved on the windows box contains this line:

/usr/bin/pfexec /usr/sbin/init 5

very similar to the 'pfexec init 5' you use when logged on in Solaris

Wednesday, September 30, 2009

Autologon

Go to /etc/X11/gdm/custom.conf and manually modify the required fields in the [daemon] section and add the following;

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=<username>
Note: You cannot auto-logon as root.

Bare in mind that I’m not concerned about security at this point as the box is not exposed to the open world, and is somewhat protected by the fact it lives on a “private” LAN. (i.e. my home lan)

If you want to run something automatically on logon you can put the commands into the /etc/profile file. Since I’ve been looking for a way to autostart virtualbox machines this will be the place i do it. (mainly because it is one of the easiest way to do it)
(source: http://sigtar.com/2009/01/29/open-solaris-autologin/)

Monday, September 28, 2009

Wireless using WUSB54GC (usb13b1,20)

At first I had a WUSB54GC based on Ralink RT3070 chipset recognized as usb1737,77 but so far no driver exists so I swapped it for the well-known older version being usb13b1,20 which uses the rum driver

It was now quite easy to get it up and running

If no wired link is available, a scan for wireless LANs is done, and the resulting list offered via a GUI popup window prompts the console user to select a preference. If a successful connection is made, the WLAN in question is stored in the plain text file /etc/nwam/known_wifi_nets and the daemon may connect to any WLAN in that list without prompting the user again. If a user wishes to add other preferences or revoke existing ones, he can do so by bringing up the NWAM Manager menu with right-click on the icon, and then selecting "Manage Favorite Wireless Networks...". A user can also edit the known_wifi_nets file directly. This interface is volatile and might change in a future release

admin@opensolaris:/etc/nwam# more known_wifi_nets
denver 0:18:39:ad:ce:36

Note: My network was recognized after I enabled broadcast again on the wireless modem and choosing the option within the Gui of NWAM to put wireless as preferred connection.

/etc/nwam/llp contains:
admin@opensolaris:/etc/nwam# more llp
bge0 static 10.0.0.4/24
rum0 static 10.0.0.10/24

In order to have wireless standard as preferred put rum0 first in llp after bge0

Helpful commands:
ifconfig -a
dladm show-wifi
dladm scan-wifi
dladm show-secobj
(Note: I removed all the profiles with dladm delete-secobj)
svcadm restart nwam

Sunday, September 6, 2009

Initial startup of remote Desktop for OpenSolaris

I've not used the xvnc-inetd service on OpenSolaris, but I have been using the vino-server without issue, which is a vnc server. The only gotcha on that is that it requires the keyring password upon first connect to the desktop, so you have to be AT the desktop at least once to "approve" the connection. To get around this and effectively dissociate the vino-server from the keyring, here is a procedure I stole from another web site. This works for me on several installations from 2008.05 on up to 2008.11. Someone may have a more efficient process than this.

Procedure:
First, enable Vino by going to System...Preferences...Desktop Sharing
0. Once you've configured Remote Desktop, go to the
System...Administration...Keyring Manager. Enter your keyring
password when prompted and let it have access to itself if prompted
(!).
1. Highlight the key that contains "vino" in it. Delete that key. Yes.
2. Start gconf-editor
3a. Navigate to desktop...gnome...remote_access.
3b. Click in the empty field to the right of "vnc_password" (the
"value" column). Enter your base64 encoded password from above.
That's it. Don't need to log out. Just connect to the system with a
VNC viewer on display "0" if you didn't change the port number.