xref: /freebsd/contrib/libxo/tests/core/test_11.c (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
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 #include "xo_encoder.h"
22 
23 void
24 test_syslog_open (void)
25 {
26     printf("syslog open\n");
27 }
28 
29 void
30 test_syslog_close (void)
31 {
32     printf("syslog close\n");
33 }
34 
35 void
36 test_syslog_send (const char *full_msg, const char *v0_hdr,
37 		  const char *text_only)
38 {
39     printf("{{%s}}\n{{%s}}\n{{%s}}\n\n", full_msg, v0_hdr, text_only);
40 }
41 
42 int
43 main (int argc, char **argv)
44 {
45     int unit_test = 1;
46     int fire = 0;
47     const char *tzone = "EST";
48 
49     argc = xo_parse_args(argc, argv);
50     if (argc < 0)
51 	return 1;
52 
53     for (argc = 1; argv[argc]; argc++) {
54 	if (xo_streq(argv[argc], "full"))
55 	    unit_test = 0;
56 	else if (xo_streq(argv[argc], "fire"))
57 	    fire = 1;
58 	else if (xo_streq(argv[argc], "tz"))
59 	    tzone = argv[++argc];
60     }
61 
62     setenv("TZ", tzone, 1);
63     tzset();
64 
65     if (!fire) {
66 	xo_set_syslog_handler(test_syslog_open, test_syslog_send,
67 			      test_syslog_close);
68     }
69 
70     if (unit_test) {
71 	xo_set_unit_test_mode(1);
72 	xo_open_log("test-program", LOG_PERROR, 0);
73     }
74 
75     xo_set_version("3.1.4");
76     xo_set_syslog_enterprise_id(42); /* SunOs */
77 
78     xo_open_container_h(NULL, "top");
79 
80     xo_syslog(LOG_INFO | LOG_KERN, "animal-status",
81 	      "The {:animal} is {:state}", "snake", "loose");
82     xo_syslog(LOG_INFO | LOG_MAIL, "animal-consumed",
83 	      "My {:animal} ate your {:pet}", "snake", "hamster");
84     xo_syslog(LOG_NOTICE | LOG_DAEMON, "animal-talk",
85 	      "{:count/%d} {:animal} said {:quote}", 1, "owl", "\"e=m\\c[2]\"");
86 
87     /*
88       <165>1 2003-10-11T22:14:15.003Z mymachine.example.com
89            evntslog - ID47 [exampleSDID@32473 iut="3" eventSource=
90            "Application" eventID="1011"] BOMAn application
91            event log entry...
92 
93    This example is modeled after Example 1.  However, this time it
94    contains STRUCTURED-DATA, a single element with the value
95    "[exampleSDID@32473 iut="3" eventSource="Application"
96    eventID="1011"]".  The MSG itself is "An application event log
97    entry..."  The BOM at the beginning of MSG indicates UTF-8 encoding.
98     */
99 
100     xo_set_syslog_enterprise_id(32473);
101     xo_syslog(LOG_LOCAL4 | LOG_NOTICE, "ID47",
102 	      "{e:iut/%u}An {:event-source} {:event-id/%u} log entry",
103 	      3, "application", 1011);
104 
105     xo_close_container_h(NULL, "top");
106 
107     xo_finish();
108 
109     return 0;
110 }
111