4 Replies Latest reply on Mar 7, 2017 5:12 PM by odegoldsby@iiinfo.com

    python orionsdk.SwisClient.(invoke, update) method examples

    odegoldsby@iiinfo.com

      Hi,

       

      Are there any more examples of using the Orionsdk.SwisClient.invoke( or update) methods than what's at the wiki page for python Orionsdk? I need to push data from an external script into the AlertNote field found in the AlertObjects table so that I can then use the ${N=Alerting;M=Notes} variable in an email alert notification that I send.. It has an association with the AlertActive table and  I see the only verbs to use (I think this is the one) is the AlertActive.AppendNote.  I'm referencing this wiki link where I attempt the syntax:

       

      Alerts · solarwinds/OrionSDK Wiki · GitHub

       

      aliases = swis.invoke('Orion.AlertActive', 'AppendNote ', value ,'TEST')      # value gets assigned as my AlertObjectID

      print(aliases)

       

       

      However I can't seem to get it to work.  Here's a Snippet of my results:

       

      <type 'list'>

      {u'TriggeredDateTime': u'2017-03-04T22:53:36.033', u'AlertNote': u'Hellow', u'TriggeredMessage': u'High CPU Utilization with Top 10 Processes', u'AlertObjectID': 6220, u'RelatedNodeId': 14}

      <type 'dict'>

      TriggeredDateTime

      AlertNote

      TriggeredMessage

      AlertObjectID

      AlertObjectID value is: 6220

      RelatedNodeId

       

      Traceback (most recent call last):

        File "./check.py", line 67, in <module>

          aliases = swis.invoke('Orion.AlertActive', 'AppendNote ', value,'TEST')

        File "/Library/Python/2.7/site-packages/orionsdk/swisclient.py", line 29, in invoke

          "Invoke/{}/{}".format(entity, verb), args).json()

        File "/Library/Python/2.7/site-packages/orionsdk/swisclient.py", line 59, in _req

          resp.raise_for_status()

        File "/Library/Python/2.7/site-packages/requests/models.py", line 909, in raise_for_status

          raise HTTPError(http_error_msg, response=self)

      requests.exceptions.HTTPError: 400 Client Error: Verb Orion.AlertActive.AppendNote : Not found for url: https://solarwinds-orion:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.AlertActive/AppendNote%20

       

       

       

      .......what am I missing??

       

       

      Also are is there some 'update' example that's possible for what I'm trying to do??

       

      Help on class SwisClient in orionsdk:

       

       

      orionsdk.SwisClient = class SwisClient

      |  Methods defined here:

      |

      |  __init__(self, hostname, username, password, verify=False)

      |

      |  create(self, entity, **properties)

      |

      |  delete(self, uri)

      |

      |  invoke(self, entity, verb, *args)

      |

      |  query(self, query, **params)

      |

      |  read(self, uri)

      |

      |  update(self, uri, **properties)

      (END)

        • Re: python orionsdk.SwisClient.(invoke, update) method examples
          odegoldsby@iiinfo.com

          UPDATED:   I figured out my question.  Hopefully this helps others.. and possibly we can get samples with explanations updated in the SDK.  My original syntax:

           

          aliases = swis.invoke('Orion.AlertActive', 'AppendNote ', value ,'TEST')      # value gets assigned as my AlertObjectID

          print(aliases)

           

          ...First.. I had an extra space  (   'AppendNote '  ).    After correcting  to (   'AppendNote'  ) .. I received this error next:

           

          C:\Python27\lib\site-packages\requests\packages\urllib3\connection.py:340: SubjectAltNameWarning: Certificate for solarwinds-orion ha

          ame`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (

          b.com/shazow/urllib3/issues/497 for details.)

            SubjectAltNameWarning

          Traceback (most recent call last):

            File "./check.py", line 70, in <module>

              aliases = swis.invoke('Orion.AlertActive', 'AppendNote', value,'TEST')

            File "C:\Python27\lib\site-packages\orionsdk\swisclient.py", line 29, in invoke

              "Invoke/{}/{}".format(entity, verb), args).json()

            File "C:\Python27\lib\site-packages\orionsdk\swisclient.py", line 59, in _req

              resp.raise_for_status()

            File "C:\Python27\lib\site-packages\requests\models.py", line 909, in raise_for_status

              raise HTTPError(http_error_msg, response=self)

          requests.exceptions.HTTPError: 400 Client Error: Verb Orion.AlertActive.AppendNote cannot unpackage parameter 0 with type System.Int32

          s://solarwinds-orion:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.AlertActive/AppendNote

           

           

          This error:   400 Client Error:  Verb Orion.AlertActive.AppendNote cannot unpackage parameter 0 with type System.Int32   indicates my syntax parameter for  'value' is not correctly formatted.   This is BECAUSE IT NEEDS TO BE AN ARRAY (OR IN PYTHON  A LIST)!!!! 

           

           

          CORRECT SYNTAX  or the one that worked for me:

                  SWIS.INVOKE (  'TABLENAME'  ,   'VERBNAME'  ,   PYTHON LIST[int],    'TEXT NOTES WHATEVER'   )   

           

          aliases = swis.invoke('Orion.AlertActive', 'AppendNote', value,'TEST')

           

           

           

          so I did this:

           

           

          (before):

           

          for key in (alertd.keys()):       

              print(key)

              if key == "AlertObjectID":

                  value = alertd['AlertObjectID']         <<<<  I wrongly assigned an integer here instead of putting this into a list

                 print "%s value is: %s" % (key, value)

           

          aliases = swis.invoke('Orion.AlertActive', 'AppendNote', value,'TEST')

           

           

          (after):

           

          for key in (alertd.keys()):       

              print(key)

              if key == "AlertObjectID":

                  value = []                                 <<<<  HERE  is the list  to be populated with the value in AlertObjectID

                  value.append(alertd['AlertObjectID'])    <<<  HERE  I append that value in the list

                  print "%s value is: %s" % (key, value)

           

          aliases = swis.invoke('Orion.AlertActive', 'AppendNote', value,'TEST')

           

           

           

           

          And my result is the boolean expression as described in documentation:

           

           

          <type 'list'>

          {u'TriggeredDateTime': u'2017-03-06T20:11:33.527', u'AlertNote': u'TEST', u'TriggeredMessage': u'High CPU Utilization with Top 10 Processes', u'AlertO

          bjectID': 6220, u'RelatedNodeId': 14}

          <type 'dict'>

          TriggeredDateTime

          AlertNote

          TriggeredMessage

          AlertObjectID

          AlertObjectID value is: [6220]

          RelatedNodeId

          C:\Python27\lib\site-packages\requests\packages\urllib3\connection.py:340: SubjectAltNameWarning: Certificate for solarwinds-orion has no `subjectAltN

          ame`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://githu

          b.com/shazow/urllib3/issues/497 for details.)

            SubjectAltNameWarning

          True                           <<<  HERE     invoke worked!

           

           

           

          doublechecked via SWQL query checking for AlertNote field.. and its updated!   whooOHooO!      Could someone add that small notation about 'list[int]'  to the python SDK notes?

          2 of 2 people found this helpful
          • Re: python orionsdk.SwisClient.(invoke, update) method examples
            mxr662

            Did you see the samples here?  AlertObjectID needs to be an array.  From here.

             

            bool AppendNote(int[] alertObjectIds, string note)  the int with the brackets indicates an arrray or perhaps a list in python?

             

            alertobjectid = [272]

            results = swis.invoke('Orion.AlertActive', 'AppendNote', alertobjectid, 'test')

            • Re: python orionsdk.SwisClient.(invoke, update) method examples
              odegoldsby@iiinfo.com

              Thanks all ...I originally didn't see a sample specific to that verb and I didn't make the connection the Alerts (Wiki) page was talking 'also' about for Python usage being that Python(orionsdk) has it's own GitHub page/download/etc.... It finally clicked after see a comment from tdanner in a different post (someone using a different language) assigning an integer when it expected an array..      So Thanks much for adding that clarity in the samples section!