From: Florian Forster Date: Fri, 9 Jul 2010 12:56:14 +0000 (+0200) Subject: "list hosts" action: Add action to list all hosts. X-Git-Tag: v4.0.0~117 X-Git-Url: https://git.octo.it/?p=collection4.git;a=commitdiff_plain;h=a164d755a41a47cff81a643dfdd088c6a8de76a5 "list hosts" action: Add action to list all hosts. --- diff --git a/src/Makefile.am b/src/Makefile.am index 82954cf..f2ba322 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,7 @@ collection_fcgi_SOURCES = main.c \ oconfig.c oconfig.h aux_types.h scanner.l parser.y \ action_graph.c action_graph.h \ action_list_graphs.c action_list_graphs.h \ + action_list_hosts.c action_list_hosts.h \ action_search.c action_search.h \ action_search_json.c action_search_json.h \ action_show_graph.c action_show_graph.h \ diff --git a/src/action_list_hosts.c b/src/action_list_hosts.c new file mode 100644 index 0000000..b58d6bb --- /dev/null +++ b/src/action_list_hosts.c @@ -0,0 +1,81 @@ +/** + * collection4 - action_list_hosts.c + * Copyright (C) 2010 Florian octo Forster + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + **/ + +#include +#include +#include +#include + +#include "action_list_hosts.h" +#include "common.h" +#include "graph.h" +#include "graph_list.h" +#include "utils_cgi.h" + +#include +#include + +static int print_one_host (const char *host, /* {{{ */ + __attribute__((unused)) void *user_data) +{ + char host_html[128]; + + strncpy (host_html, host, sizeof (host_html)); + host_html[sizeof (host_html) - 1] = 0; + html_escape_buffer (host_html, sizeof (host_html)); + + printf ("
  • " + "%s
  • \n", + script_name (), host_html, host_html); + + return (0); +} /* }}} int print_one_host */ + +static int print_all_hosts (__attribute__((unused)) void *user_data) /* {{{ */ +{ + printf ("
      \n"); + gl_foreach_host (print_one_host, /* user_data = */ NULL); + printf ("
    \n"); + + return (0); +} /* }}} int print_all_hosts */ + +int action_list_hosts (void) /* {{{ */ +{ + gl_update (); + + page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT; + char title[512]; + + strncpy (title, "List of all hosts", sizeof (title)); + title[sizeof (title) - 1] = 0; + + pg_callbacks.top_right = html_print_search_box; + pg_callbacks.middle_center = print_all_hosts; + + html_print_page (title, &pg_callbacks, /* user data = */ NULL); + + return (0); +} /* }}} int action_list_hosts */ + +/* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/action_list_hosts.h b/src/action_list_hosts.h new file mode 100644 index 0000000..aac1272 --- /dev/null +++ b/src/action_list_hosts.h @@ -0,0 +1,30 @@ +/** + * collection4 - action_list_hosts.h + * Copyright (C) 2010 Florian octo Forster + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + **/ + +#ifndef ACTION_LIST_HOSTS_H +#define ACTION_LIST_HOSTS_H 1 + +int action_list_hosts (void); + +#endif /* ACTION_LIST_HOSTS_H */ +/* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/main.c b/src/main.c index 496754f..7bc024a 100644 --- a/src/main.c +++ b/src/main.c @@ -38,6 +38,7 @@ #include "action_graph.h" #include "action_list_graphs.h" +#include "action_list_hosts.h" #include "action_search.h" #include "action_search_json.h" #include "action_show_graph.h" @@ -62,6 +63,7 @@ static const action_t actions[] = { { "graph", action_graph }, { "list_graphs", action_list_graphs }, + { "list_hosts", action_list_hosts }, { "search", action_search }, { "search_json", action_search_json }, { "show_graph", action_show_graph },