2 * collectd - src/freeswitch.c
3 * Copyright (C) 2005-2007 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
20 * Leon de Rooij <leon@scarlet-internet.nl>
28 #include "utils_match.h"
32 #define FREESWITCH_DEF_HOST "127.0.0.1"
33 #define FREESWITCH_DEF_PORT "8021"
34 #define FREESWITCH_DEF_PASSWORD "ClueCon"
36 static const char *config_keys[] =
42 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
44 typedef struct profilename
47 struct profilename *next;
50 static esl_handle_t handle = {{0}};
51 // static int thread_running = 0;
53 static char *freeswitch_host = NULL;
54 static char freeswitch_port[16];
55 static char *freeswitch_password = NULL;
57 static void freeswitch_submit (const char *profile, const char *type, gauge_t inbound, gauge_t outbound)
60 value_list_t vl = VALUE_LIST_INIT;
62 values[0].gauge = inbound;
63 values[1].gauge = outbound;
67 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
68 sstrncpy (vl.plugin, "freeswitch", sizeof (vl.plugin));
69 sstrncpy (vl.type, type, sizeof (vl.type));
70 sstrncpy (vl.type_instance, profile, sizeof (vl.type_instance));
72 plugin_dispatch_values (&vl);
73 } /* void freeswitch_submit */
75 static int freeswitch_read (void)
81 /* Set some default configuration variables */
82 host = freeswitch_host;
84 host = FREESWITCH_DEF_HOST;
86 port = freeswitch_port;
88 port = FREESWITCH_DEF_PORT;
90 password = freeswitch_password;
92 password = FREESWITCH_DEF_PASSWORD;
96 esl_send_recv(&handle, "api show channels\n\n");
97 if (handle.last_sr_event && handle.last_sr_event->body) {
98 DEBUG ("OUTPUT FROM FREESWITCH:\n%s\n\n", handle.last_sr_event->body);
101 freeswitch_submit ("res-public", "fs_channels", 3, 5);
104 } /* int freeswitch_read */
106 static int freeswitch_config (const char *key, const char *value)
108 if (strcasecmp ("Host", key) == 0)
110 if (freeswitch_host != NULL)
111 free (freeswitch_host);
112 freeswitch_host = strdup (value);
114 else if (strcasecmp ("Port", key) == 0)
116 int port = (int) (atof (value));
117 if ((port > 0) && (port <= 65535))
118 ssnprintf (freeswitch_port, sizeof (freeswitch_port),
121 sstrncpy (freeswitch_port, value, sizeof (freeswitch_port));
123 else if (strcasecmp ("Password", key) == 0)
125 if (freeswitch_password != NULL)
126 free (freeswitch_password);
127 freeswitch_password = strdup (value);
134 } /* int freeswitch_config */
137 static void *msg_thread_run(esl_thread_t *me, void *obj)
139 esl_handle_t *handle = (esl_handle_t *) obj;
142 // Maybe do some more in this loop later, like receive subscribed events,
143 // and create statistics of them
144 // see fs_cli.c function static void *msg_thread_run(), around line 198
145 while (thread_running && handle->connected)
147 esl_status_t status = esl_recv_event_timed(handle, 10, 1, NULL);
148 if (status == ESL_FAIL)
150 //DEBUG ("Disconnected [%s]\n", ESL_LOG_WARNING); // todo fixit
151 DEBUG ("Disconnected [%s]\n", "ESL_LOG_WARNING");
159 } */ /* void *msg_thread_run */
161 static int freeswitch_init (void)
163 esl_connect(&handle, "172.16.235.98", 8021, "ClueCon");
164 //esl_thread_create_detached(msg_thread_run, &handle);
166 } /* int freeswitch_init */
168 void module_register (void)
170 plugin_register_config ("freeswitch", freeswitch_config,
171 config_keys, config_keys_num);
172 plugin_register_init ("freeswitch", freeswitch_init);
173 plugin_register_read ("freeswitch", freeswitch_read);
174 } /* void module_register */