Triggering Events with Command Manager
MicroStrategy Command Manager is an external application that has basic scripting components that can be used for bulk operations. While it’s designed to automate common tasks and save time in bulk changes, it does come with the ability to integrate external applications with MicroStrategy Events. This allows you to integrate your process flow from sources such as ETL or source system events to trigger MicroStrategy tasks like Subscriptions, Cache Clears or Intelligent Cube refreshes.
Today, we’ll take a look at setting up Events in MicroStrategy and triggering them externally with Command Manager. But the fun doesn’t stop at ETL, as another use case for triggering external Events is to setup schedules otherwise not supported by the MicroStrategy Scheduler!
The MicroStrategy Scheduler handles all automated tasks inside the Intelligence Server. The traditional schedules are Time Based, which execute on a date/time schedule and repeat as defined. While this is an obvious method for scheduling, it does leave you exposed to a number of issues, specifically, that you could be firing events when the system isn’t quite ready. For example, if you have Subscriptions scheduled to run at 6am, but ETL hasn’t completed because of an error or long running jobs, you could be sending out incorrect data.
Fortunately, MicroStrategy Scheduler supports a second type of trigger, which is an Event Based schedule. For these, you simply create an Event and tie the schedule to it. From inside MicroStrategy Desktop, this is where the journey ends. You can’t do anything with an Event from inside Desktop except right click and trigger it immediately. However, from a tool such as Command Manager, you can trigger that Event and any Schedules that are tied to it. So now, you can create an Event called “Monday”, create a Schedule called “Monday Subscriptions” and then allow end users to subscribe to that schedule. ETL can now trigger the “Monday” event when they’re finished, and the Subscriptions will always go out as early as possible, but guaranteed to have completed data.
While Command Manager is a pretty robust scripting tool in it’s own right, scripts can also be run via a command line interface which is handy for automation tasks. Follow these steps to configure a Command Manager script to trigger Monday Subscriptions once ETL is ready:
Step 1 – Create the Script
Create the following script in Command Manager or even just in notepad:
TRIGGER EVENT “Monday”;
Alternatively, you can bypass the Event and also trigger subscriptions directly per project for extra control:
TRIGGER ALL SUBSCRIPTIONS FOR SCHEDULE “Monday Subscriptions” FOR PROJECT “Your Project”;
That’s it! That’s the full syntax and content of the script. Now just save it as MyScript.scp (or whatever you want to name it) and you’re done. Note that “Your Project” is case sensitive.
Step 2 – Create a Batch/Shell Script
I prefer to create a Batch/Shell script and then execute that script from the Operating System’s scheduler (Windows Task Scheduler or Cron depending on your OS). This gives you an easier place to make tweaks than opening up those tools.
Open up Notepad again and fill out the command line to call Command Manager like this:
cmdmgr.exe -n “Project Source” -u “User”-p “Password” -f “MyScript.scp” -o “MyScript.log”
Note that “Project Source” actually is a Project Source, and not a Project Name. You have to create a project source locally on the server making the call. This means you have to at least install Command Manager locally on whatever box is running this script, such as your ETL box, and you have to go to Start->Programs->MicroStrategy->Tools->Project Source Manager to create a Project Source for this script to use.
User/Password will be stored in clear text in this script file. You can protect the login information by taking a few more steps outlined in this tech note.
In a Unix environment, all of the steps are the same, except the application is mstrcmdmgr instead of cmdmgr.exe.
Step 4 – Schedule it!
This step is largely up to you, but now you just have to execute the .bat file from whatever application you’re trying to hook up to MicroStrategy Events. This can be a Cmd Task in an ETL tool such as Informatica, a command in a .NET application or even a task in the Windows Scheduler/Cron. Simply run the script, and it’s off on it’s way.
The best use case for this it to add a step at the end of an ETL process to trigger Subscriptions or Caches. But it doesn’t just end there. Another one I commonly use is to support Time Based Schedules that aren’t supported by the MicroStrategy Scheduler. The most common one is a schedule that has to run on the last day of the month. MicroStrategy doesn’t directly support that kind of dynamic date, but an easy work around would be to use a more robust type of scheduling tool like Windows Task Scheduler or Cron and have it simply execute an Event Based Schedule itself.
Many years ago, I worked in a 32bit environment that had a very heavy Document/PDF Narrowcast run in the morning. The system would get stressed and run into issues when all of those Documents tried to fire up at the same time. A solution that made it manageable to was handle the schedule queuing myself, so I wrote a simple program that would stagger the schedules by 15 minutes or so once they started. ETL would trigger my program, and my program would trigger the Events via Command Manager staggered every 15 minutes so they didn’t run on top of each other.
Do you have another idea for a use case? Drop it in the comments!