Last active
August 29, 2015 14:08
-
-
Save ProfAvery/5220d8afb02d3e975b70 to your computer and use it in GitHub Desktop.
Generate fake log entries to stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* genlogs.c - Generate fake log entries to stdout */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <unistd.h> | |
#define DATE_MAX_CHARS 25 | |
#define SIZE(a) (sizeof(a) / sizeof(*(a))) | |
char *messages[] = { | |
"%s %s Invalid user %s\n", | |
"%s %s Failed password for %s\n", | |
"%s %s pam_unix(sshd:session)Session opened for user %s\n", | |
"%s %s pam_unix(sshd: session) Session closed for user %s\n", | |
"%s %s Accepted password for %s\n", | |
"%s %s sudo: %s ; TTY=pts/0 ; PWD=/ ; USER=root ; COMMAND=/bin/su\n", | |
"%s %s running '/usr/local/repo-check.py' with root privileges on behalf of '%s'\n", | |
"%s %s session opened for user %s by (uid=0)\n", | |
}; | |
char *levels[] = { | |
"ERROR", | |
"WARNING", | |
"INFO", | |
"DEBUG", | |
"TRACE", | |
}; | |
char *users[] = { | |
"doc", | |
"grumpy", | |
"happy", | |
"sleepy", | |
"bashful", | |
"sneezy", | |
"dopey", | |
}; | |
int main(int argc, char *argv[]) | |
{ | |
int delay = 1; | |
time_t now; | |
struct tm *timestamp; | |
char date[DATE_MAX_CHARS]; | |
int l, m, u; | |
if (argc > 1) { | |
delay = atoi(argv[1]); | |
} | |
setbuf(stdout, NULL); | |
for (;;) { | |
now = time(NULL); | |
timestamp = localtime(&now); | |
strftime(date, DATE_MAX_CHARS, "[%F %T]", timestamp); | |
m = rand() % SIZE(messages); | |
l = rand() % SIZE(levels); | |
u = rand() % SIZE(users); | |
printf(messages[m], date, levels[l], users[u]); | |
sleep(delay); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment