Difference between revisions of "User:Antony Fairport/Scripts/Sim Restart Notifier"

From Second Life Wiki
Jump to navigation Jump to search
m
(Added documentation to the page and removed the link to the explanation on my blog.)
Line 1: Line 1:
[http://antonyfairport.blogspot.com/2012/06/region-restart-notifier-again.html Originally documented here].
A simple script that helps you know when a region has restarted and also what might have changed during the restart (a change of server generally seems to imply a manual restart; the same server but different server version.... well, that's obviously a server software change as part of a rolling restart.


TODO: Document here rather that push people over to the blog.
To use it, just drop the script in a prim that's rezzed on the region you want to keep track of. Left as is the script will send you an IM when there's a restart. If you'd prefer that it sends you an email (that's my preference -- if I'm in-world while my region is restarting I can sometimes miss the object's IM but I never miss the email) just set the value of '''EMAIL_TO''' to the address you want the message sent to.
 
The message you get will look something like this:
 
Shackles has restarted.
Channel: Second Life RC LeTigre
Version: 13.01.14.269010 (Changed. Was 12.12.18.268345)
Host: sim9099.agni.lindenlab.com
 
Touching the prim the script is in will result in it [[llWhisper|whispering]] the last restart time in [[PUBLIC_CHANNEL|local]].


<lsl>
<lsl>

Revision as of 03:06, 30 January 2013

A simple script that helps you know when a region has restarted and also what might have changed during the restart (a change of server generally seems to imply a manual restart; the same server but different server version.... well, that's obviously a server software change as part of a rolling restart.

To use it, just drop the script in a prim that's rezzed on the region you want to keep track of. Left as is the script will send you an IM when there's a restart. If you'd prefer that it sends you an email (that's my preference -- if I'm in-world while my region is restarting I can sometimes miss the object's IM but I never miss the email) just set the value of EMAIL_TO to the address you want the message sent to.

The message you get will look something like this:

Shackles has restarted.

Channel: Second Life RC LeTigre
Version: 13.01.14.269010 (Changed. Was 12.12.18.268345)
Host: sim9099.agni.lindenlab.com

Touching the prim the script is in will result in it whispering the last restart time in local.

<lsl> ////////////////////////////////////////////////////////////////////// // Sim Restart Notifier -- By Antony Fairport // // Informs you when the sim it is located on restarts. Handy during // rolling restarts when you've had to run away and want to be told // as soon as it's back up. // // Revision history: // ------------------------------------------------------------ // // 2012-05-21 // Added more information to the notification (channel, version, etc) // and also added the option to send an email instead of an IM. // // 2011-05-31 // First version.

////////////////////////////////////////////////////////////////////// // Set the following to an email address if you want the restart // notifier to send an email rather than send an IM. Leave it empty // to get an IM instead. string EMAIL_TO = "";

////////////////////////////////////////////////////////////////////// // Gobals. string g_sLastChannel = ""; string g_sLastVersion = ""; string g_sLastHost = ""; string g_sLastRestart = "";

////////////////////////////////////////////////////////////////////// // Format a llGetTimestamp() string FormatTime( string sTime ) {

   list l = llParseString2List( sTime, [ "T", "." ], [] );
   
   return llList2String( l, 0 ) + " " + llList2String( l, 1 ) + " UTC";

}

////////////////////////////////////////////////////////////////////// // Record details about the current server. RememberServer() {

   g_sLastChannel = llGetEnv( "sim_channel" );
   g_sLastVersion = llGetEnv( "sim_version" );
   g_sLastHost    = llGetSimulatorHostname();

}

////////////////////////////////////////////////////////////////////// // Return details of a change (or not). string Changed( string sOld, string sNew ) {

   if ( sOld != sNew )
   {
       return " (Changed. Was " + sOld + ")";
   }
   else
   {
       return "";
   }

}

////////////////////////////////////////////////////////////////////// // Send out the information about the restart. InformAboutRestart() {

   // Remember the time of this restart.        
   g_sLastRestart = FormatTime( llGetTimestamp() );
   
   // The headline for the information.
   string sHeadline = llGetRegionName() + " has restarted.";
   
   // The body of the information.
   string s = sHeadline + "\n\n";
   
   // Get the current information about the region.
   string sChannel = llGetEnv( "sim_channel" );
   string sVersion = llGetEnv( "sim_version" );
   string sHost    = llGetSimulatorHostname();
   
   // Add the host/server details.
   s += "Channel: " + sChannel + Changed( g_sLastChannel, sChannel ) + "\n";
   s += "Version: " + sVersion + Changed( g_sLastVersion, sVersion ) + "\n";
   s += "Host: "    + sHost    + Changed( g_sLastHost,    sHost    ) + "\n";
   // Having compared, we remember the new server state.
   RememberServer();
   // If we have an email address...
   if ( EMAIL_TO != "" )
   {
       // ...send it as an email.
       llEmail( EMAIL_TO, sHeadline, s );
   }
   else
   {
       // No email address. Just IM it.
       llInstantMessage( llGetOwner(), s );
   }

}

////////////////////////////////////////////////////////////////////// // Default state. default {

   //////////////////////////////////////////////////////////////////
   // State entry.
   state_entry()
   {
       // Remember the current details of the server.
       RememberServer();
   }
   //////////////////////////////////////////////////////////////////
   // Reset on rez.
   on_rez( integer start_param )
   {
       llResetScript();
   }
       
   //////////////////////////////////////////////////////////////////
   // React to a touch.
   touch_start( integer num_detected )
   {
       // If we don't have a last restart time...
       if ( g_sLastRestart == "" )
       {
           // ...so say.
           llWhisper( 0, "No restart has been recorded yet." );
       }
       else
       {
           // Otherwise say what the last recorded restart time is.
           llWhisper( 0, "Last restart was " + g_sLastRestart );
       }
   }
   
   //////////////////////////////////////////////////////////////////
   // React to changes.
   changed( integer change )
   {
       // If the region has started...
       if ( change & CHANGED_REGION_START )
       {
           // ...inform about the restart.
           InformAboutRestart();
       }
       // Reset if we're passed on.
       else if ( change & CHANGED_OWNER )
       {
           llResetScript();
       }
   }

} </lsl>