Skip to content

Client API Interface

string GetPluginName()

This method gets called whenever Pulseway requires the plugin name for logging, displaying it to the user in the plugins tab and saving settings.

public override string GetPluginName()
{
    return "Simple Plugin";
}
    

string GetPluginDescription()

GetPluginDescription's main purpose is pretty straight forward; it shows to the user a short descriptive text that represents the main functionality of your plugin.

public override string GetPluginDescription()
{
    return "This plugin shows the current date and time.";
}
    

Groups GetAdditionalComputerDetails()

In order for Pulseway to actually show anything new to its clients this method gets used. The Groups that get returned will be shown in the computer details page. This is the perfect place to show a plugin main menu with "PageItem" and "CommandItem" that will further be used to lead the user to the data he is looking for.

public override Groups GetAdditionalComputerDetails()
{
    Groups container = new Groups(); // Group of "Group" types.
    Group mainGroup = new Group("Simple Plugin"); // Group of "SimpleItem" / "CommandItem" / "PageItem" with the title Simple Plugin.
    SimpleItem date = new SimpleItem("Current Date: ", DateTime.Now.Date.ToShortDateString()); // Simple Item with "Current Date: " title and current date as subtitle.
    SimpleItem time = new SimpleItem("Current Time: ", DateTime.Now.TimeOfDay.ToString()); // Simple Item with "Current Time: " title and current time as subtitle.
    mainGroup.Items.Add(date); // Adding the date SimpleItem to our Group container.
    mainGroup.Items.Add(time); // Adding the time SimpleItem to our Group container.
    container.Add(mainGroup); // Adding the mainGroup Group to Groups container.
    return container; // Returning our Groups container to Pulseway.
}
    

void CommandReceived(int commandId)

Here is where the action begins. The command got executed and we received the identification number of which command was called.

private const int COMMAND_INCREASE_INVOCATION_COUNT = 1;
private int invocationCount;
public override void CommandReceived(int commandId)
{
    if (commandId == COMMAND_INCREASE_INVOCATION_COUNT)
        invocationCount++;
}
    

The ID must be unique.

void PluginLoaded()

This method gets triggered when the plugin is fully loaded and ready to start working.

public override void PluginLoaded()
{
    invocationCount = 0;
}
    

void SetValueForKey(string Key, string Value)

In order to save plugin's data we can implement our own methods or use "SetValueForKey" which creates a registry entry with the name specified in the "Key" parameter and our value safely encrypted.

public override void PluginLoaded()
{
    SetValueForKey("Plugin Configuration", "This plugin shows the current date and time.");
}
    

string GetValueForKey()

GetValueForKey is used to get a previously stored value using "SetValueForKey". This takes the value from the Windows Registry, decrypts it and returns your value in clear text.

public override string GetPluginDescription()
{
    return GetValueForKey("PluginDescription");
}
      

Version GetMinimumRequiredAgentVersion()

When your plugin uses a pre-release version of Pulseway and you want to release it, you should specify which is the minimum required version to make sure that everything will work smoothly.

public override MM.Monitor.Client.Version GetMinimumRequiredAgentVersion()
{
    return new MM.Monitor.Client.Version(2, 9, 1);
}
      

Form GetConfigurationForm()

If your plugin requires a configuration in order to work then the best approach is having a dialog (a Form in our case) which can handle the plugin configuration. This Form gets created when the user clicks the "Configure" button inside the "Plugins" tab from Pulseway Manager.

public override System.Windows.Forms.Form GetConfigurationForm()
{
        return new MyConfigurationForm(this) as System.Windows.Forms.Form;
}
    
And the form code:
using System.Windows.Forms;
using MM.Monitor.Client;
namespace SimplePlugin
{
    public partial class MyConfigurationForm : Form
    {
        private readonly IDataStore dataStore;
        public MyConfigurationForm(IDataStore dataStore)
        {
            InitializeComponent();
            this.dataStore = dataStore;
        }
    }
}
   

In order to use API's "GetValueForKey" and "SetValueForKey" we need to pass our plugin reference to the configuration form.

void PluginDataCheck()

This is where your plugin checks whether it needs to inform you about something, perfect place for notifications to be sent. It gets called automatically every 15-20 seconds.

public override void PluginDataCheck()
{
    invocationCount++;
}
   

void SendNotificationToAllDevices(string message, NotificationPriority priority, bool allowMultipleNotifications = false)

Method used to send a notification to all devices that have push notifications enabled. The message can have up to 250 characters to display on the mobile device alert and up to 5000 characters to be viewed inside the Pulseway client.

public override void PluginDataCheck()
{
    SendNotificationToAllDevices("Current Invocation Count: " + invocationCount, NotificationPriority.NORMAL);
}
    

After one notification is sent you can send another one only after the first one is deleted using a client application, unless allowMultipleNotifications is true.

bool CanSendNotifications

CanSendNotifications is a Boolean field that lets you know if you can send a notification (If false it means that there is a notification sent by this plugin that wasn't deleted from the client application.

public override void PluginDataCheck()
{
    if (CanSendNotifications)
        SendNotificationToAllDevices("Current Invocation Count: " + invocationCount, NotificationPriority.NORMAL);
}
    

void NotificationDeleted()

If your plugin has to send a notification and you CanSendNotifications returns false then you need to use a Queue (Or any other collection) to store unsent notifications and when we get the signal that we can send a new notification to send the next one on our list.

private readonly Queue notificationList = new Queue();
public override void PluginDataCheck()
{
    string Message = "Current Invocation Count: " + invocationCount;
    if (CanSendNotifications)
        SendNotificationToAllDevices(Message, NotificationPriority.NORMAL);
    else
        notificationList.Enqueue(Message);
}
public override void NotificationDeleted()
{
    SendNotificationToAllDevices(notificationList.Dequeue().ToString(), NotificationPriority.NORMAL);
}
    

ComputerInfo GetComputerInfo()

Sometimes having more information about local computer is crucial so Pulseway API makes sure you have all the data you need to know in real time. ComputerInfo type stores 3 things:

  • bool InMaintenanceMode: If true than Maintenance Mode is enabled (that means that all notifications will not be sent).
  • string Name: The name of the computer that was set in Pulseway Manager.
  • string Group: The group of the computer that was set in Pulseway Manager.

public override void PluginDataCheck()
{
    ComputerInfo localComputer = GetComputerInfo();
    if (CanSendNotifications && !localComputer.InMaintenanceMode)
        SendNotificationToAllDevices(String.Format("Current Invocation Count: {0}\nSent from: {1}\nIn Group:{2}",
    invocationCount, localComputer.Name, localComputer.Group), NotificationPriority.NORMAL);
}
   

void PluginUnloaded()

This is used called right after the plugin is marked for removal and gives you a chance to disconnect active connections or perform cleanup procedures.

public override void PluginUnloaded()
{
    MyDatabaseConnection.Close();
    MyDatabaseConnection.Dispose();
}
    

Groups GetPageDetails(int pageId)

Occurs when a PageItem gets called by a client and asks for its Groups content.

private const int PAGE_COMPUTER_DETAILS = 1;
private const int PAGE_COMMAND_RESET_INVOCATION_COUNT = 1;
public override Groups GetPageDetails(int pageId)
{
    if (pageId != PAGE_COMPUTER_DETAILS)
    return null;
    Groups container = new Groups();
    ComputerInfo localComputer = GetComputerInfo();
    Group mainGroup = new Group("Computer Details");
    SimpleItem name = new SimpleItem("Computer Name: ", localComputer.Name);
    SimpleItem group = new SimpleItem("Computer Group: ", localComputer.Group);
    SimpleItem maintenance = new SimpleItem("Computer Maintenance: ", localComputer.InMaintenanceMode.ToString());
    CommandItem command = new CommandItem(PAGE_COMMAND_RESET_INVOCATION_COUNT, "Reset Invocation Count");
    mainGroup.Items.Add(name);
    mainGroup.Items.Add(group);
    mainGroup.Items.Add(maintenance);
    container.Add(mainGroup);
    return container;
}
    

The ID must be unique.

void PageCommandReceived()

PageCommandReceived is not the same thing with CommandReceived. All CommandItems that are triggered from inside a PageItem will trigger PageCommandReceived and all CommandItems that are called from the GetAdditionalComputerDetails will trigger CommandReceived.

public override void PageCommandReceived(int pageId, int commandId)
{
    if (pageId != PAGE_COMPUTER_DETAILS && commandId != PAGE_COMMAND_RESET_INVOCATION_COUNT)
        return;
    invocationCount = 0;
}
   

void Trace(string logMessage)

Method used for debugging purposes. If "Diagnostic Logging" is enabled from Pulseway Manager ("Settings" tab -> "Diagnostics" subtab) the logMessage text will be written to a log file located at Pulseway's installation path with the name "trace.txt".

public override void PageCommandReceived(int pageId, int commandId)
{
    if (pageId != PAGE_COMPUTER_DETAILS && commandId != PAGE_COMMAND_RESET_INVOCATION_COUNT)
    {
        Trace(String.Format("PageCommandReceived has unknown ids: {0} - {1}", pageId, commandId));
        return;
    }
    invocationCount = 0;
}
    

void DateInputValueChanged(string inputId, Date inputValue)

Method that will be called whenever an DateInput's value has changed. The Date type contains the year, month and day sent from the mobile client.

public override void DateInputValueChanged(string inputId, Date inputValue)
{
    Console.WriteLine(inputValue.Year + " " + inputValue.Month + " " + inputValue.Day);
}
    

void TimeInputValueChanged(string inputId, Time inputValue)

Method that will be called whenever an TimeInput's value has changed. The Time type contains the hour and minute sent from the mobile client.

public override void TimeInputValueChanged(string inputId, Time inputValue)
{
    Console.WriteLine(inputValue.Hour + ":" + inputValue.Minute);
}
    

void DateTimeInputValueChanged(string inputId, MM.Monitor.Client.DateTime inputValue)

Method that will be called whenever an DateTimeInput's value has changed. The DateTime type contains the year, month, day, hour and minute sent from the mobile client.

public override void DateTimeInputValueChanged(string inputId, MM.Monitor.Client.DateTime inputValue)
{
    Console.WriteLine(inputValue.Year + ":" + inputValue.Month + " " + inputValue.Day + " " + inputValue.Hour + ":" + inputValue.Minute);
}
    

void NumericInputValueChanged(string inputId, int inputValue)

Method that will be called whenever an NumericInput's value has changed. The inputValue type contains the number sent from the mobile client.

public override void NumericInputValueChanged(string inputId, int inputValue)
{
    Console.WriteLine(inputValue.ToString());
}
    

void TextInputValueChanged(string inputId, string inputValue)

Method that will be called whenever an TextInput's value has changed. The inputValue type contains the text sent from the mobile client.

public override void TextInputValueChanged(string inputId, string inputValue)
{
    Console.WriteLine(inputValue);
}
    

void PickListInputValueChanged(string inputId, int pickListItemId)

Method that will be called whenever an PickListInput's selected item has changed. The pickListItemId represents the ID of the PickListItem.

public override void PickListInputValueChanged(string inputId, int pickListItemId)
{
    Console.WriteLine(pickListItemId.ToString() + " selected");
}