Log Insight: GET Configuration APIs

You may recall that I stated that a Tech Preview of configuration APIs was made available in Log Insight 3.3. I have been asked on more than one occasion where the documentation for the configuration APIs reside. Unfortunately, the documentation has not been published yet so I figured I would provide some information to get you started. Read on to learn more!
li-logo

Before We Begin

UPDATE: This post has been DEPRECATED. Please refer instead to https://sflanders.net/2016/10/19/log-insight-configuration-apis/.
Disclaimer: These are TECH PREVIEW APIs meaning they are not supported and may change or even be removed in a future version of Log Insight. You have been warned.

Authentication

Before you can use the configuration APIs, you must authenticate. While I have covered authentication in the past, I wanted to provide a Bash alias I use to in order to pass around the session ID required:
UPDATE: This post has been DEPRECATED. Please refer instead to https://sflanders.net/2016/10/19/log-insight-configuration-apis/.

liauth() {
    command -v curl >/dev/null 2>/dev/null
    if [ $? != 0 ]; then echo "ERROR: curl command required"; fi
    if [ "$2" != "Local" -a "$2" != "ActiveDirectory" -o -z "$4" ]
    then
        echo "USAGE: liauth <FQDN> <Local|ActiveDirectory> <USERNAME> <PASSWORD>"
    else
        LISESSIONID=$(curl -s -X POST -i -k \
            -H "content-type: application/json" \
            -d '{ "provider": "'$2'", "username": "'$3'", "password": "'$4'" }' \
            https://$1/api/v1/sessions)
        if [ ! -z "$(echo $LISESSIONID | grep -i sessionid)" ]; then
            export LISESSIONID=$(echo $LISESSIONID | awk '{split($0,a,"\""); print a[8];}')
        else
            echo "ERROR: sessionID not found
$LISESSIONID"
        fi
    fi
}

GET vs. POST

As the title of this post indicates, I plan on covering most of the GET configuration APIs available today. The reason for this is because the GET configuration APIs only require that you know the METHOD to call. I may cover the POST configuration APIs in a future post or wait for the documentation to get published.

GET Configuration APIs

My goal is not to provide documentation for all of the GET configuration APIs — as that should be made public soon — but instead to provide a list of GET configuration APIs you can call today. Similar to the authentication Bash alias above, I have created another Bash alias for the GET configuration APIs:
UPDATE: This post has been DEPRECATED. Please refer instead to https://sflanders.net/2016/10/19/log-insight-configuration-apis/.

liget() {
    command -v python >/dev/null 2>/dev/null
    if [ ! -z "$3" -a $? != 0 ]; then echo "ERROR: curl command required"; fi
    if [ -z "$2" ]; then echo "USAGE: liget <FQDN> <METHOD> [--pretty]
Methods:
ad/config
adgroups|adgroups/<domain>/<name>|adgroups/<domain>/<name>/[capabilities|groups|datasets]|
agent|agent/groups|
appliance/support-bundles/<id>?timeout=<timeout>|
archiving/config|
cluster/nodes|cluster/nodes/:<nodetoken>|
datasets|datasets/<dataSetsID>|
forwarding|
health/resources/:<clusternodeid>|health/activequeries|health/statistics|
groups|groups/<groupId>|groups/<groupId>/[users|adgroups|capabilities|datasets]|
ilb|ilb/status|
licenses|
notifications|
time|time/config|
upgrades/:version|upgrades/:version/nodes/:node|
users|users/<userId>|users/<userId>/[capabilities|groups|datasets]|
version|
vrops|vrops/:exampleHostname|
vsphere|vsphere/:hostname|vsphere/:vspherehostname/hosts|vsphere/:hostname/hosts/esxihost>"
    elif [ -z "$LISESSIONID" ]; then echo "ERROR: Must authenticate first with liauth"
    elif [ ! -z "$3" ]; then curl -sk -X GET -H 'Content-Type: application/json' \
        -H 'Authorization: Bearer '$(echo -n $LISESSIONID) https://$1/api/v1/$2 \
        | python -m json.tool
    else curl -sk -X GET -H 'Content-Type: application/json' \
        -H 'Authorization: Bearer '$(echo -n $LISESSIONID) https://$1/api/v1/$2
    fi
}

Example: Agent Statistics

I wanted to provide an example of how to use the above Bash aliases based on the most common configuration API request I have received: how to get the agent statistics information from the /admin/agents page. To do this, I would first call the authentication alias followed by the configuration alias as follows:
UPDATE: This post has been DEPRECATED. Please refer instead to https://sflanders.net/2016/10/19/log-insight-configuration-apis/.

$ > liauth 192.168.1.25 Local <username> <password>
$ > liget 192.168.1.25 agent
{"agents":[{"agentId":"564d4dfc-6bca-07ce-3ef9-e8c1ac61ce47","lastSeen":1467569599216,"statsAsOf":1465606712683,"totalEvts":27941,"droppedEvts":0,"evtRate":0.0,"os":"Ubuntu 14.04.4 LTS","version":"3.3.0.3516686","ipAddr":"192.168.1.180","fqdn":"smith01.sflanders.net","agentStatus":"Disconnected"},{"agentId":"564d1c9f-a2fb-fb00-094d-aab5f3036d2e","lastSeen":1468765926073,"statsAsOf":1465606736554,"totalEvts":94981212,"droppedEvts":5,"evtRate":83.98332977294922,"os":"SUSE Linux Enterprise Server 11 (x86_64)","version":"3.4.0.3820781","ipAddr":"192.168.1.118","fqdn":"vcs01.sflanders.net","agentStatus":"Active"}]}
$ > liget 192.168.1.25 agent --pretty
{
    "agents": [
        {
            "agentId": "564d4dfc-6bca-07ce-3ef9-e8c1ac61ce47",
            "agentStatus": "Disconnected",
            "droppedEvts": 0,
            "evtRate": 0.0,
            "fqdn": "smith01.sflanders.net",
            "ipAddr": "192.168.1.180",
            "lastSeen": 1467569599216,
            "os": "Ubuntu 14.04.4 LTS",
            "statsAsOf": 1465606712683,
            "totalEvts": 27941,
            "version": "3.3.0.3516686"
        },
        {
            "agentId": "564d1c9f-a2fb-fb00-094d-aab5f3036d2e",
            "agentStatus": "Active",
            "droppedEvts": 5,
            "evtRate": 83.98332977294922,
            "fqdn": "vcs01.sflanders.net",
            "ipAddr": "192.168.1.118",
            "lastSeen": 1468765926073,
            "os": "SUSE Linux Enterprise Server 11 (x86_64)",
            "statsAsOf": 1465606736554,
            "totalEvts": 94981212,
            "version": "3.4.0.3820781"
        }
    ]
}

Enjoy!

© 2016, Steve Flanders. All rights reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top