1 /*
2 * Copyright (c) 2014, Juniper Networks, Inc.
3 * All rights reserved.
4 * This SOFTWARE is licensed under the LICENSE provided in the
5 * ../Copyright file. By downloading, installing, copying, or otherwise
6 * using the SOFTWARE, you agree to be bound by the terms of that
7 * LICENSE.
8 * Phil Shafer, July 2014
9 */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <unistd.h>
15 #include <errno.h>
16 #include <time.h>
17 #include <ctype.h>
18 #include <syslog.h>
19
20 #include "xo.h"
21
22 void
test_syslog_open(void)23 test_syslog_open (void)
24 {
25 printf("syslog open\n");
26 }
27
28 void
test_syslog_close(void)29 test_syslog_close (void)
30 {
31 printf("syslog close\n");
32 }
33
34 void
test_syslog_send(const char * full_msg,const char * v0_hdr,const char * text_only)35 test_syslog_send (const char *full_msg, const char *v0_hdr,
36 const char *text_only)
37 {
38 printf("{{%s}}\n{{%s}}\n{{%s}}\n\n", full_msg, v0_hdr, text_only);
39 }
40
41 int
main(int argc,char ** argv)42 main (int argc, char **argv)
43 {
44 int unit_test = 1;
45 int fire = 0;
46 const char *tzone = "EST";
47
48 argc = xo_parse_args(argc, argv);
49 if (argc < 0)
50 return 1;
51
52 for (argc = 1; argv[argc]; argc++) {
53 if (strcmp(argv[argc], "full") == 0)
54 unit_test = 0;
55 else if (strcmp(argv[argc], "fire") == 0)
56 fire = 1;
57 else if (strcmp(argv[argc], "tz") == 0)
58 tzone = argv[++argc];
59 }
60
61 setenv("TZ", tzone, 1);
62 tzset();
63
64 if (!fire) {
65 xo_set_syslog_handler(test_syslog_open, test_syslog_send,
66 test_syslog_close);
67 }
68
69 if (unit_test) {
70 xo_set_unit_test_mode(1);
71 xo_open_log("test-program", LOG_PERROR, 0);
72 }
73
74 xo_set_version("3.1.4");
75 xo_set_syslog_enterprise_id(42); /* SunOs */
76
77 xo_open_container_h(NULL, "top");
78
79 xo_syslog(LOG_INFO | LOG_KERN, "animal-status",
80 "The {:animal} is {:state}", "snake", "loose");
81 xo_syslog(LOG_INFO | LOG_MAIL, "animal-consumed",
82 "My {:animal} ate your {:pet}", "snake", "hamster");
83 xo_syslog(LOG_NOTICE | LOG_DAEMON, "animal-talk",
84 "{:count/%d} {:animal} said {:quote}", 1, "owl", "\"e=m\\c[2]\"");
85
86 /*
87 <165>1 2003-10-11T22:14:15.003Z mymachine.example.com
88 evntslog - ID47 [exampleSDID@32473 iut="3" eventSource=
89 "Application" eventID="1011"] BOMAn application
90 event log entry...
91
92 This example is modeled after Example 1. However, this time it
93 contains STRUCTURED-DATA, a single element with the value
94 "[exampleSDID@32473 iut="3" eventSource="Application"
95 eventID="1011"]". The MSG itself is "An application event log
96 entry..." The BOM at the beginning of MSG indicates UTF-8 encoding.
97 */
98
99 xo_set_syslog_enterprise_id(32473);
100 xo_syslog(LOG_LOCAL4 | LOG_NOTICE, "ID47",
101 "{e:iut/%u}An {:event-source} {:event-id/%u} log entry",
102 3, "application", 1011);
103
104 xo_close_container_h(NULL, "top");
105
106 xo_finish();
107
108 return 0;
109 }
110