Jump to content

Retrospect 6.1 Email Notification Issue


Recommended Posts

I am having an issue using the python version of the backup alert script.

I edited the file with my email address and SMTP server and it still doesn't work.

 

When I run the script within Applescript Utility all I see in the results box is the current date.

It looks like there is something wrong with the code.

 

Here is the code from the applescript that was included with my Retrospect 6.1:

-- Retrospect Event Handler for Mail.app for OSX 
-- ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-- You _must_ edit these email address property definitions. Insert the desired recipients
-- into each group using quote marks, commas to separate multiple recipients, or
-- leave curly brackets empty to not receive any mail for a group. Addresses must be
-- in the form of one of the examples below, and a mix of the two types can be used.
-- ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
property kMainGroup : {"email@somewhere.domain", "email2@somewhere.domain"} --will get mail for all events .
property kSuccessGroup : {} --will get mail only if no errors occurred
property kErrorGroup : {} --will get mail only when Retrospect reports an error
property kMediaRequestGroup : {} --will get mail when Retrospect needs new media
property kMailServer : "my.smtpserver.domain" -- the smtp server to use for sending mail
property kFrom : "email@somewhere.domain" -- the from address for the mails that Retrospect sends
--SMTP Authentication
--if your mail server uses SMTP authentication, enter the username and password here
property kUsername : ""
property kPassword : ""
-- the full path to the script that sends mail
property kScriptCommand : "/usr/bin/python /Library/Preferences/Retrospect/macmail.py"
-- This constant defines the interval (in hours) between Backup Server report emails.
property kSendBackupServerReport : 12
-- Set this property to false if you don't want the main group to receive mail on script or Backup Server starts.
property sendMailOnStart : true
-- Nothing below this line needs to be edited.
--
-- End of properties for the sendMail Function.
--
-- Properties needed for the mediaRequestTimedOut function.
property theRequestedMediaType : "" -- name of the media type
property theRequestedMember : "" -- this will let the user know what the name of the next tape will be
-- This property changes the look of the backup report.
property lineDelimiter : "----------------------"
-- Property for the header of the backup report.
property dantzLegal : "Report generated by Retrospect, Copyright 2002 Dantz Development Corporation." & return & return â¬
& lineDelimiter & return & return
-- globals
global gBackUpReport, gVolumeErrors, gNumVolumesBackedup, gStorageSet, gMediaRequestSent, gBackUpServerRunning, gTimeKeeper
-- always intialize globals
set gBackUpReport to ""
set gNumVolumesBackedup to 0
set gVolumeErrors to 0
set gBackUpServerRunning to false
set gTimeKeeper to (current date)
--
-- start of the Retrospect suite
--
on scriptStart given scriptName:theScript, startDate:theDate
if gBackUpServerRunning = false then
 set gVolumeErrors to 0
 set theMessage to "The script \"" & theScript & "\" started on " & theDate & "."
 set gBackUpReport to dantzLegal & return & theMessage & return & return & return & lineDelimiter & return & return
 if sendMailOnStart is true then
  set mySubject to "Retrospect script has started"
  sendMail given Subject:mySubject, myMessage:theMessage, recipientsList:kMainGroup
 end if
end if
return true -- If you do not return true, Retrospect will stop the script.
end scriptStart
on serverStart()
set gBackUpServerRunning to true
set theMessage to "Backup Server has started."
set gBackUpReport to dantzLegal & "From Backup Server:" & return & return
if sendMailOnStart is true then
 set mySubject to "Backup Server has started"
 sendMail given Subject:mySubject, myMessage:theMessage, recipientsList:kMainGroup
end if
set gTimeKeeper to (current date) + (kSendBackupServerReport * hours)
end serverStart
on serverEnd()
set gBackUpServerRunning to false
if sendMailOnStart is true then
 set theMessage to "Backup Server has stopped."
 set mySubject to "Backup Server has stopped"
 sendMail given Subject:mySubject, myMessage:theMessage, recipientsList:kMainGroup
end if
end serverEnd
on scriptEnd given scriptName:theScript, scriptErrorMessage:theScriptErrorMessage, errorCount:theErrorCount
if gBackUpServerRunning = false then
 if theErrorCount is 0 and gVolumeErrors is 0 then
  set mySubject to "Execution completed successfully"
  set gBackUpReport to gBackUpReport & "The script finished with no errors."
  sendMail given Subject:mySubject, myMessage:gBackUpReport, recipientsList:kSuccessGroup
  sendMail given Subject:mySubject, myMessage:gBackUpReport, recipientsList:kMainGroup
 else
  set mySubject to "Retrospect script finished with errors"
  set gBackUpReport to gBackUpReport & "The script finished with errors."
  sendMail given Subject:mySubject, myMessage:gBackUpReport, recipientsList:kErrorGroup
  sendMail given Subject:mySubject, myMessage:gBackUpReport, recipientsList:kMainGroup
 end if
 set gVolumeErrors to 0
end if
end scriptEnd
on volumeEnd given volumeName:theVolume, kbCopied:theKB, fileCount:theFileCount, durationInSeconds:theDuration, backupDate:theBackupDate, startDate:theStartDate, endDate:theEndDate, destinationName:theDestination, ClientName:theClient, zoneName:theZone, scriptName:theScript, backupTypeString:theBackupType, subvolumeDiskName:theDiskName, fileErrorCount:theFileErrorCount, volumeErrorCode:theVolumeError, volumeErrorMessage:theVolumeErrorMessage, activatorCodeString:theActivatorCode
set gStorageSet to theDestination
set gNumVolumesBackedup to gNumVolumesBackedup + 1
if theVolumeError is not 0 or theFileErrorCount is not 0 then
 set gVolumeErrors to gVolumeErrors + 1
end if

if theDiskName is not "" then
 set theParent to "The Subvolume’s parent disk is \"" & theDiskName & "\"."
else
 set theParent to ""
end if
set theDuration to secondsConverter(theDuration)

if theVolumeError is 0 then
 set theSuccess to "successfully"
 set mySubject to "Retrospect: Success"
 set gBackUpReport to gBackUpReport & "Volume \"" & theVolume & "\" completed " & theSuccess & â¬
  ", copying " & theFileCount & " files for " & theKB & " K with " & theFileErrorCount & â¬
  " errors." & return & return & "Script \"" & theScript & "\" finished copying volume \"" & â¬
  theVolume & "\" to destination \"" & theDestination & "\"." & return & return & "Duration: " & â¬
  theDuration & "." & return & return & lineDelimiter & return & return
else
 set theSuccess to "with error " & theVolumeError & ": " & theVolumeErrorMessage
 set mySubject to "Retrospect: Error " & theVolumeError & ": " & theVolumeErrorMessage
 set gBackUpReport to gBackUpReport & "•Error•" & return & return & â¬
  "Volume \"" & theVolume & "\" completed " & theSuccess & "." & return & return & lineDelimiter & return & return
end if
end volumeEnd
on mediaRequest given mediaTypeString:theMediaType, requestedMemberName:theMember, mediaIsKnownBoolean:mediaKnown
set gMediaRequestSent to false
set theRequestedMediaType to theMediaType
set theRequestedMember to theMember
return true
end mediaRequest
on mediaRequestTimedOut given numberOfSecondsWaited:theTimeOut
set theTimeOut to secondsConverter(theTimeOut)
if not gMediaRequestSent then
 set theMsg to "Retrospect needs a " & theRequestedMediaType & " named \"" & theRequestedMember & "\"." & return & return & â¬
  "Please provide this " & theRequestedMediaType & " or other appropriate media." & return & return & â¬
  "You have " & theTimeOut & "to supply Retrospect with new media or the current operation will cease."
 sendMail given Subject:"Retrospect: Media Request", myMessage:theMsg, recipientsList:kMediaRequestGroup
 sendMail given Subject:"Retrospect: Media Request", myMessage:theMsg, recipientsList:kMainGroup
 set gMediaRequestSent to true
 return false -- reset the media request
else
 set gVolumeErrors to gVolumeErrors + 1
 set gBackUpReport to gBackUpReport & â¬
  "•Media request timeout occurred before script could successfully finish•" & return & return
 return true -- one media request timer cycle so timeout.
end if
end mediaRequestTimedOut
-- The RetrospectQuit handler should always be available so the Retrospect Event Handler quits when Retrospect quits.
on RetrospectQuit()
quit --Please leave this in so that the Retrospect Event Handler cleans up properly
end RetrospectQuit
--
-- end of the Retrospect suite
--

-- sendmail function for shell driven mail sending
to sendMail given Subject:subj, myMessage:bodyText, recipientsList:reciplist

if reciplist is {} or reciplist is "" or reciplist is {""} or bodyText is "" then return -- Nothing or no one to send to.
set reciplist to reciplist as list
--Here we writet the message body to a temporary file, so that macmail.py doesn't have to deal with shell limitations (such as maximum number of characters on the command line
set target_file to "tmp:macmail.message"
--no poisoning of our emails by other users
do shell script "/bin/rm -f " & POSIX path of target_file
my write_to_file(bodyText, target_file, false)

repeat with toaddress in reciplist
 do shell script kScriptCommand & space & toaddress & space & kMailServer & space & quoted form of subj & space & POSIX path of target_file & space & kFrom & space & kUsername & space & kPassword
end repeat
--ditch the temp file
do shell script "/bin/rm -f " & POSIX path of target_file
end sendMail
-- idle handler for delayed sending in backup server scripts.
on idle
if gBackUpServerRunning is false then return --only enter the idle handler if we are running a backup server script
if (current date) > gTimeKeeper then
 set convertedDate to shortDate() --set the date to short date format
 set timeOfDate to time string of (current date) --now get the time
 set convertedDate to convertedDate & " " & timeOfDate --now put them together

 set gBackUpReport to gBackUpReport & return & â¬
  "Retrospect Backup Server backed up " & gNumVolumesBackedup & " volume(s) in the last " & kSendBackupServerReport & " hours. "
 if gVolumeErrors is 0 then
  set mySubject to convertedDate & " Backup Server Report"
  set gBackUpReport to gBackUpReport & return & return & "Backup Server reported no errors. "
  sendMail given Subject:mySubject, myMessage:gBackUpReport, recipientsList:kSuccessGroup
  sendMail given Subject:mySubject, myMessage:gBackUpReport, recipientsList:kMainGroup
 else
  set mySubject to convertedDate & " Error in Backup Server Report"
  set gBackUpReport to gBackUpReport & "Backup Server reported " & gVolumeErrors & " errors. "
  sendMail given Subject:mySubject, myMessage:gBackUpReport, recipientsList:kErrorGroup
  sendMail given Subject:mySubject, myMessage:gBackUpReport, recipientsList:kMainGroup
 end if
 set gBackUpReport to dantzLegal & "From Backup Server:" & return & return
 set gTimeKeeper to (current date) + (kSendBackupServerReport * hours)
 set gNumVolumesBackedup to 0
 set gVolumeErrors to 0
end if
return
end idle
-- this function will convert seconds to hours minutes seconds.
on secondsConverter(mySeconds)
set timeString to ""
set myHours to 0
set myMinutes to 0

if (mySeconds = 0) then
 set timeString to "zero seconds"
else
 if (mySeconds ≥ hours) then
  set myHours to mySeconds div hours
  set mySeconds to mySeconds mod hours

  if (myHours = 1) then
   set timeString to timeString & "1 hour "
  else
   set timeString to timeString & myHours & " hours "
  end if
 end if

 if (mySeconds ≥ minutes) then
  set myMinutes to mySeconds div minutes
  set mySeconds to mySeconds mod minutes

  if (myMinutes = 1) then
   set timeString to timeString & "1 minute "
  else
   set timeString to timeString & myMinutes & " minutes "
  end if
 end if

 if (mySeconds ≠ 0) then
  if (mySeconds = 1) then
   set timeString to timeString & "1 second"
  else
   set timeString to timeString & mySeconds & " seconds"
  end if
 end if
end if
return timeString
end secondsConverter
-- this function will convert AppleScript's long date format to a short date format.
on shortDate()
set today to current date
set thisDate to day of today
set theDay to thisDate + 0
-- And now do the month
set thisMonth to month of today
if thisMonth is January then
 set theMonth to 1
else if thisMonth is February then
 set theMonth to 2
else if thisMonth is March then
 set theMonth to 3
else if thisMonth is April then
 set theMonth to 4
else if thisMonth is May then
 set theMonth to 5
else if thisMonth is June then
 set theMonth to 6
else if thisMonth is July then
 set theMonth to 7
else if thisMonth is August then
 set theMonth to 8
else if thisMonth is September then
 set theMonth to 9
else if thisMonth is October then
 set theMonth to 10
else if thisMonth is November then
 set theMonth to 11
else -- It has to be December
 set theMonth to 12
end if
set thisYear to year of today
set theYear to thisYear + 0
set theYear to characters 3 through 4 of (theYear as string) as string

return (theMonth & "/" & theDay & "/" & theYear) as string
end shortDate
-- From apple essential subroutines
on write_to_file(this_data, target_file, append_data)
try
 set the target_file to the target_file as text
 set the open_target_file to â¬
  open for access file target_file with write permission
 if append_data is false then â¬
  set eof of the open_target_file to 0
 write this_data to the open_target_file starting at eof
 close access the open_target_file
 return true
on error
 try
  close access file target_file
 end try
 return false
end try
end write_to_file

  • Like 1
Link to comment
Share on other sites

OK.

All I remember is that is was a real pain to set up correctly.

 

Looking at this line of code:

 

property kScriptCommand : "/usr/bin/python /Library/Preferences/Retrospect/macmail.py"

Is there a file called macmail.py in that Retrospect folder?

Link to comment
Share on other sites

OK.

All I remember is that is was a real pain to set up correctly.

 

Looking at this line of code:

 

property kScriptCommand : "/usr/bin/python /Library/Preferences/Retrospect/macmail.py"

Is there a file called macmail.py in that Retrospect folder?

 

Yes the macmail.py file is in the correct location.

I am able to get email notifications with the following AppleScript: http://hints.macworld.com/article.php?story=20060221145350354

so I know that's not the problem.

 

There is something wrong with the code in the script that is causing it to just spit out the current date and not send out an email.

Link to comment
Share on other sites

I used the Applescript version of the notification script for years, but I had to make some significant changes to get it working properly. Some of the bugs I remember fixing included things like it losing information if ou stopped the backup server, and throwing away information if the output email grew bigger than 32K characters. As I recall, there were a bunch of other bugs, too.

 

(I can post my version if you like - it works with Eudora, and is somewhat special to my setup)

 

I recommend taking a long hard look at the script. It probably got less debugging attention than the Applescript one, and has the same kinds of bugs.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...