8 Replies Latest reply on May 25, 2016 6:54 PM by pserwe

    Alert creation with Python.

    e.solonin

      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.

        • Re: Alert creation with Python.
          tdanner

          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.

            • Re: Alert creation with Python.
              dvanzyl

              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.

                • Re: Alert creation with Python.
                  tdanner

                  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.

                • Re: Alert creation with Python.
                  e.solonin

                  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.