2 * Copyright (c) 2018, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <mon_internal.h>
42 // Monitoring common code
44 struct mon_cmd_entry {
49 struct mon_opt_entry {
55 /* Table of commands */
56 struct mon_cmd_entry mon_cmd_table[] = {
57 { MON_CMD_SHOW, "show" },
58 { MON_CMD_UNKNOWN } /* list terminator */
61 /* Table of options */
62 struct mon_opt_entry mon_opt_table[] = {
63 { OPT_TYPE_SHOW_VERSION, MON_CMD_SHOW, "version" },
64 { OPT_TYPE_SHOW_CONFIG_FILES, MON_CMD_SHOW, "config_files" },
65 { OPT_TYPE_SHOW_UPTIME, MON_CMD_SHOW, "uptime" },
66 { OPT_TYPE_SHOW_TID_REQS_PROCESSED, MON_CMD_SHOW, "tid_reqs_processed" },
67 { OPT_TYPE_SHOW_TID_REQS_FAILED, MON_CMD_SHOW, "tid_reqs_failed" },
68 { OPT_TYPE_SHOW_TID_REQS_PENDING, MON_CMD_SHOW, "tid_reqs_pending" },
69 { OPT_TYPE_SHOW_TID_ERROR_COUNT, MON_CMD_SHOW, "tid_error_count" },
70 { OPT_TYPE_SHOW_ROUTES, MON_CMD_SHOW, "routes" },
71 { OPT_TYPE_SHOW_PEERS, MON_CMD_SHOW, "peers" },
72 { OPT_TYPE_SHOW_COMMUNITIES, MON_CMD_SHOW, "communities" },
73 { OPT_TYPE_SHOW_REALMS, MON_CMD_SHOW, "realms" },
74 { OPT_TYPE_SHOW_RP_CLIENTS, MON_CMD_SHOW, "rp_clients" },
75 { OPT_TYPE_UNKNOWN } /* list terminator */
80 static struct mon_cmd_entry *find_cmd_entry(MON_CMD code)
82 struct mon_cmd_entry *entry;
84 for (entry=mon_cmd_table; entry->code != MON_CMD_UNKNOWN; entry++) {
85 if (entry->code == code)
92 const char *mon_cmd_to_string(MON_CMD cmd)
94 struct mon_cmd_entry *entry = find_cmd_entry(cmd);
102 MON_CMD mon_cmd_from_string(const char *s)
104 struct mon_cmd_entry *entry;
106 for (entry=mon_cmd_table; entry->code != MON_CMD_UNKNOWN; entry++) {
107 if (strcmp(s, entry->name) == 0)
111 return MON_CMD_UNKNOWN;
116 static struct mon_opt_entry *find_opt_entry(MON_OPT_TYPE code)
118 struct mon_opt_entry *entry;
120 for (entry=mon_opt_table; entry->code != OPT_TYPE_UNKNOWN; entry++) {
121 if (entry->code == code)
128 const char *mon_opt_type_to_string(MON_OPT_TYPE opt_type)
130 struct mon_opt_entry *entry = find_opt_entry(opt_type);
138 MON_OPT_TYPE mon_opt_type_from_string(const char *s)
140 struct mon_opt_entry *entry;
142 for (entry=mon_opt_table; entry->code != OPT_TYPE_UNKNOWN; entry++) {
143 if (strcmp(s, entry->name) == 0)
147 return OPT_TYPE_UNKNOWN;