API /api/v0/devicesgroups/:name/maintenance - "Server Error: Set APP_DEBUG=true to see details."

Hi! I’m trying to use /api/v0/devicesgroups/:name/maintenance API, but I’m getting an error

curl -X POST -d '{"title":"Device group Maintenance","notes":"A 2 hour Maintenance triggered via API","start":"04:30","duration":"2:00"}' -H 'X-Auth-Token: *******************' http://10.255.255.20/api/v0/devicegroups/MIAFL00/maintenance
{
    "message": "Server Error: Set APP_DEBUG=true to see details."
}%                   

Any ides what I’m doing wrong?

Thank you

Lacking correct doco - the date/time formats are the issue.

If you set APP_DEBUG-true in .env as it says, you’ll get a load of output which complains at the top about:

    "message": "Data missing",
    "exception": "Carbon\\Exceptions\\InvalidFormatException",
    "file": "/opt/librenms/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php",
    "line": 676,
    "trace": [
        {
            "file": "/opt/librenms/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php",
            "line": 699,
            "function": "rawCreateFromFormat",
            "class": "Carbon\\Carbon",
            "type": "::"
        },
        {
            "file": "/opt/librenms/includes/html/api_functions.inc.php",
            "line": 2164,
            "function": "createFromFormat",
            "class": "Carbon\\Carbon",
            "type": "::"
        },

...

In the code it hardcodes the call to that in the format ‘Y-m-d H:i:00’ and a lazy duration split ‘hrs:mins’:

So play along with that and I got it to work:

$ curl --insecure -X POST -H "X-Auth-Token: $LNMSAPI" "$APIPATH/devicegroups/MYDEVGROUP/maintenance" --data-raw '
{
 "title":"Device group Maintenance",
  "notes":"A 2 hour Maintenance triggered via API",
  "start":"2022-07-15 04:30:00",
  "duration":"02:00"
}
'

Outputs:

{
    "status": "ok",
    "message": "Device group MYDEVGROUP (5) will begin maintenance mode at 2022-07-15 04:30:00 for 02:00h"
}

If that works for you, I’ll do a PR to update the doco.

It worked. Thank you very much for your help.

curl  -X POST -H "X-Auth-Token: ***********************" \
--data-raw '
{"title":"Device group Maintenance","notes":"A 2 hour Maintenance triggered via API","start":"2022-07-13 15:00:00","duration":"2:00"}
' \
http://10.255.255.20/api/v0/devicegroups/DETMI00/maintenance
{
    "status": "ok",
    "message": "Device group DETMI00 (34) will begin maintenance mode at 2022-07-13 15:00:00 for 2:00h"
}%                        

@rhinoau, there is one issue. The actual device group is not set.

Is it a bug?

Thank you

Yes I get the same, no group/device mapping.

The code that does all that is beyond me and I can’t see anything obvious, hopefully someone else can offer some insights.

It looks like it makes an \App\Models\AlertSchedule object and passes it to the devicegroup object it has found. It appears its not putting an entry in the alert_schedulables table referencing the device_group.

If I look at my alert_schedule table - here’s the one that the API inserted:

MariaDB [librenms]> select * from alert_schedule where title = 'Device Group Maintenance';
+-------------+-----------+---------------------+---------------------+---------------+--------------------------+----------------------------------------+
| schedule_id | recurring | start               | end                 | recurring_day | title                    | notes                                  |
+-------------+-----------+---------------------+---------------------+---------------+--------------------------+----------------------------------------+
|          27 |         0 | 2022-07-14 20:30:00 | 2022-07-14 20:30:00 | NULL          | Device group Maintenance | A 2 hour Maintenance triggered via API |
+-------------+-----------+---------------------+---------------------+---------------+--------------------------+----------------------------------------+
1 row in set (0.000 sec)

If I then make a mapping as below, it shows correctly in the UI with a mapping:

MariaDB [librenms]> insert into alert_schedulables (schedule_id, alert_schedulable_id, alert_schedulable_type ) values (27, 5, 'device_group');
Query OK, 1 row affected (0.005 sec)

MariaDB [librenms]> select * from alert_schedulables order by item_id desc limit 1;
+---------+-------------+----------------------+------------------------+
| item_id | schedule_id | alert_schedulable_id | alert_schedulable_type |
+---------+-------------+----------------------+------------------------+
|      53 |          27 |                    5 | device_group           |
+---------+-------------+----------------------+------------------------+

I’m not understanding all the frameworks and database abstraction going on as I’m not very familiar with it - so can’t see an obvious fix. It also looks like the /devices/ API endpoint maintenance call has the same issue, it doesn’t assign it to the device.

@rhinoau, I have opened an issue in GitHub https://github.com/librenms/librenms/issues/14111

Nice! I see this was fixed: https://github.com/librenms/librenms/pull/14127
Thank you!!!

1 Like

Baffling that both those were just straight broken. Unfortunately, missed the 22.7.0 release.

1 Like

Was about to follow behind with some doco and noticed that the devices endpoint has some issues and goes to 1970 and uses now()+duration for end time. I see there is some fallback to now() if no start time is given - easy fix, but is there a preference on how it should respond?

Some options/thoughts - guessing backward compatibility isn’t a major issues seeing as it never worked:

  1. default devices and devicegroups to specific time with now() start fallback
  2. provide separate functions for scheduled versus immediate maintenance
  3. separate functions with the existing ones defaulting to scheduled or immediate based on a new global setting

I’m leaning #1 - use now() if no start time and accept specific if supplied.

PR to answer my own conjecture:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.