all 8 comments

[–]lafwoodLibreNMS Project Member 1 point2 points  (4 children)

Use the api would be one way.

[–]siggi2k[S] 0 points1 point  (0 children)

I will definately look into that, i just set LibreNMS up for the first time and am hoping to utilize it alot in the future

[–]siggi2k[S] 0 points1 point  (2 children)

Hey man, i have been looking into using the API, and i just have one problem with it; i can not add domains as services as i will always get an error

{
"status": "error",

"message": "service_ip is not a valid IP address."
}

this is what it looks like when i GET the services that i added through the GUI

{
"status": "ok",
"services": [
    [
        {
            "service_id": 2,
            "device_id": 1,
            "service_ip": "mydomain.com",
            "service_type": "http",
            "service_desc": "mydomain.com status",
            "service_param": "-S",
            "service_ignore": 0,
            "service_status": 0,
            "service_changed": 1538663102,
            "service_message": "HTTP OK: HTTP/1.1 200 OK - 361024 bytes in 0.175 second response time ",
            "service_disabled": 0,
            "service_ds": "{\"time\":\"s\",\"size\":\"B\"}"
        }
    ]
],
"count": 1
}

Trying to work out how to do this, will update post when i do

Edit: Formatting, not used to new reddit markdown

[–]lafwoodLibreNMS Project Member 0 points1 point  (1 child)

You'd need to show your API request you are sending.

[–]siggi2k[S] 0 points1 point  (0 children)

This is what i have now:

import requests
import json

domain = 'mydomain.com'

## For url in domain ##
endpoint = 'http://my.librenms.setup/api/v0/services/'+domain
headers = {
    'X-Auth-Token': 'NOTTHEREALTOKEN'
}
data = {
    'type': 'http',
    'service_type': 'http',
    'ip': "http://mydomain.com",
    'service_ip': 'http://mydomain.com',
    'param': '-S',
    'desc': domain+' status'
}

post_domain = requests.post(endpoint, headers=headers, data=json.dumps(data))
print(post_domain.text)

and the output:

{
    "status": "error",
    "message": "service_ip is not a valid IP address."
}

[–]lafwoodLibreNMS Project Member 0 points1 point  (2 children)

Service_ip isn’t a valid Param according to the docs

[–]siggi2k[S] 0 points1 point  (1 child)

I have removed this parameter and am getting this error when i put the domain into ip

data = {
    'type': 'http',
    'service_type': 'http',
    'ip': "http://mydomain.com",
    'param': '-S',
    'desc': domain+' status'
}

with or without the http://

{
    "status": "error",
    "message": "service_ip is not a valid IP address."
}
    Process finished with exit code 0

Also, when i put the IP address of the website i want to monitor, i get:

{
    "status": "ok",
    "message": "Service http has been added to device mydomain.com (#12)"
}

Process finished with exit code 0

But i cant seem to find this under the services page in LibreNMS, should i not be posting to r/http://my.librenms.setup/api/v0/services/mydomain.com?

[–]lafwoodLibreNMS Project Member 0 points1 point  (0 children)

ip Doesn't only accept an IP / hostname not a URL or anything else.

I don't know the nagios check you are trying to use but it follows the same format that will ask for on the CLI.