Code

"list hosts" action: Add action to list all hosts.
authorFlorian Forster <ff@octo.it>
Fri, 9 Jul 2010 12:56:14 +0000 (14:56 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Fri, 9 Jul 2010 12:56:14 +0000 (14:56 +0200)
src/Makefile.am
src/action_list_hosts.c [new file with mode: 0644]
src/action_list_hosts.h [new file with mode: 0644]
src/main.c

index 82954cf1e9ea6e2ceabfafcebe23ff08d1847562..f2ba32282c002b5626985fdcbec54d4d49713b3a 100644 (file)
@@ -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 (file)
index 0000000..b58d6bb
--- /dev/null
@@ -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 <ff at octo.it>
+ **/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "action_list_hosts.h"
+#include "common.h"
+#include "graph.h"
+#include "graph_list.h"
+#include "utils_cgi.h"
+
+#include <fcgiapp.h>
+#include <fcgi_stdio.h>
+
+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 ("      <li class=\"host\"><a href=\"%s?action=search;q=host:%s\">"
+      "%s</a></li>\n",
+      script_name (), host_html, host_html);
+
+  return (0);
+} /* }}} int print_one_host */
+
+static int print_all_hosts (__attribute__((unused)) void *user_data) /* {{{ */
+{
+  printf ("    <ul class=\"host_list\">\n");
+  gl_foreach_host (print_one_host, /* user_data = */ NULL);
+  printf ("    </ul>\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 (file)
index 0000000..aac1272
--- /dev/null
@@ -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 <ff at octo.it>
+ **/
+
+#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 : */
index 496754f8f73e129a5d1e9cad8b3a1fba235783a6..7bc024a8a12a0db056ad90c22d62ae8a37484db8 100644 (file)
@@ -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 },