How to create a API poller proxy in Python using Orion API


The native SAM api poller handling  is very static requiring manual handling in SW for changes on the target side.

With a proxy Python script we could handle changes as well as just installing the script for other sites.

Further, the api poller is a SAM function whereas the api data is related to different network elements.

The proxy could then also resolve this mismatch.

 I have envisaged that we should be able to generate a python script which will:

  • Initialize - identify the components from the api response to be monitored and configure SW variables accordingly
  • For each polling it will detect if any configuration changes have been made on the target side and adapt the SW config accordingly
  • For each polling it will update the SW variables and SW actions should be taken if status is down etc as natively handled by SW

My starting point for changing values in SW is to use the Orion api via Python as documented at

One should then be able to add nodes and set custom properties for those.

However, I do not understand how one should be able to apply a “push model” (from the proxy into SW) yielding a SW handling with alarms etc for these variables / custom properties.

The documentation is focused on poller types which is the opposite way of data handling (fetch model).

I would then be pleased to get some guidance on how use the orion api with python for our purposes.


  • This all depends on what you are looking to change.  If you want to assign or unassign specific Application Templates (you mentioned Server & Application Monitor (SAM)  near the beginning), that can be done with the API.  If you want to assign custom properties to either the assigned application or nodes, this can also be done.

    But most people "shortcut" this by using Groups.  Here's a (simplified) scenario:

    • You have an application template (we'll call it "Custom Application")
    • This application needs to be assigned to a set of nodes.
    • You create a custom property (for Nodes) called "RunsCustomApp" (True/False) and check the box when the server runs the application.
    • You create a Group called "Custom App Servers" and have a Dynamic Query defining membership where "RunsCustomApp" is True.
    • You can then assign the "Custom Application" template to the group.
    • When nodes move in and out of the group, the application is either assigned or unassigned from the device.
  • Thanks for the feedback!
    I am sorry, but I am not able to follow some details in what you are suggesting (as I am not an experienced user), and would be pleased if you could direct me to the associated documentation and to add some details 

    • From your reply my understanding is that my (Python) proxy would be the Custom application to be created. (I have no experience in applying custom applications)
    • I will then have to create a Group of nodes ("Custom App Servers") there the nodes have a specific custom property defined and set. I would name the new property myself e.g. "RunsCustomApp".
    • There should then be a dynamic membership as to add/remove nodes from the Group which should be controlled by the proxy/application

    Thereby the node mapping is achieved and one could then e.g. use maps to present the topology.
    However, it is not clear how the status information shall be updated / pushed into SW by the proxy/application.

  • Hi Kevin,

    I'm hoping you can help me with the Invoke methods mentioned in your comment since you posted it recently and I can't find much documentation or discussion on it.

    Using SWQL studio, I can see the list of templates with this query: SELECT TOP 1000 ID, Guid, Name, Version, DisplayName, Description, Created, Updated, TemplateData, RequestsCount, MetricsCount, IsCustom FROM Orion.APIPoller.Templates

    My goal is to create a script to automate the creation of an API poller using one of these template ID's. The use case is that one of the teams in my organization has been quietly monitoring almost 300 API's via testing using Postman and script automation for the past several years, and I would like to plug in whatever document they give me (.txt or .csv) with all of the necessary details, into a script so that it takes all of the params and builds the API Pollers accordingly so that I don't have to do it manually.
    They are mulesoft API's hosted in the cloud, if that matters.
    My ultimate goal would be to use this functionality for DevOps to automate the monitoring of new API's with "self-service" for dev teams in mind.
    ***The issue is that I can't figure out what to pass with the Orion.APIPoller.Invoke - CreateApiPollerFromTemplate  in SWQL Studio, specifically, the "Configuration" body and the "Parameters" body***
    I've had success with similar invoke methods with SWQL, but this one is giving me a hard time.
    Please help. Thanks.
  • I haven't done this work before.  The verbs and read/write capabilities are there.  I just haven't done the work before.  My API pollers are VERY simple when I work with them.

  • Hi Kevin,

    Perhaps you could invite some expert on the API Pollers into this discussion as to overcome the problems with the static configuration.

    Unfortunately I do not have a SW instance up and running at the moment as to refer to the various DB tables for API Pollers.
    However, I see that one could structure the problem as:

    When making the configuration in the GUI what are the steps to create the related DB instances.
    There is then eg to define the values to be read and their translations into SW e.g. map 'Up' into SW value = 1.
    (Using the GUI for configuration one defines the URLs, token handling, parameters to be read and associated SW mapping, and could serve as a way to understand the API poller tables)

    The question is then if there is some additional SW functions that would be automatically triggered when creating the basic data in the DB and to populate some other tables.
    The critical question is then how the polling will be triggered, potentially SW will automatically check all the API pollers in the DB and populate the DB tables holding the polling data. (Alarm handling will be defined on top)

    Surprisingly the polling interval is not controlled in the API pollers but in the "hidden system configuration file".

    In addition, one has to consider how to apply changes related to data to be read etc along the road.

    Best regards

  • Without an instance, there's very little that can be done.  And I'm not working with the database directly, but with the API.  Without an instance, the API's are not available.

    We don't support working with the database tables directly - because they can change version to version.

  •    Kevin, can you refer to someone who has created API pollers via the SDK or some documentation with examples.

    We thought about opening a support ticket, but they push back on helping with custom scripts!

  • We don't have any documentation for it.  All the API's docs are up in the GitHub Wiki (and some samples).  I don't think we have any specific for API pollers.

  • I don't see a section for the API poller.  Can you help point to that specific section of the Github Wiki?

  • Here is an example adapted from some internal design documents.  I haven't tested this, so take it with a big grain of salt.  If this doesn't work, I'll ask the team that worked on this feature to comment here.

    CreateApiPollerFromTemplate allows you to create an API Poller based on a template exported either from an existing API Poller or from the out-of-the-box template library.  But how do you get that template file to begin with?  If you're exporting an existing API Poller to a file (template.xml in the example below), you could use the ExportTemplate verb:

    Import-Module SwisPowerShell
    $hostname = "IP"
    $username = "Username"
    $plainTextPassword = "***"
    $password = $plainTextPassword | ConvertTo-SecureString -AsPlainText -Force
    $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
    $swis = Connect-Swis -host $hostname -cred $cred
    $templateId = 1
    $result = Invoke-SwisVerb $swis Orion.APIPoller.Templates ExportTemplate @($templateId)
    $exportedTemplate = $result.InnerText
    $exportedTemplate | Out-File ".\template.xml"

    Once you have a template file to work with, you can import it via the CreateApiPollerFromTemplate verb:

    Import-Module SwisPowerShell
    $hostname = "IP"
    $username = "Username"
    $plainTextPassword = "***"
    $password = $plainTextPassword | ConvertTo-SecureString -AsPlainText -Force
    $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
    $swis = Connect-Swis -host $hostname -cred $cred
    $apiPollerTemplate = (Get-Content -Path ".\template.xml" | Out-String)
    $configuration= @{
        "CredentialType" = "BasicAuth"
        "CredentialID" = "1"
    $parameters= @{ };
    $result = Invoke-SwisVerb $swis "Orion.ApiPoller.ApiPoller" "CreateApiPollerFromTemplate" @("Orion.Nodes", 1, $apiPollerTemplate, $configuration, $parameters)
    $apiPollerId = $result.InnerText

  •     Thank you for the response.  This documentation helps a lot.

    I was able to get it to work manually through the SWQL studio, but when trying via the PowerShell script I keep getting this message.  I can't figure out what is does not like.

    Invoke-SwisVerb : Verb Orion.APIPoller.ApiPoller.CreateApiPollerFromTemplate cannot unpackage parameter 3 of type System.Collections.Generic.Dictionary`2[System.String,System.String]

    Initially I was trying to pass in the XML string as it was passed in via SWQL studio and then I changed the $configuration and $parameters to the hash table format you suggested, but it returns the same error.

    Here is my code snippet:

    $entityType = "Orion.Nodes"
    $entityID = 3045
    $template = '<?xml version="1.0" encoding="utf-8"?><Template xmlns:xsi="">" xmlns:xsd="">><Description /><Created>2024-03-05T04:38:10.3644824Z</Created><Updated>2024-03-05T04:38:10.3644824Z</Updated><Version>1</Version><RequestDetailsCollection><RequestDetails><Url></Url><Body /><HttpVerb>Get</HttpVerb><ValueToMonitorCollection><ValueToMonitor><DisplayName>status code</DisplayName><Path>$</Path><ThresholdRule>NotEqualTo</ThresholdRule><WarningThresholdValue xsi:nil="true" /><CriticalThresholdValue>200</CriticalThresholdValue><Type>StatusCode</Type><StringToNumberTransformationRules /><StringToNumberTransformationOtherValues>0</StringToNumberTransformationOtherValues></ValueToMonitor></ValueToMonitorCollection><RequestVariables /><RequestDetailsOrder>0</RequestDetailsOrder></RequestDetails></RequestDetailsCollection><PollingInterval>60</PollingInterval></Template>'
    ## Variable format option 1
    #$configuration = '<ArrayOfKeyValueOfstringstring xmlns:i="">" xmlns="'">>' | ConvertFrom-StringData
    #$parameters = '<ArrayOfKeyValueOfstringstring xmlns:i="">" xmlns="'">>' | ConvertFrom-StringData
    ## Variable format option 2
    $configuration = @{
    "Name" = $pollerName
    "DisplayName" = $pollerName
    "Url" = $pollerURL
    "VerifySslCertificate" = $true
    "UseProxy" = $false
    "PollingInterval" = 60
    "CredentialType" = "OAuth2Shared"
    "CredentialID" = "173"
    $parameters = @{ };
    Invoke-SwisVerb $swis Orion.APIPoller.ApiPoller CreateApiPollerFromTemplate @($entityType, $entityID, $template, $configuration, $parameters)

  • Internally, the last two parameters for this SWIS verb (configuration and parameters) are of type Dictionary<string, string> in C#.  That means it's a dictionary data structure with a string key and a string value.  When serialized as XML, Microsoft uses ArrayOfKeyValueOfstringstring (see  There's a lot of useful information about working with that kind of data and some examples of what the XML looks like at  See Where are Orion.Credential.CreateCredentials & Orion.Credential.UpdateCredentials for an example of another place this data format is used with the Orion SDK for a different verb.  The XML there should give you a good idea of what this should look like. 

Reply Children
No Data