Changeset e102af344eb4afacdeeb549fb60d77715f815a53
- Timestamp:
- 01/27/08 04:24:46 (5 years ago)
- git-parent:
- Files:
-
- src/modules/ping_icmp.c (modified) (1 diff)
- src/noit_conf.c (modified) (1 diff)
- src/noit_conf.h (modified) (2 diffs)
- src/noit_module.c (modified) (4 diffs)
- src/noit_module.h (modified) (2 diffs)
- src/noitd.c (modified) (2 diffs)
- src/sample.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/modules/ping_icmp.c
r7e43d37 re102af3 1 /* 2 * Copyright (c) 2007, OmniTI Computer Consulting, Inc. 3 * All rights reserved. 4 */ 5 6 #include "noit_defines.h" 7 8 #include "noit_module.h" 9 #include "noit_poller.h" 10 11 static int ping_icmp_onload(noit_module_t *self) { 12 return 0; 13 } 14 static int ping_icmp_config(noit_module_t *self, noit_hash_table *options) { 15 return 0; 16 } 17 static int ping_icmp_init(noit_module_t *self) { 18 return 0; 19 } 20 static int ping_icmp_initiate_check(noit_module_t *self, noit_check_t check) { 21 return 0; 22 } 23 24 noit_module_t ping_icmp = { 25 NOIT_MODULE_MAGIC, 26 NOIT_MODULE_ABI_VERSION, 27 "ping_icmp", 28 "ICMP based host availability detection", 29 ping_icmp_onload, 30 ping_icmp_config, 31 ping_icmp_init, 32 ping_icmp_initiate_check 33 }; 34 src/noit_conf.c
rcaa7b86 re102af3 66 66 } 67 67 68 noit_hash_table *noit_conf_get_hash(noit_conf_section_t section, 69 const char *path) { 70 int i, cnt; 71 noit_hash_table *table; 72 xmlXPathObjectPtr pobj; 73 xmlXPathContextPtr current_ctxt; 74 xmlNodePtr current_node = (xmlNodePtr)section; 75 xmlNodePtr node; 76 77 table = calloc(1, sizeof(*table)); 78 current_ctxt = xpath_ctxt; 79 if(current_node) { 80 current_ctxt = xmlXPathNewContext(master_config); 81 current_ctxt->node = current_node; 82 } 83 pobj = xmlXPathEval((xmlChar *)path, current_ctxt); 84 if(!pobj) goto out; 85 if(pobj->type != XPATH_NODESET) goto out; 86 if(xmlXPathNodeSetIsEmpty(pobj->nodesetval)) goto out; 87 cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 88 for(i=0; i<cnt; i++) { 89 char *value; 90 node = xmlXPathNodeSetItem(pobj->nodesetval, i); 91 value = (char *)xmlXPathCastNodeSetToString(pobj->nodesetval); 92 noit_hash_replace(table, 93 strdup((char *)node->name), strlen((char *)node->name), 94 strdup(value), free, free); 95 } 96 out: 97 if(current_ctxt && current_ctxt != xpath_ctxt) 98 xmlXPathFreeContext(current_ctxt); 99 return table; 100 } 68 101 noit_conf_section_t noit_conf_get_section(noit_conf_section_t section, 69 102 const char *path) { src/noit_conf.h
rcaa7b86 re102af3 8 8 9 9 #include "noit_defines.h" 10 #include "utils/noit_hash.h" 10 11 11 12 typedef enum { noit_true, noit_false } noit_conf_boolean; … … 21 22 noit_conf_get_sections(noit_conf_section_t section, const char *path, 22 23 int *cnt); 24 25 API_EXPORT(noit_hash_table *) 26 noit_conf_get_hash(noit_conf_section_t section, const char *path); 23 27 24 28 API_EXPORT(int) noit_conf_get_string(noit_conf_section_t section, src/noit_module.c
rcaa7b86 re102af3 23 23 noit_module_t *module; 24 24 25 if(!noit_conf_get_string( "/global/modules/directory", &base))25 if(!noit_conf_get_string(NULL, "/global/modules/directory", &base)) 26 26 base = strdup(""); 27 27 … … 48 48 } 49 49 50 module = (noit_module_t *)dlsymbol; 51 if(noit_module_validate_magic(module) == -1) { 50 if(noit_module_validate_magic((noit_module_t *)dlsymbol) == -1) { 52 51 noit_log(noit_stderr, NULL, "I can't understand module %s\n", name); 53 52 dlclose(dlhandle); … … 55 54 } 56 55 56 module = calloc(1, sizeof(*module)); 57 memcpy(module, dlsymbol, sizeof(*module)); 58 59 if(module->onload(module)) { 60 free(module); 61 return -1; 62 } 57 63 noit_hash_store(&modules, module->name, strlen(module->name), module); 58 64 return 0; … … 68 74 } 69 75 76 void noit_module_init() { 77 noit_conf_section_t *sections; 78 int i, cnt = 0; 79 80 sections = noit_conf_get_sections(NULL, "/global/modules/module", &cnt); 81 if(!sections) return; 82 for(i=0; i<cnt; i++) { 83 noit_hash_table *config; 84 noit_module_t *module; 85 char module_file[PATH_MAX]; 86 char module_name[256]; 87 if(!noit_conf_get_stringbuf(sections[i], "image", 88 module_file, sizeof(module_file))) { 89 noit_log(noit_stderr, NULL, 90 "No image defined in module stanza %d\n", i+1); 91 continue; 92 } 93 if(!noit_conf_get_stringbuf(sections[i], "name", 94 module_name, sizeof(module_name))) { 95 noit_log(noit_stderr, NULL, 96 "No name defined in module stanza %d\n", i+1); 97 continue; 98 } 99 if(noit_module_load(module_file, module_name)) { 100 noit_log(noit_stderr, NULL, 101 "Could not load %s:%s\n", module_file, module_name); 102 continue; 103 } 104 config = noit_conf_get_hash(sections[i], "config/*"); 105 module = noit_module_lookup(module_name); 106 if(module->config(module, config)) { 107 noit_log(noit_stderr, NULL, 108 "Configure failed on %s:%s\n", module_file, module_name); 109 continue; 110 } 111 noit_log(noit_stderr, NULL, "Module %s:%s successfully loaded.\n", 112 module_file, module_name); 113 } 114 } src/noit_module.h
rcaa7b86 re102af3 11 11 #include "noit_poller.h" 12 12 13 #define NOIT_MODULE_MAGIC 0x4017DA7A 13 #define NOIT_MODULE_MAGIC 0x4017DA7A 14 #define NOIT_MODULE_ABI_VERSION 1 14 15 15 typedef struct {16 typedef struct _noit_module { 16 17 uint32_t magic; 17 18 uint32_t version; 18 19 char *name; 19 20 char *description; 20 int (*onload)( );21 int (*config)( noit_hash_table *options);22 int (*init)( );23 int (*initiate_check)( noit_check_t check);21 int (*onload)(struct _noit_module *); 22 int (*config)(struct _noit_module *, noit_hash_table *options); 23 int (*init)(struct _noit_module *); 24 int (*initiate_check)(struct _noit_module *, noit_check_t check); 24 25 } noit_module_t; 25 26 … … 30 31 ((MODULE_MAGIC(a) == NOIT_MODULE_MAGIC)?0:-1) 31 32 33 API_EXPORT(void) 34 noit_module_init(); 32 35 API_EXPORT(int) 33 36 noit_module_load(const char *file, const char *name); src/noitd.c
rcaa7b86 re102af3 12 12 #include "noit_listener.h" 13 13 #include "noit_console.h" 14 #include "noit_module.h" 14 15 #include "noit_conf.h" 15 16 … … 65 66 } 66 67 noit_console_init(); 67 68 noit_module_init(); 68 69 noit_listener_init(); 69 70 src/sample.conf
rcaa7b86 re102af3 6 6 <modules> 7 7 <directory>./modules</directory> 8 <module> 9 <image>ping_icmp</image> 10 <name>ping_icmp</name> 11 <config> 12 <key1>value2</key1> 13 <key2>value2</key2> 14 </config> 15 </module> 8 16 </modules> 9 17 <listeners>
