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>
27 #include "utils_match.h"
31 #define FREESWITCH_DEF_HOST "127.0.0.1"
32 #define FREESWITCH_DEF_PORT "8021"
33 #define FREESWITCH_DEF_PASSWORD "ClueCon"
35 static const char *config_keys[] =
41 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
43 typedef struct profilename
46 struct profilename *next;
49 // static profilename_t *first_profilename = NULL;
50 static char *freeswitch_host = NULL;
51 static char freeswitch_port[16];
52 static char *freeswitch_password = NULL;
54 static void freeswitch_submit (const char *type_instance, gauge_t inbound, gauge_t outbound)
57 value_list_t vl = VALUE_LIST_INIT;
59 values[0].gauge = inbound;
60 values[1].gauge = outbound;
64 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
65 sstrncpy (vl.plugin, "freeswitch", sizeof (vl.plugin));
66 sstrncpy (vl.type, "freeswitch", sizeof (vl.type));
67 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
69 plugin_dispatch_values (&vl);
70 } /* void freeswitch_submit */
72 static int freeswitch_read (void)
78 host = freeswitch_host;
80 host = FREESWITCH_DEF_HOST;
82 port = freeswitch_port;
84 port = FREESWITCH_DEF_PORT;
86 password = freeswitch_password;
88 password = FREESWITCH_DEF_PASSWORD;
91 esl_handle_t handle = {{0}};
92 esl_connect(&handle, host, port, password);
94 esl_send_recv(&handle, "api show channels\n\n");
97 // DO YOUR THING HERE TO PARSE &handle
100 esl_disconnect(&handle);
103 freeswitch_submit ("profilename", 0, 0);
106 } /* int freeswitch_read */
108 static int freeswitch_config (const char *key, const char *value)
110 if (strcasecmp ("Host", key) == 0)
112 if (freeswitch_host != NULL)
113 free (freeswitch_host);
114 freeswitch_host = strdup (value);
116 else if (strcasecmp ("Port", key) == 0)
118 int port = (int) (atof (value));
119 if ((port > 0) && (port <= 65535))
120 ssnprintf (freeswitch_port, sizeof (freeswitch_port),
123 sstrncpy (freeswitch_port, value, sizeof (freeswitch_port));
125 else if (strcasecmp ("Password", key) == 0)
127 if (freeswitch_password != NULL)
128 free (freeswitch_password);
129 freeswitch_password = strdup (value);
136 } /* int freeswitch_config */
138 void module_register (void)
140 plugin_register_config ("freeswitch", freeswitch_config,
141 config_keys, config_keys_num);
142 plugin_register_read ("freeswitch", freeswitch_read);
143 } /* void module_register */