* collectd-nagios - src/collectd-nagios.c
* Copyright (C) 2008-2010 Florian octo Forster
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
*
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Florian octo Forster <octo at verplant.org>
+ * Florian octo Forster <octo at collectd.org>
**/
#if HAVE_CONFIG_H
static _Bool nan_is_error_g = 0;
static char **match_ds_g = NULL;
-static int match_ds_num_g = 0;
+static size_t match_ds_num_g = 0;
/* `strdup' is an XSI extension. I don't want to pull in all of XSI just for
* that, so here's an own implementation.. It's easy enough. The GCC attributes
gauge_t *new_values;
char **new_names;
- size_t i;
-
if (match_ds_g == NULL)
return (RET_OKAY);
new_values = (gauge_t *)calloc (match_ds_num_g, sizeof (*new_values));
if (new_values == NULL)
{
- fprintf (stderr, "malloc failed: %s\n", strerror (errno));
+ fprintf (stderr, "calloc failed: %s\n", strerror (errno));
return (RET_UNKNOWN);
}
new_names = (char **)calloc (match_ds_num_g, sizeof (*new_names));
if (new_names == NULL)
{
- fprintf (stderr, "malloc failed: %s\n", strerror (errno));
+ fprintf (stderr, "calloc failed: %s\n", strerror (errno));
free (new_values);
return (RET_UNKNOWN);
}
- for (i = 0; i < (size_t) match_ds_num_g; i++)
+ for (size_t i = 0; i < match_ds_num_g; i++)
{
size_t j;
}
free (*values);
- for (i = 0; i < *values_num; i++)
+ for (size_t i = 0; i < *values_num; i++)
free ((*values_names)[i]);
free (*values_names);
return (((ret - range->invert) == 0) ? 0 : 1);
} /* int match_range */
+__attribute__((noreturn))
static void usage (const char *name)
{
fprintf (stderr, "Usage: %s <-s socket> <-n value_spec> <-H hostname> [options]\n"
char *hostname = NULL;
int status;
- size_t i;
status = lcc_listval (connection, &ret_ident, &ret_ident_num);
if (status != 0) {
return (RET_UNKNOWN);
}
- for (i = 0; i < ret_ident_num; ++i) {
+ for (size_t i = 0; i < ret_ident_num; ++i) {
char id[1024];
if ((hostname_g != NULL) && (strcasecmp (hostname_g, ret_ident[i].host)))
int num_okay = 0;
const char *status_str = "UNKNOWN";
int status_code = RET_UNKNOWN;
- size_t i;
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
if (isnan (values[i]))
{
if (values_num > 0)
{
printf (" |");
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
printf (" %s=%f;;;;", values_names[i], values[i]);
}
printf ("\n");
static int do_check_con_average (size_t values_num,
double *values, char **values_names)
{
- size_t i;
double total;
int total_num;
double average;
total = 0.0;
total_num = 0;
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
if (isnan (values[i]))
{
}
printf ("%s: %g average |", status_str, average);
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
printf (" %s=%f;;;;", values_names[i], values[i]);
printf ("\n");
static int do_check_con_sum (size_t values_num,
double *values, char **values_names)
{
- size_t i;
double total;
int total_num;
const char *status_str = "UNKNOWN";
total = 0.0;
total_num = 0;
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
if (isnan (values[i]))
{
}
printf ("%s: %g sum |", status_str, total);
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
printf (" %s=%f;;;;", values_names[i], values[i]);
printf ("\n");
static int do_check_con_percentage (size_t values_num,
double *values, char **values_names)
{
- size_t i;
double sum = 0.0;
double percentage;
return (RET_WARNING);
}
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
if (isnan (values[i]))
{
}
printf ("%s: %lf percent |", status_str, percentage);
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
printf (" %s=%lf;;;;", values_names[i], values[i]);
return (status_code);
} /* int do_check_con_percentage */
size_t values_num;
char ident_str[1024];
lcc_identifier_t ident;
- size_t i;
int status;
snprintf (ident_str, sizeof (ident_str), "%s/%s",
hostname_g, value_string_g);
ident_str[sizeof (ident_str) - 1] = 0;
- memset (&ident, 0, sizeof (ident));
status = lcc_string_to_identifier (connection, &ident, ident_str);
if (status != 0)
{
status = RET_UNKNOWN;
if (consolitation_g == CON_NONE)
- status = do_check_con_none (values_num, values, values_names);
+ status = do_check_con_none (values_num, values, values_names);
else if (consolitation_g == CON_AVERAGE)
- status = do_check_con_average (values_num, values, values_names);
+ status = do_check_con_average (values_num, values, values_names);
else if (consolitation_g == CON_SUM)
status = do_check_con_sum (values_num, values, values_names);
else if (consolitation_g == CON_PERCENTAGE)
free (values);
if (values_names != NULL)
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
free (values_names[i]);
free (values_names);
case 'd':
{
char **tmp;
- tmp = (char **) realloc (match_ds_g,
+ tmp = realloc (match_ds_g,
(match_ds_num_g + 1)
* sizeof (char *));
if (tmp == NULL)