Closed SamKr closed 1 week ago
Adding routes for the syslogs in on the list of todo items. For now you can use the custom method to implement this.
It is a bit unclear to me what the difference and overlap exactly is between the syslogs and the alarms and events. If anyone has thoughts on this, please do share them here.
Thanks @malle-pietje, I'll run a syslog server for a while and see if any pattern comes up from that.
Custom API request is working like a charm as well in the meantime, great example script :)
For those who are looking for it (I use the script as scriptname.php $siteId
):
<?php
/**
* PHP API usage example
*
* contributed by: Art of WiFi
* description: example basic PHP script to execute a custom API request using the
* custom_api_request() function/method
*/
/**
* using the composer autoloader
*/
require_once 'vendor/autoload.php';
/**
* include the config file (place your credentials etc. there if not already present)
* see the config.template.php file for an example
*/
require_once 'config.php';
/**
* The site to authorize the device with
* https://github.com/Art-of-WiFi/UniFi-API-client#important-notes
*/
$site_id = isset($argv[1]) ? $argv[1] : 'default';
/**
* Current timestamp in milliseconds
*/
$timestamp = round(microtime(true) * 1000);
/**
* parameters
*/
$url = '/v2/api/site/' . $site_id . '/system-log/system-critical-alert';
$request_method = 'POST';
$payload = [
'timestampFrom' => 0,
'timestampTo' => $timestamp,
'pageSize' => 100,
'categories' => ["INTERNET","POWER","DEVICES","SYSTEM"],
'pageNumber' => 0,
'systemLogDeviceTypes' => ["GATEWAYS","SWITCHES","ACCESS_POINT","SMART_POWER","BUILDING_TO_BUILDING_BRIDGES","UNIFI_LTE","NON_NETWORK_DEVICES"]
];
$return = 'array';
/**
* initialize the UniFi API connection class and log in to the controller and do our thing
*/
$unifi_connection = new UniFi_API\Client(
$controlleruser,
$controllerpassword,
$controllerurl,
$site_id,
$controllerversion
);
$set_debug_mode = $unifi_connection->set_debug($debug);
$loginresults = $unifi_connection->login();
$results = $unifi_connection->custom_api_request($url, $request_method, $payload, $return);
/**
* provide feedback in JSON format or as PHP Object
*/
echo json_encode($results, JSON_PRETTY_PRINT);
//print_r($results);
Edit: the script now fetches the current timestamp itself, since that's what you probably need.
@SamKr thanks for sharing! Nice đź‘Ť
Wanted to add a note that a method has been added to handle the various syslog “classes”. See this commit for details: https://github.com/Art-of-WiFi/UniFi-API-client/commit/70f6a374e2c73eb91a9aa20f6c9375b235d55ce1
Alarms and events are coming in perfectly through the API client. However, it appears one alarm is missing, that we do receive per email. I don't know if that's because UniFi triggers this at a later/different point in the process, so it never shows up in the regular alarmlist, or if perhaps some other function should be used. I've been unable to find it anywhere in the API browser.
This is the email in question:
When I go to the UniFi controller's webportal, the notification is there as well in
System Log
->Critical
:Multiple devices are using the same IP address: {redacted}. Please check each device's configuration to ensure none are communicating with a rogue DHCP server.
Url:
https://{redacted}:8443/manage/{redacted}/syslog/systemCritical
Any idea on this?