Path: blob/main/contrib/libxo/tests/core/test_11.c
39537 views
/*1* Copyright (c) 2014, Juniper Networks, Inc.2* All rights reserved.3* This SOFTWARE is licensed under the LICENSE provided in the4* ../Copyright file. By downloading, installing, copying, or otherwise5* using the SOFTWARE, you agree to be bound by the terms of that6* LICENSE.7* Phil Shafer, July 20148*/910#include <stdio.h>11#include <stdlib.h>12#include <string.h>13#include <unistd.h>14#include <errno.h>15#include <time.h>16#include <ctype.h>17#include <syslog.h>1819#include "xo.h"20#include "xo_encoder.h"2122void23test_syslog_open (void)24{25printf("syslog open\n");26}2728void29test_syslog_close (void)30{31printf("syslog close\n");32}3334void35test_syslog_send (const char *full_msg, const char *v0_hdr,36const char *text_only)37{38printf("{{%s}}\n{{%s}}\n{{%s}}\n\n", full_msg, v0_hdr, text_only);39}4041int42main (int argc, char **argv)43{44int unit_test = 1;45int fire = 0;46const char *tzone = "EST";4748argc = xo_parse_args(argc, argv);49if (argc < 0)50return 1;5152for (argc = 1; argv[argc]; argc++) {53if (xo_streq(argv[argc], "full"))54unit_test = 0;55else if (xo_streq(argv[argc], "fire"))56fire = 1;57else if (xo_streq(argv[argc], "tz"))58tzone = argv[++argc];59}6061setenv("TZ", tzone, 1);62tzset();6364if (!fire) {65xo_set_syslog_handler(test_syslog_open, test_syslog_send,66test_syslog_close);67}6869if (unit_test) {70xo_set_unit_test_mode(1);71xo_open_log("test-program", LOG_PERROR, 0);72}7374xo_set_version("3.1.4");75xo_set_syslog_enterprise_id(42); /* SunOs */7677xo_open_container_h(NULL, "top");7879xo_syslog(LOG_INFO | LOG_KERN, "animal-status",80"The {:animal} is {:state}", "snake", "loose");81xo_syslog(LOG_INFO | LOG_MAIL, "animal-consumed",82"My {:animal} ate your {:pet}", "snake", "hamster");83xo_syslog(LOG_NOTICE | LOG_DAEMON, "animal-talk",84"{:count/%d} {:animal} said {:quote}", 1, "owl", "\"e=m\\c[2]\"");8586/*87<165>1 2003-10-11T22:14:15.003Z mymachine.example.com88evntslog - ID47 [exampleSDID@32473 iut="3" eventSource=89"Application" eventID="1011"] BOMAn application90event log entry...9192This example is modeled after Example 1. However, this time it93contains STRUCTURED-DATA, a single element with the value94"[exampleSDID@32473 iut="3" eventSource="Application"95eventID="1011"]". The MSG itself is "An application event log96entry..." The BOM at the beginning of MSG indicates UTF-8 encoding.97*/9899xo_set_syslog_enterprise_id(32473);100xo_syslog(LOG_LOCAL4 | LOG_NOTICE, "ID47",101"{e:iut/%u}An {:event-source} {:event-id/%u} log entry",1023, "application", 1011);103104xo_close_container_h(NULL, "top");105106xo_finish();107108return 0;109}110111112