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."
}%
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"
}%
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:
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.
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:
default devices and devicegroups to specific time with now() start fallback
provide separate functions for scheduled versus immediate maintenance
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.