C

LogHive provides a simple REST API that you can use to push events and errors. Here is an example code for C:

Push Event

#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>

int main(void)
{
    CURL *curl;
    CURLcode res;
    char *data = "{\"project\":\"MySaas\",\"group\":\"YourGroupName\",\"event\":\"YourEventName\",\"description\":\"YourDescription\",\"notify\":true}";
    char *url = "https://api.loghive.app/v1/event/add";
    char *content_type = "Content-Type: application/json";
    char *authorization = "ApiKey: your-api-key";
    struct curl_slist *header_list = NULL;
    header_list = curl_slist_append(header_list, content_type);
    header_list = curl_slist_append(header_list, authorization);

    curl = curl_easy_init();
    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);

        res = curl_easy_perform(curl);
        if (res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));

        curl_easy_cleanup(curl);
        curl_slist_free_all(header_list);
    }

    return 0;
}

Push Insight

#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>

int main(void)
{
    CURL *curl;
    CURLcode res;
    char *data = "{\"project\":\"MySaas\",\"insight\":\"system1-online\",\"value\":1}";
    char *url = "https://api.loghive.app/v1/insight/add";
    char *content_type = "Content-Type: application/json";
    char *authorization = "ApiKey: your-api-key";
    struct curl_slist *header_list = NULL;
    header_list = curl_slist_append(header_list, content_type);
    header_list = curl_slist_append(header_list, authorization);

    curl = curl_easy_init();
    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);

        res = curl_easy_perform(curl);
        if (res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));

        curl_easy_cleanup(curl);
        curl_slist_free_all(header_list);
    }

    return 0;
}

Last updated