Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Growl for SoftRAID and other apps that use system.log Apps
I use SoftRAID for mirroring (part of my backup scheme for my PowerBook), but was missing some notifications on missing or out-of-sync disks. Since SoftRAID reports changes of disk status in system.log, I wrote an AppleScript that reads the system.log and filters out SoftRAID messages, displaying them via Growl.

This can also be used for other applications that report things to system.log, or even to Growl all system.log messages. You can set the filter for the syslog messages, the amount of time to look back in the system.log, and other things like that. Basic usage instructions are in the script.

[robg adds: I haven't tested this one.]
    •    
  • Currently 1.60 / 5
  You rated: 1 / 5 (5 votes cast)
 
[7,432 views]  

Growl for SoftRAID and other apps that use system.log | 8 comments | Create New Account
Click here to return to the 'Growl for SoftRAID and other apps that use system.log' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Growl for SoftRAID and other apps that use system.log
Authored by: eboss on Mar 01, '07 08:40:01AM

Hi, I don't use SoftRAID, but the idea is very good.

It would be great to have a log monitor that reacts to some words and/or regular expressions (regexps) and sends some Growl notifications.

I don't have any skill in Applescript nor Cocoa dev, so I can just submit the idea and hope that someone brilliant would implement it ;-)



[ Reply to This | # ]
Growl for system.log
Authored by: WinUser on Mar 03, '07 01:35:21PM

My script is set up that it is not hard to change for what you want. Tell me what you are thinking about and I'll give it a shot... Send me a mail to get quick response.



[ Reply to This | # ]
Growl for SoftRAID and other apps that use system.log
Authored by: wuf810 on Mar 01, '07 01:06:21PM
Very nice. I use Softraid and I will have go with this. At the moment I use a piece of software called Raid Monitor Does softraid provide more info through the system log than Raid Monitor?

[ Reply to This | # ]
Raid Monitor
Authored by: WinUser on Mar 03, '07 02:02:04PM

I think you are using the MacOSX software RAID, not the SoftRAID product, which is a little more advanced. While my script works for SoftRAID system.log messages, Raid Monitor does not recognize SoftRAID and works for the 'normal' OSX RAID.



[ Reply to This | # ]
Growl for SoftRAID and other apps that use system.log
Authored by: sadyhr on Mar 05, '07 12:38:53PM
Hi What am I doing wrong?
I have pasted the script into Script Editor and get errors, when trying to save as script or compile the script.
It complains, that it expected an end of line but found an "id".
It's stopping at the:
property scriptName : "syslogSoftRAID" -- the name of this script

---
/Sebastian

[ Reply to This | # ]

version?
Authored by: WinUser on Mar 06, '07 06:54:10AM

What version of Scripteditor do you use? I have 2.1.1 (81) with applescript 1.10.7



[ Reply to This | # ]
version?
Authored by: sadyhr on Mar 06, '07 02:43:21PM

Hi
I'm using precisely the same versions as you.
And running 10.4.8 on a PM G4 AGP.

---
/Sebastian



[ Reply to This | # ]
linewrapping
Authored by: WinUser on Mar 12, '07 12:17:48PM
I think that when you download the script, it adds some linefeeds which messes up the script. Here is a better version:
-- Script to read the system.log and show softRAID messages using GROWL.
-- Make sure the system.log is readable by this application.
-- Save this script from ScriptEditor as Application with checkbox "stay open"

property useGrowl : true -- set this to true to get warnings via Growl (http://growl.info/)
property updateDelay : 15 -- seconds 

property scriptName : "syslogSoftRAID" -- the name of this script
property SoftRAIDAppName : "SoftRAID 3.6.app" -- the name of the softRAID application, to get its icon

property softRAIDFilter : "SoftRAID driver" -- text to filter the syslog on

property shownItems : {} -- list of lines that have already been processed/shown

property useDelayLoop : false -- set this to true if you want to run from Script Editor

property onlySoftRAIDLog : true -- set this to true if you want to see only SoftRAID

property firstLookBackTime : hours * 10 -- how far back do we look the first time
property normalLookBackTime : 5 * updateDelay -- how far back do we look normally

property lookBackTime : firstLookBackTime -- the time to look back

property firstReadBackLines : 1000 -- number of lines to read from syslog the first time
property normalReadBackLines : 20 -- number of lines to read back normally

property readBackLines : firstReadBackLines -- number of lines to read from syslog

property maxMemoryLines : 1000 -- number of lines to hold in memory


property firsttime : true -- if it is the first time we do this


-- the run handler (invoked at script startup)
on run
	
	--display dialog ("running")
	
	if useGrowl then
		registerWithGrowl()
	end if
	
	
	update()
	delay updateDelay
	
	if useDelayLoop then
		repeat
			update()
			delay updateDelay
		end repeat
	end if
	
end run



-- the idle handler (invoked every 'updateDelay' seconds)
on idle
	if useDelayLoop then
		-- we should never get here
		display alert "Internal error: idle handler called even though using delay loop"
		quit
	end if
	
	update()
	return updateDelay
end idle




-- do the things we should do
on update()
	
	set now to current date
	
	if onlySoftRAIDLog then
		set logLines to do shell script "grep '" & softRAIDFilter & "' /var/log/system.log |tail -n " & readBackLines
	else
		set logLines to do shell script "cat /var/log/system.log |tail -n  " & readBackLines
	end if
	
	if logLines is equal to "" then
		display dialog ("read my rights")
		quit
		
	end if
	
	-- get the list of lines
	set myList to paragraphs of logLines
	
	-- check all lines we read
	repeat with anItem in myList
		
		set now to current date
		
		set txt to anItem as string -- to make sure it is a normal string
		
		if txt is not equal to "" then
			
			set m to word 1 of txt
			set d to word 2 of txt
			set y to year of now
			
			
			if (month of now as string) contains m then
				
				--display dialog ("month of now as string [" & (month of now as string) & "] contains m[" & m & "]")
				set m to month of now
			else
				--display dialog ("month of now as string [" & (month of now as string) & "] does not contains m[" & m & "]")
				set tempdate to now
				set day of tempdate to 1
				set prevmonth to tempdate - 1 * days
				set m to month of prevmonth
				set y to year of prevmonth
				--display dialog (prevmonth as string)
				--display dialog ("m=" & m & "  y=" & y)
				--display dialog (now as string)
			end if
			
			set logdate to date (now as string)
			
			--display dialog (now as string)
			
			set day of logdate to d
			set month of logdate to m
			set year of logdate to y
			
			--display dialog (now as string)
			
			set h to word 3 of txt
			set m to word 4 of txt
			set s to word 5 of txt
			
			set hours of logdate to h
			set minutes of logdate to m
			set seconds of logdate to s
			
			--display dialog (now as string)
			
			--displayOtherWarningUsingGrowl("time", logdate as string)
			
			set timedifference to now - logdate -- seconds 
			
			-- if it is not too old and not handled before, we can handle it
			if (timedifference  normalLookBackTime) then
					-- if it is kinda old (the first time) we want to show the time
					set txt to h & ":" & m & ":" & s & " " & txt
				end if
				
				
				if txt contains softRAIDFilter then
					--displaySoftRAIDWarningUsingGrowl(SoftRAIDAppName, txt)
					--display dialog (timedifference)
					displaySoftRAIDWarningUsingGrowl(SoftRAIDAppName, (logdate as string) & txt)
				else
					displayOtherWarningUsingGrowl("Console", txt)
				end if
				
				-- remember this line to prevent it from being displayed more than once
				set end of shownItems to (anItem as string)
				
				-- prevent memory overflow by deleting old lines if memory is full enough
				if (count of shownItems) > maxMemoryLines then
					delete first item of shownItems
				end if
				
			end if
			
		end if
		
	end repeat
	
	
	if firsttime is true then
		-- this is the first time, set some properties to normal values
		
		set readBackLines to normalReadBackLines
		set lookBackTime to normalLookBackTime
		
		set firsttime to false
		
	end if
	
	
end update

-- display a message using Growl
on displaySoftRAIDWarningUsingGrowl(appName, msg)
	tell application "GrowlHelperApp"
		notify with name "SoftRAID Driver system.log lines" title "SoftRAID" description msg application name scriptName icon of application appName
	end tell
end displaySoftRAIDWarningUsingGrowl


-- display a message using Growl
on displayOtherWarningUsingGrowl(appName, msg)
	tell application "GrowlHelperApp"
		notify with name "non-SoftRAID system.log lines" title "system.log" description msg application name scriptName icon of application appName
		
	end tell
end displayOtherWarningUsingGrowl


-- registerWithGrowl:
-- Registers our notifications with the "Growl" tool
on registerWithGrowl()
	set notifList to {"SoftRAID Driver system.log lines", "non-SoftRAID system.log lines"}
	
	tell application "GrowlHelperApp"
		register as application scriptName all notifications notifList default notifications notifList
	end tell
	
end registerWithGrowl


[ Reply to This | # ]