예제 #1
0
/* Flush logs (for example, at the end of a purge pass or after dumping stats) */
void FlushLogs(  )
{
    log_init_check(  );

    flush_log_descr( &log );
    flush_log_descr( &report );
    flush_log_descr( &alert );
}
예제 #2
0
/* Flush logs (for example, at the end of a purge pass or after dumping
 * stats) */
void FlushLogs(void)
{
    log_init_check();

    flush_log_descr(&log);
    flush_log_descr(&report);
    flush_log_descr(&alert);
#ifdef HAVE_CHANGELOGS
    flush_log_descr(&chglogs);
#endif
}
예제 #3
0
void DisplayReport(const char *format, ...)
{
    va_list args;

    va_start(args, format);
    display_line_log(&report, NULL, format, args);
    va_end(args);

    /* always flush reports, because we don't want to lose events */
    flush_log_descr(&report);

}   /* DisplayReport */
예제 #4
0
void vDisplayLogFn(log_level debug_level, const char *tag, const char *format,
                   va_list ap)
{
    time_t now = time(NULL);

    if (log_config.debug_level >= debug_level) {
        display_line_log(&log, tag, format, ap);

        /* test if it's time to flush.
         * Also flush major errors, to display it immediately. */
        if ((now - last_time_flush_log) > TIME_FLUSH_LOG
            || debug_level >= LVL_MAJOR) {
            flush_log_descr(&log);
            last_time_flush_log = now;
        }
    }
}
예제 #5
0
void RaiseAlert(const char *title, const char *format, ...)
{
    va_list     args;
    char        mail[MAX_MAIL_LEN];
    char        title2[1024];
    int         written;
    time_t      now = time(NULL);
    struct tm   date;

    log_init_check();

    /* send alert mail, if an address was specified in config file */
    if (!EMPTY_STRING(log_config.alert_mail)) {
        localtime_r(&now, &date);
        written = snprintf(mail, MAX_MAIL_LEN,
                           "===== %s =====\n"
                           "Date: %.4d/%.2d/%.2d %.2d:%.2d:%.2d\n"
                           "Program: %s (pid %lu)\n"
                           "Host: %s\n"
                           "Filesystem: %s\n",
                           title, 1900 + date.tm_year, date.tm_mon + 1,
                           date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec,
                           prog_name, (unsigned long)getpid(), machine_name,
                           global_config.fs_path);

        va_start(args, format);
        vsnprintf(mail + written, MAX_MAIL_LEN - written, format, args);
        va_end(args);

        snprintf(title2, 1024, "%s (%s on %s)", title, global_config.fs_path,
                 machine_name);
        SendMail(log_config.alert_mail, title2, mail);
    }

    if (!EMPTY_STRING(log_config.alert_file)) {
        display_line_log_(&alert, "ALERT", "%s", title);
        va_start(args, format);
        display_line_log(&alert, "ALERT", format, args);
        va_end(args);

        /* always flush alerts, because we don't want to lose events */
        flush_log_descr(&alert);
    }

}   /* DisplayAlert */
예제 #6
0
void DisplayLog( int debug_level, const char *tag, const char *format, ... )
{
    time_t         now = time( NULL );
    va_list        args;

    if ( log_config.debug_level >= debug_level )
    {
        va_start( args, format );
        display_line_log( &log, tag, format, args );
        va_end( args );

        /* test if its time to flush. Also flush major errors, to display it immediately. */
        if ( (now - last_time_flush_log > TIME_FLUSH_LOG)
             || (debug_level >= LVL_MAJOR) )
        {
            flush_log_descr( &log );
            last_time_flush_log = now;
        }
    }
}                               /* DisplayLog */
예제 #7
0
/* Flush batched alerts.
 * Must be called under the protection of alert_mutex
 * release mutex ASAP if release_mutex_asap is true,
 * else: don't release it.
 */
static void FlushAlerts(bool release_mutex_asap)
{
    alert_type_t   *pcurr;
    unsigned int    alert_types = 0;
    unsigned int    mail_size = 0;
    char            title[MAIL_TITLE_MAX];
    GString        *contents = NULL;
    time_t          now;
    struct tm       date;

    /* first list scan, to determine the number of alerts, etc... */
    for (pcurr = alert_list; pcurr != NULL; pcurr = pcurr->next) {
        alert_types++;
        mail_size += pcurr->estim_size;
    }

    if (alert_count == 0) {
        if (release_mutex_asap)
            V(alert_mutex);
        return;
    }

    now = time(NULL);
    localtime_r(&now, &date);

    snprintf(title, MAIL_TITLE_MAX,
             "robinhood alert summary (%s on %s): %u alerts",
             global_config.fs_path, machine_name, alert_count);

    contents = g_string_new("");
    g_string_printf(contents, "Date: %.4d/%.2d/%.2d %.2d:%.2d:%.2d\n"
                    "Program: %s (pid %lu)\n"
                    "Host: %s\n"
                    "Filesystem: %s\n",
                    1900 + date.tm_year, date.tm_mon + 1, date.tm_mday,
                    date.tm_hour, date.tm_min, date.tm_sec, prog_name,
                    (unsigned long)getpid(), machine_name,
                    global_config.fs_path);

    g_string_append(contents, "\n===== alert summary ====\n\n");
    g_string_append_printf(contents, "%u alerts:\n", alert_count);

    for (pcurr = alert_list; pcurr != NULL; pcurr = pcurr->next) {
        g_string_append_printf(contents, "\t* %u %s\n", pcurr->count,
                               pcurr->title);
    }

    for (pcurr = alert_list; pcurr != NULL;) {
        unsigned int i;

        g_string_append_printf(contents, "\n==== alert '%s' ====\n\n",
                               pcurr->title);

        for (i = 0; i < pcurr->count; i++) {
            /* print and free */
            if (pcurr->entries[i]) {
                g_string_append_printf(contents, "%s\n", pcurr->entries[i]);
                if (log_config.alert_show_attrs)
                    g_string_append_printf(contents, "Entry info:\n%s\n",
                                           pcurr->info[i]);

                free(pcurr->entries[i]);
                free(pcurr->info[i]);
            }
        }
        /* free the list of entries */
        free(pcurr->entries);
        free(pcurr->info);

        /* set the list to the next item */
        alert_list = pcurr->next;
        /* free the item */
        free(pcurr);
        /* next item */
        pcurr = alert_list;
    }

    /* reset alert count */
    alert_count = 0;

    /* all alerts has been released, we can put the lock */
    if (release_mutex_asap)
        V(alert_mutex);

    /* send the mail and/or write the alert in alert file */
    if (!EMPTY_STRING(log_config.alert_mail))
        SendMail(log_config.alert_mail, title, contents->str);

    if (!EMPTY_STRING(log_config.alert_file)) {
        if (alert.log_type == RBH_LOG_SYSLOG) {
            /* we need to split the content after each '\n' */
            char *curr = contents->str;
            char *next = NULL;
            display_line_log_(&alert, "ALERT", "=== ALERT REPORT ===");
            do {
                next = strchr(curr, '\n');
                if (next != NULL) {
                    next[0] = '\0';
                    next++;
                }
                display_line_log_(&alert, "ALERT", curr);
                curr = next;
            } while (curr != NULL);
            display_line_log_(&alert, "ALERT", "=== END OF ALERT REPORT ===");
        } else {
            display_line_log_(&alert, "ALERT", "=== ALERT REPORT ===\n%s",
                              contents->str);
            display_line_log_(&alert, "ALERT", "=== END OF ALERT REPORT ===");
        }

        /* always flush alerts, because we don't want to lose events */
        flush_log_descr(&alert);
    }

    g_string_free(contents, TRUE);
    /* mutex already released, can go out now */

}   /*  Flush alerts */