Changeset db656f3332551668dbf8656d8dcd05fe917ddcd7
- Timestamp:
- 09/06/08 23:51:16 (5 years ago)
- git-parent:
- Files:
-
- buildtools/xml2h (added)
- configure.in (modified) (1 diff)
- src/Makefile.in (modified) (2 diffs)
- src/modules/Makefile.in (modified) (9 diffs)
- src/modules/dns.c (modified) (2 diffs)
- src/modules/http.c (modified) (6 diffs)
- src/modules/lua.c (modified) (4 diffs)
- src/modules/module-online.xsl (added)
- src/modules/postgres.c (modified) (2 diffs)
- src/modules/snmp.c (modified) (2 diffs)
- src/modules/ssh2.c (modified) (2 diffs)
- src/noit_conf.c (modified) (1 diff)
- src/noit_console.c (modified) (1 diff)
- src/noit_console.h (modified) (4 diffs)
- src/noit_console_state.c (modified) (11 diffs)
- src/noit_module.c (modified) (2 diffs)
- src/noit_module.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
configure.in
r27a24a1 rdb656f3 212 212 AC_MSG_RESULT([$XML2LIBS]) 213 213 214 AC_CHECK_FUNC(xmlParseDocument, , [AC_MSG_ERROR(*** libxml2 is required ***)]) 215 216 AC_MSG_CHECKING([libxslt cflags]) 217 XSLTCFLAGS=`xslt-config --cflags` 218 CFLAGS="$CFLAGS $XSLTCFLAGS" 219 AC_MSG_RESULT([$XSLTCFLAGS]) 220 221 AC_MSG_CHECKING([libxslt libs]) 222 XSLTLIBS=`xslt-config --libs` 223 LIBS="$LIBS $XSLTLIBS" 224 AC_MSG_RESULT([$XSLTLIBS]) 225 226 AC_CHECK_FUNC(xsltParseStylesheetDoc, , [AC_MSG_ERROR(*** libxslt is required ***)]) 227 214 228 APRPREFIX="`apr-1-config --prefix`" 215 229 AC_MSG_CHECKING([libserf cflags]) src/Makefile.in
r0a06b2c rdb656f3 9 9 PGLIBS=@PGLIBS@ 10 10 INSTALL=@INSTALL@ 11 XML2H=@top_srcdir@/buildtools/xml2h 11 12 12 13 prefix=@prefix@ … … 97 98 @echo "- compiling $<" 98 99 100 noit_module.o: module-online.h 101 102 module-online.h: modules/module-online.xsl 103 @echo "- making module-online.h (StyleSheet include" 104 @$(XML2H) helpStyleXML < modules/module-online.xsl > $@ 105 99 106 noit_tokenizer.c: noit_tokenizer.re 100 107 @re2c -o $@ noit_tokenizer.re src/modules/Makefile.in
r27a24a1 rdb656f3 1 .SUFFIXES: .lo .@MODULEEXT@ 1 .SUFFIXES: .lo .@MODULEEXT@ .xml .xmlh 2 2 3 3 CC=@CC@ … … 18 18 XSLTPROC=@XSLTPROC@ 19 19 XMLLINT=@XMLLINT@ 20 XML2H=@top_srcdir@/buildtools/xml2h 20 21 21 22 top_srcdir=@top_srcdir@ … … 27 28 all: $(MODULES) 28 29 30 .xml.xmlh: 31 @$(XML2H) `echo $< | sed -e 's/\.xml$$//;'`_xml_description < $< > $@ 32 29 33 lua.@MODULEEXT@: lua.lo lua_noit.lo 30 34 @$(MODULELD) $(LDFLAGS) -o $@ lua.lo lua_noit.lo ../lua/liblua.lo 31 35 @echo "- linking $@" 32 36 33 lua.lo: lua.c 37 lua.lo: lua.c lua.xmlh 34 38 @$(CC) $(CPPFLAGS) $(SHCFLAGS) -I$(top_srcdir)/src/lua/src -c lua.c -o $@ 35 39 @echo "- compiling $<" … … 43 47 @echo "- linking $@" 44 48 45 postgres.lo: postgres.c 49 postgres.lo: postgres.c postgres.xmlh 46 50 @$(CC) $(CPPFLAGS) $(SHCFLAGS) $(PGCFLAGS) -c $< -o $@ 47 51 @echo "- compiling $<" … … 51 55 @echo "- linking $@" 52 56 53 dns.lo: dns.c 57 dns.lo: dns.c dns.xmlh 54 58 @$(CC) $(CPPFLAGS) $(SHCFLAGS) -c $< -o $@ 55 59 @echo "- compiling $<" … … 59 63 @echo "- linking $@" 60 64 61 http.lo: http.c 65 http.lo: http.c http.xmlh resmon.xmlh resmon_part.xmlh 62 66 @$(CC) $(CPPFLAGS) $(SHCFLAGS) -I$(top_srcdir)/src/serf @SERFCFLAGS@ -c http.c -o $@ 63 67 @echo "- compiling $<" … … 71 75 @echo "- linking $@" 72 76 77 ssh2.lo: ssh2.xmlh 78 73 79 ping_icmp.@MODULEEXT@: ping_icmp.lo 74 80 @$(MODULELD) $(LDFLAGS) -o $@ $< … … 78 84 @$(MODULELD) $(LDFLAGS) -o $@ $< 79 85 @echo "- linking $@" 86 87 snmp.lo: snmp.xmlh 80 88 81 89 .c.lo: … … 95 103 96 104 clean: 97 rm -f *.lo *.@MODULEEXT@ 105 rm -f *.lo *.@MODULEEXT@ *.xmlh src/modules/dns.c
r4ce9c54 rdb656f3 666 666 } 667 667 668 #include "dns.xmlh" 668 669 noit_module_t dns = { 669 670 { … … 672 673 "dns", 673 674 "DNS RR checker", 675 dns_xml_description, 674 676 dns_onload 675 677 }, src/modules/http.c
rc39dbcd rdb656f3 893 893 return 0; 894 894 } 895 896 #include "http.xmlh" 895 897 noit_module_t http = { 896 898 { … … 899 901 "http", 900 902 "libserf-based HTTP and HTTPS resource checker", 903 http_xml_description, 901 904 serf_onload 902 905 }, … … 907 910 }; 908 911 912 #include "resmon.xmlh" 909 913 noit_module_t resmon = { 910 914 { … … 913 917 "resmon", 914 918 "libserf-based resmon resource checker", 919 resmon_xml_description, 915 920 serf_onload 916 921 }, … … 921 926 }; 922 927 928 #include "resmon_part.xmlh" 923 929 noit_module_t resmon_part = { 924 930 { … … 927 933 "resmon_part", 928 934 "resmon part resource checker", 935 resmon_part_xml_description, 929 936 serf_onload 930 937 }, src/modules/lua.c
r5211225 rdb656f3 144 144 } 145 145 static int 146 noit_lua_module_set_description(lua_State *L) { 147 noit_module_t *module; 148 if(lua_gettop(L) != 1) luaL_error(L, "wrong number of arguments"); 149 module = lua_touserdata(L, lua_upvalueindex(1)); 150 module->hdr.description = strdup(lua_tostring(L, 1)); 151 return 0; 152 } 153 static int 154 noit_lua_module_set_name(lua_State *L) { 155 noit_module_t *module; 156 if(lua_gettop(L) != 1) luaL_error(L, "wrong number of arguments"); 157 module = lua_touserdata(L, lua_upvalueindex(1)); 158 module->hdr.name = strdup(lua_tostring(L, 1)); 159 return 0; 160 } 161 static int 162 noit_lua_module_set_xml_description(lua_State *L) { 163 noit_module_t *module; 164 if(lua_gettop(L) != 1) luaL_error(L, "wrong number of arguments"); 165 module = lua_touserdata(L, lua_upvalueindex(1)); 166 module->hdr.xml_description = strdup(lua_tostring(L, 1)); 167 return 0; 168 } 169 static int 146 170 noit_module_index_func(lua_State *L) { 171 noit_module_t **udata, *module; 172 const char *k; 147 173 int n; 148 174 n = lua_gettop(L); /* number of arguments */ … … 151 177 luaL_error(L, "metatable error, arg1 not a noit_module_t!"); 152 178 } 179 udata = lua_touserdata(L, 1); 180 module = *udata; 181 if(!lua_isstring(L, 2)) { 182 luaL_error(L, "metatable error, arg2 not a string!"); 183 } 184 k = lua_tostring(L, 2); 185 switch(*k) { 186 case 'd': 187 if(!strcmp(k, "description")) { 188 lua_pushlightuserdata(L, module); 189 lua_pushcclosure(L, noit_lua_module_set_description, 1); 190 } 191 else break; 192 return 1; 193 case 'n': 194 if(!strcmp(k, "name")) { 195 lua_pushlightuserdata(L, module); 196 lua_pushcclosure(L, noit_lua_module_set_name, 1); 197 } 198 else break; 199 return 1; 200 case 'x': 201 if(!strcmp(k, "xml_description")) { 202 lua_pushlightuserdata(L, module); 203 lua_pushcclosure(L, noit_lua_module_set_xml_description, 1); 204 } 205 else break; 206 return 1; 207 default: 208 break; 209 } 210 luaL_error(L, "noit_module_t no such element: %s", k); 153 211 return 0; 154 212 } … … 732 790 } 733 791 792 #include "lua.xmlh" 734 793 noit_module_loader_t lua = { 735 794 { … … 738 797 "lua", 739 798 "Lua check loader", 799 lua_xml_description, 740 800 noit_lua_loader_onload, 741 801 }, src/modules/postgres.c
rab6d943 rdb656f3 256 256 } 257 257 258 #include "postgres.xmlh" 258 259 noit_module_t postgres = { 259 260 { … … 262 263 "postgres", 263 264 "PostgreSQL Checker", 265 postgres_xml_description, 264 266 postgres_onload 265 267 }, src/modules/snmp.c
r3277121 rdb656f3 465 465 return 0; 466 466 } 467 468 #include "snmp.xmlh" 467 469 noit_module_t snmp = { 468 470 { … … 471 473 "snmp", 472 474 "SNMP collection", 475 snmp_xml_description, 473 476 noit_snmp_onload 474 477 }, src/modules/ssh2.c
rc39dbcd rdb656f3 300 300 } 301 301 302 #include "ssh2.xmlh" 302 303 noit_module_t ssh2 = { 303 304 { … … 306 307 "ssh2", 307 308 "Secure Shell version 2 checker", 309 ssh2_xml_description, 308 310 ssh2_onload 309 311 }, src/noit_conf.c
r4bed82b rdb656f3 445 445 return noit_conf_set_string(section,path,"true"); 446 446 return noit_conf_set_string(section,path,"false"); 447 }448 449 static int450 noit_console_write_xml(void *vncct, const char *buffer, int len) {451 noit_console_closure_t ncct = vncct;452 return nc_write(ncct, buffer, len);453 }454 static int455 noit_console_close_xml(void *vncct) {456 return 0;457 447 } 458 448 src/noit_console.c
r7180374 rdb656f3 454 454 }; 455 455 456 int 457 noit_console_write_xml(void *vncct, const char *buffer, int len) { 458 noit_console_closure_t ncct = vncct; 459 return nc_write(ncct, buffer, len); 460 } 461 462 int 463 noit_console_close_xml(void *vncct) { 464 return 0; 465 } 466 456 467 void 457 468 noit_console_init() { src/noit_console.h
r7180374 rdb656f3 34 34 /* This performs a pop (exiting if at toplevel) */ 35 35 extern cmd_info_t console_command_exit; 36 extern cmd_info_t console_command_help; 36 37 extern cmd_info_t console_command_shutdown; 37 38 extern cmd_info_t console_command_restart; … … 59 60 60 61 typedef struct _console_state_stack { 62 char *name; 61 63 noit_console_state_t *state; 62 64 void *userdata; … … 121 123 122 124 API_EXPORT(int) 125 noit_console_help(noit_console_closure_t ncct, int argc, char **argv, 126 noit_console_state_t *, void *); 127 128 API_EXPORT(int) 123 129 noit_console_shutdown(noit_console_closure_t ncct, int argc, char **argv, 124 130 noit_console_state_t *, void *); … … 171 177 noit_console_state_t *dstate, void *closure); 172 178 179 API_EXPORT(int) 180 noit_console_write_xml(void *vncct, const char *buffer, int len); 181 182 API_EXPORT(int) 183 noit_console_close_xml(void *vncct); 184 185 API_EXPORT(void) 186 noit_console_add_help(const char *topic, console_cmd_func_t topic_func); 187 173 188 #endif src/noit_console_state.c
r7180374 rdb656f3 12 12 #include "noit_console.h" 13 13 #include "noit_tokenizer.h" 14 #include "noit_module.h" 14 15 15 16 #include <netinet/in.h> … … 17 18 #include <pcre.h> 18 19 20 int cmd_info_comparek(const void *akv, const void *bv) { 21 char *ak = (char *)akv; 22 cmd_info_t *b = (cmd_info_t *)bv; 23 return strcasecmp(ak, b->name); 24 } 25 int cmd_info_compare(const void *av, const void *bv) { 26 cmd_info_t *a = (cmd_info_t *)av; 27 cmd_info_t *b = (cmd_info_t *)bv; 28 return strcasecmp(a->name, b->name); 29 } 30 31 cmd_info_t console_command_help = { 32 "help", noit_console_help, NULL, NULL 33 }; 19 34 cmd_info_t console_command_exit = { 20 35 "exit", noit_console_state_pop, NULL, NULL … … 27 42 }; 28 43 44 void 45 noit_console_add_help(const char *topic, console_cmd_func_t topic_func) { 46 noit_console_state_t *s = console_command_help.dstate; 47 if(!s) { 48 console_command_help.dstate = s = calloc(1, sizeof(*s)); 49 noit_skiplist_init(&s->cmds); 50 noit_skiplist_set_compare(&s->cmds, cmd_info_compare, cmd_info_comparek); 51 } 52 noit_console_state_add_cmd(s, NCSCMD(topic, topic_func, NULL, NULL)); 53 } 29 54 30 55 static char * … … 194 219 195 220 int 221 noit_console_render_help(noit_console_closure_t ncct, 222 noit_console_state_t *dstate) { 223 noit_skiplist_node *iter = NULL; 224 if(!dstate) { 225 nc_printf(ncct, "No help available.\n"); 226 return -1; 227 } 228 for(iter = noit_skiplist_getlist(&dstate->cmds); iter; 229 noit_skiplist_next(&dstate->cmds,&iter)) { 230 cmd_info_t *cmd = iter->data; 231 if(strcmp(cmd->name, "help")) nc_printf(ncct, " ==> '%s'\n", cmd->name); 232 } 233 return 0; 234 } 235 236 int 196 237 noit_console_state_delegate(noit_console_closure_t ncct, 197 238 int argc, char **argv, … … 201 242 202 243 if(argc == 0) { 203 n c_printf(ncct, "arguments expected\n");204 /* XXX: noit_console_render_help(dstate); */244 noit_console_render_help(ncct, dstate); 245 nc_printf(ncct, "incomplete command.\n"); 205 246 return -1; 206 247 } … … 221 262 222 263 if(!argc) { 264 noit_console_render_help(ncct, stack->state); 223 265 nc_printf(ncct, "arguments expected\n"); 224 266 return -1; … … 266 308 } 267 309 } 310 if(ncct->state_stack->name) free(ncct->state_stack->name); 311 ncct->state_stack->name = strdup(cmd->name); 268 312 return cmd->func(ncct, argc-1, argv+1, cmd->dstate, cmd->closure); 269 313 } … … 271 315 noit_console_state_do(noit_console_closure_t ncct, int argc, char **argv) { 272 316 return _noit_console_state_do(ncct, ncct->state_stack, argc, argv); 273 }274 275 int cmd_info_comparek(const void *akv, const void *bv) {276 char *ak = (char *)akv;277 cmd_info_t *b = (cmd_info_t *)bv;278 return strcasecmp(ak, b->name);279 }280 int cmd_info_compare(const void *av, const void *bv) {281 cmd_info_t *a = (cmd_info_t *)av;282 cmd_info_t *b = (cmd_info_t *)bv;283 return strcasecmp(a->name, b->name);284 317 } 285 318 … … 292 325 noit_console_state_add_cmd(s, 293 326 NCSCMD("apply", noit_console_generic_apply, NULL, NULL)); 327 noit_console_state_add_cmd(s, &console_command_help); 294 328 return s; 295 329 } … … 375 409 exit(1); 376 410 } 377 411 int 412 noit_console_help(noit_console_closure_t ncct, int argc, char **argv, 413 noit_console_state_t *dstate, void *unused) { 414 noit_console_state_stack_t *current; 415 current = ncct->state_stack; 416 417 if(!argc) { 418 noit_console_state_stack_t *i = current; 419 if(!current) { 420 nc_printf(ncct, "no state!\n"); 421 return -1; 422 } 423 for(i=current;i;i=i->last) { 424 if(i != current) 425 nc_printf(ncct, " -> '%s'\n", i->name ? i->name : "(null)"); 426 } 427 if(dstate) { 428 nc_printf(ncct, "= Topics =\n"); 429 noit_console_render_help(ncct, dstate); 430 } 431 if(current->state) { 432 nc_printf(ncct, "\n= Commands =\n"); 433 noit_console_render_help(ncct, current->state); 434 } 435 return 0; 436 } 437 else if(argc > 0) { 438 nc_printf(ncct, "Help for '%s':\n", argv[0]); 439 if(noit_console_state_delegate(ncct, argc, argv, dstate, NULL) == 0) 440 return 0; 441 } 442 nc_printf(ncct, "command not understood.\n"); 443 return -1; 444 } 378 445 int 379 446 noit_console_state_pop(noit_console_closure_t ncct, int argc, char **argv, … … 394 461 current->last = NULL; 395 462 if(current->state->statefree) current->state->statefree(current->state); 463 if(current->name) free(current->name); 396 464 free(current); 397 465 noit_console_state_init(ncct); src/noit_module.c
rfc9516a rdb656f3 8 8 #include <stdio.h> 9 9 #include <dlfcn.h> 10 11 #include <libxml/parser.h> 12 #include <libxslt/xslt.h> 13 #include <libxslt/xsltInternals.h> 14 #include <libxslt/transform.h> 10 15 11 16 #include "noit_module.h" … … 172 177 } 173 178 179 #include "module-online.h" 180 181 void noit_module_print_help(noit_console_closure_t ncct, 182 noit_module_t *module, int examples) { 183 const char *params[3] = { NULL }; 184 xmlDocPtr help = NULL, output = NULL; 185 xmlOutputBufferPtr out; 186 xmlCharEncodingHandlerPtr enc; 187 static xmlDocPtr helpStyleDoc = NULL; 188 static xsltStylesheetPtr helpStyle = NULL; 189 if(!helpStyle) { 190 if(!helpStyleDoc) 191 helpStyleDoc = xmlParseMemory(helpStyleXML, strlen(helpStyleXML)); 192 if(!helpStyleDoc) { 193 nc_printf(ncct, "Invalid XML for style XML\n"); 194 return; 195 } 196 helpStyle = xsltParseStylesheetDoc(helpStyleDoc); 197 } 198 if(!helpStyle) { 199 nc_printf(ncct, "no available stylesheet.\n"); 200 return; 201 } 202 if(!module) { 203 nc_printf(ncct, "no module\n"); 204 return; 205 } 206 if(!module->hdr.xml_description) { 207 nc_printf(ncct, "%s is undocumented, complain to the vendor.\n", 208 module->hdr.name); 209 return; 210 } 211 help = xmlParseMemory(module->hdr.xml_description, 212 strlen(module->hdr.xml_description)); 213 if(!help) { 214 nc_printf(ncct, "%s module has invalid XML documentation.\n", 215 module->hdr.name); 216 return; 217 } 218 219 if(examples) { 220 params[0] = "example"; 221 params[1] = "'1'"; 222 params[2] = NULL; 223 } 224 output = xsltApplyStylesheet(helpStyle, help, params); 225 if(!output) { 226 nc_printf(ncct, "formatting failed.\n"); 227 goto out; 228 } 229 230 enc = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8); 231 out = xmlOutputBufferCreateIO(noit_console_write_xml, 232 noit_console_close_xml, 233 ncct, enc); 234 xmlSaveFormatFileTo(out, output, "utf8", 1); 235 236 out: 237 if(help) xmlFreeDoc(help); 238 if(output) xmlFreeDoc(output); 239 } 240 241 int 242 noit_module_help(noit_console_closure_t ncct, 243 int argc, char **argv, 244 noit_console_state_t *state, void *closure) { 245 if(argc == 0) { 246 /* List modules */ 247 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 248 const char *name; 249 int klen; 250 noit_image_t *hdr; 251 252 nc_printf(ncct, "= Loaders and Modules =\n"); 253 while(noit_hash_next(&loaders, &iter, (const char **)&name, &klen, 254 (void **)&hdr)) { 255 nc_printf(ncct, " %s\n", hdr->name); 256 } 257 memset(&iter, 0, sizeof(iter)); 258 while(noit_hash_next(&modules, &iter, (const char **)&name, &klen, 259 (void **)&hdr)) { 260 nc_printf(ncct, " %s\n", hdr->name); 261 } 262 return 0; 263 } 264 else if(argc == 1 || 265 (argc == 2 && !strcmp(argv[1], "examples"))) { 266 /* help for a specific module */ 267 noit_module_t *mod; 268 mod = noit_module_lookup(argv[0]); 269 noit_module_print_help(ncct, mod, argc == 2); 270 return 0; 271 } 272 nc_printf(ncct, "help module [ <modulename> [ examples ] ]\n"); 273 return -1; 274 } 275 174 276 void noit_module_init() { 175 277 noit_conf_section_t *sections; 176 278 int i, cnt = 0; 279 280 noit_console_add_help("module", noit_module_help); 177 281 178 282 /* Load our module loaders */ src/noit_module.h
rfc9516a rdb656f3 12 12 13 13 #define NOIT_LOADER_MAGIC 0xA7AD7104 14 #define NOIT_LOADER_ABI_VERSION 314 #define NOIT_LOADER_ABI_VERSION 4 15 15 16 16 typedef struct _noit_image { … … 19 19 char *name; 20 20 char *description; 21 char *xml_description; 21 22 int (*onload)(struct _noit_image *); 22 23 void *opaque_handle; … … 42 43 43 44 #define NOIT_MODULE_MAGIC 0x4017DA7A 44 #define NOIT_MODULE_ABI_VERSION 245 #define NOIT_MODULE_ABI_VERSION 3 45 46 46 47 typedef struct _noit_module { … … 85 86 API_EXPORT(void) 86 87 noit_module_set_userdata(noit_module_t *mod, void *newdata); 87 88 API_EXPORT(void) 89 noit_module_print_help(noit_console_closure_t ncct, 90 noit_module_t *module, int examples); 88 91 89 92 #endif
