Client library for Logz.io API, see below for supported endpoints.
The primary purpose of this library is to act as the API interface for the logz.io Terraform provider. To use it, you'll need to create an API token and provide it to the client library along with your logz.io regional API server address.
Note: the lastest version of the API (1.3) is not backwards compatible with previous versions, specifically the client entrypoint names have changed to prevent naming conflicts. Use UsersClient
(Users API) ,SubaccountClient
(Sub-accounts API), AlertsClient
(Alerts API) and EndpointsClient
(Endpoints API) rather than Users
, Alerts
and Endpoints
.
To create an alert where the type field = 'mytype' and the loglevel field = ERROR, see the logz.io docs for more info
https://support.logz.io/hc/en-us/articles/209487329-How-do-I-create-an-Alert-
client, _ := alerts.New(apiToken, apiServerAddress)
alert := client.CreateAlert(alerts.CreateAlertType{
Title: "this is my alert",
Description: "this is my description",
QueryString: "loglevel:ERROR",
Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
alerts.SeverityHigh,
10,
},
},
SearchTimeFrameMinutes: 0,
NotificationEmails: []interface{}{},
IsEnabled: true,
SuppressNotificationsMinutes: 0,
ValueAggregationType: alerts.AggregationTypeCount,
ValueAggregationField: nil,
GroupByAggregationFields: []interface{}{"my_field"},
AlertNotificationEndpoints: []interface{}{},
})
function | func name |
---|---|
create alert | func (c *AlertsClient) CreateAlert(alert CreateAlertType) (*AlertType, error) |
update alert | func (c *AlertsClient) UpdateAlert(alertId int64, alert CreateAlertType) (*AlertType, error) |
delete alert | func (c *AlertsClient) DeleteAlert(alertId int64) error |
get alert (by id) | func (c *AlertsClient) GetAlert(alertId int64) (*AlertType, error) |
list alerts | func (c *AlertsClient) ListAlerts() ([]AlertType, error) |
To create a new user, on a specific account or sub-account. you'll need your account Id.
client, _ := users.New(apiToken, apiServerAddress)
user := client.User{
Username: "[email protected]",
Fullname: "my username",
AccountId: 123456,
Roles: []int32{users.UserTypeUser},
}
function | func name |
---|---|
create user | func (c *UsersClient) CreateUser(user User) (*User, error) |
update user | func (c *UsersClient) UpdateUser(user User) (*User, error) |
delete user | func (c *UsersClient) DeleteUser(id int32) error |
get user | func (c *UsersClient) GetUser(id int32) (*User, error) |
list users | func (c *UsersClient) ListUsers() ([]User, error) |
suspend user | func (c *UsersClient) SuspendUser(userId int32) (bool, error) |
unsuspend user | func (c *UsersClient) UnSuspendUser(userId int32) (bool, error) |
To create a new sub-account, on a main account.
client, _ := sub_accounts.New(apiToken, apiServerAddress)
subaccount := sub_accounts.SubAccountCreate{
Email: "[email protected]",
AccountName: "my account name",
MaxDailyGB: 6.5,
RetentionDays: 4,
Searchable: true,
Accessible: false,
SharingObjectAccounts: []int32{accountId1, accountId2}, //Id's of the accounts who will be able to access this account
DocSizeSetting: true,
}
function | func name |
---|---|
create sub-account | func (c *SubAccountClient) CreateSubAccount(subAccount SubAccountCreate) (*SubAccount, error) |
update sub-account | func (c *SubAccountClient) UpdateSubAccount(id int64, subAccount SubAccount) error |
delete sub-account | func (c *SubAccountClient) DeleteSubAccount(id int64) error |
get sub-account | func (c *SubAccountClient) GetSubAccount(id int64) (*SubAccount, error) |
get detailed sub-account | func (c *SubAccountClient) GetDetailedSubAccount(id int64) (*SubAccountDetailed, error) |
list sub-accounts | func (c *SubAccountClient) ListSubAccounts() ([]SubAccount, error) |
list detailed sub-accounts | func (c *SubAccountClient) DetailedSubAccounts() ([]SubAccountDetailed, error) |
For each type of endpoint there is a different structure, below you can find an example for creating a Slack endpoint. For more info, see: https://docs.logz.io/api/#tag/Manage-notification-endpoints or check our endpoints tests for more examples.
client, _ := endpoints.New(apiToken, apiServerAddress)
endpoint, err := underTest.CreateEndpoint(endpoints.Endpoint{
Title: "some_endpoint",
Description: "my description",
Url: "https://this.is.com/some/webhook",
EndpointType: endpoints.EndpointTypeSlack,
})
- Clone this repo locally
- As this package uses Go modules, make sure you are outside of
$GOPATH
or you have theGO111MODULE=on
environment variable set. Then rungo get
to pull down the dependencies.
go test -v -race ./...
- v1.3.2
- fix client custom endpoint headers bug
- improve tests
- v1.3
- unnecessary resource updates bug fix.
- support tags in alerts
- v1.2
- Add subaccount support