This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Alert creation with Python.

Hello.

I  try to trigger new alert with help of Python.

I found an old discussion here on thwack with example in PowerShell  Insert directly to AlertLog or Events Log , and tried to use it as template, so I received next code:

def main():

    npm_server = 'localhost'

    username = 'admin'

    password = ''

    swis = SwisClient(npm_server, username, password)

    print("Add an alert:")

        # set up property bag for the new node

    props = {

        'AlertDefID':'9a05848a-f441-4a5d-8b2c-e74e3a61b42d', ##Replace here with the Guid of the alert definition you are using. Random GUIDs won't work 

        'ActiveObject': 8,

        'ObjectType':'Node',

        'State': 2,

        'WorkingState':0, 

        'ObjectName':'uMPLS-PE1_7k-1.main.velcom.by', 

        'AlertMessage':'was triggered. IT IS  SUCCESS!!!!', 

        'Acknowledged':0

    }

    print("Adding alert {}... ".format(props['AlertDefID']), end="")   

    results = swis.create('Orion.AlertStatus', **props)

    print("DONE!")

   

requests.packages.urllib3.disable_warnings()

if __name__ == '__main__':

    main()

It does not show any script errors and runs OK, but alert instance doesnt appear in DB and Manage Alerts view.

As I understand active alert instance is defined by 3 entries in DB : Orion.AlertStatus, Orion.AlertObjects, Orion.AlertActive.

And Orion.AlertStatus seems to be the main one, because it have fields related to other ones.

So can someone help me in this question or guide to the right direction. maybe I have to pass additional parameters to Orion.AlertStatus entry, or maybe have to create other entries in DB.

Thanks in advance for your replies.

  • Orion.AlertStatus is part of the older "Advanced Alerts" system. AlertObjects, AlertActive, and some other entities (see Alerts · solarwinds/OrionSDK Wiki · GitHub​) are the basis for the alert system introduced in 2015 with NPM 11.5.

    What you are attempting to do here (directly trigger an alert) is not really supported. What's your real goal? I might be able to point you to another more supported way to achieve it.

  • On the subject of alerts. What would be the best way to disable all alerts during a maintenance window and re-enable the ones that was de-activated after the maintenance window has expired? I'm not looking for un-managing nodes, but rather, enable and disable alert rules.

  • You can toggle the Enabled property of the Orion.AlertConfigurations instances using the "update" call. Get the Uri values of the alert rules you want to turn off, then call update and set Enabled to false. When you want to turn them back on, call update again and set Enabled to true.

  • Our final goal is to trigger an alert after arrival of an trap in TrapViewer.

    So step by step:

    - Comes trap from device to Orion TrapConsole\Viewer.

    - It triggers a rule for this trap

    - In this rule one of the actions is Execute an external program

    - This external program is a Python script which makes query to the DB table for traps, takes necessary information about trap and creates new alert in Alert console for this trap

    I know what same result can be achieved with creation of a SQL\SWQL based alert in AlertManager. But this solution haves some disadvantages. Our main goal is to minimize time from trap arrival to alert creation. minimal time of alert trigger check is 15 seconds. But it is not very efficient to run query every 15 seconds for alert which triggers not very often. At the same time for my tests with 15 seconds interval of trigger condition check I found what some times it fails to raise an alert for active trap.

    So we thought it will be better to insert an alert directly after trap arrival.

  • Ok, that makes sense. There's no way to do this now that wouldn't be a nasty pile of hacks. When we update Traps and Syslog to use the new (well, 2015) alerting system, this will be perfectly natural, but that's not in this release.

  • Thanks for your reply.

    As I understand this feature won't be implemented in upcoming NPM 12 release?

    Can you provide some inside information (emoticons_happy.png)  about progress on the field of Traps and Syslog functionality update? Can we expect it this year or it is a matter of next big release?

    Based on number of users posts about alerting for traps here on thwack, it is very anticipated feature.

    Once again thanks for your reply and help.

  • I don't have a timeline for you. You can add your vote here:

  • Yeah, please up vote and boy it'd be nice if this one didn't get kicked under the carpet for 4 years.. but yeah..

    Peter