Sitecore Agents Summary

Last week, I had been given the task to check all the different agents that have been implemented if they are active or not. It was like performing a sort of audit. This is a very easy job to be done. In order to be able to see if the agents are activated, I would need to go to the showconfig page which is already in built when installing the Sitecore Instance.

First of all, you need to have access in order to be able to log into the showconfig page. Once login, you only need to do a search with the following keyword: ‘<scheduling’. Then all the different agents will be present under the node. Again, this is so easy. But viewing the different agents from the showconfig can be time consuming as you need to filter between the Sitecore in-built agents and your custom agents. Also, you will need to read between the tags.

During this post, I will explain the method I had used to get the different agents and also makes it accessible to any person. In brief, I have written a simple code which read the config file using Sitecore  and display the result on an ASPX page.

Code Behind ASPX Page

public partial class AgentSummary : Page
{
    public List AgentList
    {
        get
        {
            var agentList = new List();

            var agentNodes = Factory.GetConfigNodes("scheduling/agent");

            var activeFlag = true;

            foreach (XmlNode agentNode in agentNodes)
            {
                try
                {
                    if (!XmlUtil.GetAttribute("name", agentNode).IsNullOrEmpty())
                    {
                        var interval = DateTime.Parse(XmlUtil.GetAttribute("interval", agentNode));

                        if (interval.Equals(DateTime.Today))
                        {
                            activeFlag = false;
                        }

                        var agentObject = new AgentDetails
                        {
                            AgentName = XmlUtil.GetAttribute("name", agentNode),
                            Interval = XmlUtil.GetAttribute("interval", agentNode),
                            Status = activeFlag ? "Active" : "Disable"
                        };

                        agentList.Add(agentObject);

                        activeFlag = true;
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }

            return agentList;
        }
    }
}

public class AgentDetails
{
    public string AgentName { get; set; }

    public string Interval { get; set; }

    public string Status { get; set; }
}

And voila, I have a page which shows all my agents along with its interval and the status whether it is active or not.

agent

You can get the code on GitHub here. The module is also available on the Sitecore Marketplace. You can download it from this link.

Credit to Jack Rugile for the table UI

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s