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.

I wanted to create a Java program for Solarwinds to Query everything on an IP Address

Hi,

I wanted to create a Java Program which could run Queries and give me an output for the Queries. I already have it in Python but specifically wanted it for Java.

import requests

import json

from getpass import getpass

"""

Make sure to set a valid nodeID in line 50 before using!

"""

class SwisClient:

    def __init__(self, hostname, username, password):

        self.url = "https://%s:17778/SolarWinds/InformationService/v3/Json/" % (hostname)

        self.credentials = (username, password)

    def query(self, query, **params):

        return self._req("POST", "Query", {'query': query, 'parameters': params}).json()

    def _req(self, method, frag, data=None):

        return requests.request(method, self.url + frag,

            data=json.dumps(data),

            verify=False,

            auth=self.credentials,

            headers={'Content-Type': 'application/json'})

def samplecode(npm_server,username,password):

    swis = SwisClient(npm_server,username,password)

   

    print ("Query Test:")

    results = swis.query("Query") # set valid NodeID!

    #uri = results['results'][0]['Uri']

    print (results)

   

def main():

    npm_server = input("IP address of NPM Server: ")

    username = input("Username: ")

    password = getpass("Password: ")

    samplecode(npm_server,username,password)

if __name__ == "__main__":

    main()

Thanks

Arnav