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.

ValidateCustomProperty Verb

Both Orion.NodesCustomProperties and Orion.VolumesCustomProperties have a Verb named, "ValidateCustomProperty".  Does anyone know what this verb does?  Can anyone provide the parameters required for it and the expected output?

From a lot of trial and error it seems that the verb expects 5 parameters: 3 strings, an integer, and a list of strings.  The output I get is a property bag with 2 properties: {"Status":3,"ErrorMessage":null}.  However, the format of the input and the meaning of the output remain vague.

  • This verb is primarily intended for the custom property management UI to provide feedback to users. It checks to see whether a given name is suitable for creating a custom property. It does not actually create a custom property or make any changes to the system.

    The parameters for the verb are:

    string PropertyName - name of the custom property

    string Description - description of the custom property

    string ValueType - one of {nvarchar, varchar, int, real, float, datetime, bit, ntext, text}

    int? Size - either null or an integer representing the maximum size of the custom property. Only relevant for the nvarchar and varchar data types

    string[] Value - optional list of values for the property. Used to constrain a string property to a specific list of possible values.

    But only first parameter (PropertyName) contributes to the validation result.

    In the returned object, these are the possible values for Status:

    0 = Valid. This means that you could call CreateCustomProperty with these arguments and expect success.

    1 = IsSystem. The proposed custom property conflicts with a system (non-custom) property.

    2 = IsReserved. The proposed custom property conflicts with a query keyword.

    3 = Exists. The proposed custom property conflicts with an existing custom property.

    4 = Error. An unexpected error occurred while trying to validate the proposed custom property. See the ErrorMessage property of the returned object for details.

  • Ah, I see.  Rats, I had been hoping that it would validate a proposed value against an existing custom property's restricted list of values, if it had one.  Ah, well, I'll have to do without that, I suppose.

    Thanks for the info!

  • Any chance that you found a way to validate a proposed value against an existing custom property's restricted list of values? I am trying to do this and running into the same challenge.

  • Just query the Orion.CustomPropertyValues, if the value is not already an exact match (case sensitive) for an item in the list you could reject it?

    SELECT Table, Field, Value

    FROM Orion.CustomPropertyValues

  • I wound up doing it the hard way, with my own code.  Here are snippets of the Python code I wrote.  Take them with a grain of salt; I'm a novice coder.

    osettings.py:

    ...

        base_url = 'https://' + server + ':' + str(port) + '/SolarWinds/InformationService/v3/Json/'

        query_url = base_url + 'Query'

        create_url = base_url + 'Create'

        create_node_url = create_url + '/Orion.Nodes'

        create_poller_url = create_url + '/Orion.Pollers'

    ...

    ocommom.py:

    ...

    def query_orion(query, url, user, password):

        body = {"query":query}

        if osettings.debug: print body

        response = requests.post(url, auth=(user, password), json=body, verify=False)

        if osettings.debug: print response

        if str(response) != "<Response [200]>":

            if str(response) == "<Response [403]>":

                results = [{"Error":"Authentication failure"}]

            else:

                results = [{"Error":"HTTP error: "+str(response)}]

        else:

            jresponse = response.json()

            if osettings.debug: print jresponse

            if "results" in jresponse:

                results = jresponse["results"]

            else:

                sys.exit("Orion Query returned unexpected reponse: " + jresponse)

        return results

    ...

    orion_customs.py:

    ...

    def get_args():

        parser = argparse.ArgumentParser(description="Manipulate Orion node custom properties",parents=[ocommon.parser])

        # Get arguments for working on a node's custom properties

        parser.add_argument("-c","--orion_cust_prop", required=True, help="Name of Orion custom property")

        parser.add_argument("-v","--orion_cust_value", required=True, help="Value of Orion custom property")

        return parser.parse_args()

    ...

        # Get the current custom properties of the node

        query = "SELECT Uri FROM Orion.Nodes WHERE IPAddress='" + ipaddr +"'"

        response = ocommon.query_orion(query, osettings.query_url, args.orionUser, args.orionPassword)

        node_uri = response[0]["Uri"]

        custom_url = osettings.base_url + node_uri + "/CustomProperties"

        response = requests.get(custom_url, auth=(args.orionUser, args.orionPassword), verify=False)

        current_properties = json.loads(response.text)

        if args.debug: print current_properties

       

        # Check to see if the property is available to set

        if args.orion_cust_prop in current_properties.keys():

            # Get the type of Custom Property

            query = "SELECT DataType FROM Orion.CustomProperty WHERE Field='" + args.orion_cust_prop + "'"

            value_bag = ocommon.query_orion(query, osettings.query_url, args.orionUser, args.orionPassword)

            value_type = value_bag[0]["DataType"]

            if value_type == "bit":

                # This is a True/False type of value

                # Check to see if the value is True or False; if so, confirm that it is properly set

                if args.orion_cust_value.lower() in ("true", "false"):

                    if current_properties[args.orion_cust_prop] != args.orion_cust_value:

                        ocommon.set_prop(custom_url, args.orion_cust_prop, args.orion_cust_value, args.orionUser, args.orionPassword)

                else:

                    sys.exit("Custom Property: " + args.orion_cust_prop + " must be either True or False")

            elif value_type == "nvarchar":

                # This is a text type of value

                # Check to see if the Custom Property has a table of restricted values

                query = "SELECT Value FROM Orion.CustomPropertyValues WHERE Field='" + args.orion_cust_prop + "'"

                value_bag = ocommon.query_orion(query, osettings.query_url, args.orionUser, args.orionPassword)

                if value_bag[0]["Value"] != None:

                    # There is a restricted list; check to see if the value is in the list

                    value_list = []

                    for item in value_bag:

                        value_list.append(item["Value"])

                    if args.orion_cust_value not in value_list:

                        sys.exit(args.orion_cust_value + " is not a valid value for Custom Property: " + args.orion_cust_prop)

                # Check to see if the property is properly set; if not, set it

                if current_properties[args.orion_cust_prop] != args.orion_cust_value:

                    ocommon.set_prop(custom_url, args.orion_cust_prop, args.orion_cust_value, args.orionUser, args.orionPassword)

            else:

                sys.exit("Custom Property type: " + value_type + " is not supported in this module yet")

        else:

            sys.exit("Custom property " + args.orion_cust_prop + " is not available for this node.")

    ...