Events
The events resource can be used to retrieve events in the system.
Available methods:
GET POST |
/api/2/reports/events/list | Events overview |
GET POST |
/api/2/reports/events/get | Event details |
GET POST |
/api/2/reports/events/summary | Events summary |
POST |
/api/2/reports/events/dismiss | Dismiss active failed events |
POST |
/api/2/reports/events/notice | Add a note to an event |
list
Returns a list of events stored in M/Monit. Arguments can be combined to select specific events.
Arguments
| active | number | optional | The active events filter. Possible values: 0=show all events, 1=show only active errors, 2=show only active errors but exclude user dismissed errors |
| hostid | number | optional | Show only events from hosts with matching host id. The argument can be used multiple times to select multiple hosts |
| hostgroupid | number | optional | Show only events for hosts that are member of the given hostgroupid |
| servicenameid | number | optional | Show only events for the given service name id |
| servicegroupid | number | optional |
Show only events for services in the given service group. The value is the service group name id, as /api/2/map/servicegroup returns it: a service group with the same name on several hosts has one id
|
| servicetype | number | optional | Show only events for the given service type. Possible values: 0=filesystem, 1=directory, 2=file, 3=process, 4=remote host, 5=system, 6=fifo, 7=program |
| eventtype | number | optional |
Show only events of the given event type. The value is an event type id, a sequential number (not a bit mask), as listed by /api/2/map/event (for example 1=action). Events from Monit versions older than 6.1.0, which report only the event class, are matched by the class of the given type
|
| state | number | optional | Show only events with the given state. Possible values: 0=success, 1=error, 2=change |
| datefrom | unix timestamp | optional | Show only events from the given time stamp |
| dateto | unix timestamp | optional | Show only events until the given time stamp |
| results | number | optional | Returns only the given number of events (page size) |
| startindex | number | optional | Result set offset (page index) |
| sort | string | optional | The sort key. Possible values: "date", "hostname", "servicename", "event", "note" |
| dir | string | optional | The sort direction. Possible values: "desc" (descending), "asc" (ascending) |
curl -b ~/.mmonit/cookie \
http://127.0.0.1:8080/api/2/reports/events/list
Output
| recordsReturned | The number of events in the result set |
| pageSize | The maximum number of events to return (page size) |
| totalRecords | The total number of events which match the selection. If the totalRecords exceeds the pageSize value, the result is paginated |
| startIndex | The page index (position) in the selection |
| sort | The sort key. Possible values: "date", "hostname", "servicename", "event", "note" |
| dir | The sort direction. Possible values: "desc" (descending), "asc" (ascending) |
| records | |
| id | The internal event id assigned by M/Monit when the event is stored |
| date | Unix timestamp (GMT timezone), as a string |
| hostname | The host name |
| hostid | The host id |
| servicename | The service name |
| servicenameid | The unique id assigned to the servicename string (shared by any instance of the same string) |
| event | The event description |
| eventtype |
The event state, despite the name: the eventtype argument above takes an event type id. Possible values: 0=success, 1=error, 2=change
|
| note | The event notice flag. Possible values: 0=no event notice, 1=event notice is set |
{
"recordsReturned": 1,
"pageSize": 15,
"totalRecords": 1,
"startIndex": 0,
"sort": "date",
"dir": "desc",
"records": [
{
"id": 272,
"date": "1414560357",
"hostname": "myhost",
"hostid": 185,
"servicename": "devfs",
"servicenameid": 8,
"event": "unmonitor action done",
"eventtype": 2,
"note": 0
}
]
}
get
Returns details for a specific event.
Arguments
| id | number | required | The event id to get |
curl -b ~/.mmonit/cookie \
http://127.0.0.1:8080/api/2/reports/events/get?id=274
Output
| id | The event id |
| hostid | The host id |
| host | The host name |
| date | Unix timestamp (GMT timezone), as a string |
| servicename | The service name |
| servicetype | The service type (string representation) |
| event | The event type (string representation) |
| eventtype |
The event type id, as listed by /api/2/map/event (0 for events from Monit versions older than 6.1.0, which report only the event class)
|
| eventstate | The event state. Possible values: 0=success, 1=error, 2=change |
| action | The event action (string representation) |
| message | The event description |
| note | |
| date | The note timestamp (unix timestamp, as a string) |
| uname | The note author username |
| message | The note body |
{
"id": 274,
"hostid": 185,
"host": "trilobite.local",
"date": "1414560351",
"servicename": "devfs",
"servicetype": "Filesystem",
"event": "Action done",
"eventtype": 1,
"eventstate": 2,
"action": "Alert",
"message": "monitor action done",
"note": [
{
"date": "1414560557",
"uname": "admin",
"message": "Lorem ipsum"
}
]
}
Errors
| 400 | The id is missing or malformed |
| 404 | No such event, or the event is on a host the user may not view |
The error body is a JSON object, for example {“error”:“Event 274 does not exist”}.
summary
Returns the events summary for the last 24 hours.
Arguments
| none |
curl -b ~/.mmonit/cookie \
http://127.0.0.1:8080/api/2/reports/events/summary
Output
| datefrom | The time range start (now - 24 hours) [unix timestamp] |
| dateto | The time range stop (now) [unix timestamp] |
| events | |
| label | The event state |
| data | An array of unix timestamps, events count pairs. Each unix timestamp is the start of a 30-minute slot, with the number of events in that slot |
{
"datefrom": 1374972247,
"dateto": 1375058647,
"events": [
{
"label": "Failed",
"data": []
},
{
"label": "Changed",
"data": [
[ 1375007400, 1 ],
[ 1375009200, 2 ]
]
},
{
"label": "Succeeded",
"data": [
[ 1375014600, 1 ]
]
}
]
}
dismiss
Dismiss the given active event so it doesn’t show up in the event list if active filter is set to 2. This method accepts POST only, as it changes state.
Arguments
| id | number | required | The event id to dismiss |
curl -b ~/.mmonit/cookie \
-d "id=723" \
http://127.0.0.1:8080/api/2/reports/events/dismiss
Output
On success, HTTP 200 with an empty body.
Errors
| 400 | The id is missing or malformed |
| 403 | The event is on a host the user may not view |
| 404 | No such event |
The error body is a JSON object, for example {“error”:“Event 723 does not exist”}.
notice
Add a note to the given event. The note is stored with the current time and the name of the logged-in user, and the event’s note flag is set. This method accepts POST only.
Arguments
| id | number | required | The event id |
| notice | string | optional | The note text, up to 10240 characters. Without it the request does nothing and answers HTTP 200, also for an unknown event |
curl -b ~/.mmonit/cookie \
-d "id=723" -d "notice=Disk replaced" \
http://127.0.0.1:8080/api/2/reports/events/notice
Output
On success, HTTP 200 with an empty body.
Errors
| 400 | The id is missing or malformed, or the note is longer than 10240 characters |
| 403 | The event is on a host the user may not view |
| 404 | No such event |
The error body is a JSON object, for example {“error”:“Event 723 does not exist”}.