Comparison

plugins/mod_external_services.lua @ 11628:0807e835d3b5

mod_external_services: Report overall status as a module status Because during startup, if all items are provided by a different module (e.g. mod_turn_external) then this would log a scary warning even if everything is fine after that other module has been loaded. This way, any persistent problematic state is reported in the console. Errors with individual items should still be reported by prepare(). Now, if you load mod_external_services alone without configuring any services, no error or warning is reported in the log, but maybe that's not so bad with it reported in the console.
author Kim Alvefur <zash@zash.se>
date Mon, 21 Jun 2021 22:43:26 +0200
parent 11627:3a5212fd7e8e
child 11753:c4599a7c534c
comparison
equal deleted inserted replaced
11627:3a5212fd7e8e 11628:0807e835d3b5
101 function module.load() 101 function module.load()
102 -- Trigger errors on startup 102 -- Trigger errors on startup
103 local extras = module:get_host_items("external_service"); 103 local extras = module:get_host_items("external_service");
104 local services = ( configured_services + extras ) / prepare; 104 local services = ( configured_services + extras ) / prepare;
105 if #services == 0 then 105 if #services == 0 then
106 module:log("warn", "No services configured or all had errors"); 106 module:set_status("warn", "No services configured or all had errors");
107 end 107 end
108 end 108 end
109 109
110 module:handle_items("external_service", function(added) 110 module:handle_items("external_service", function(added)
111 prepare(added.item); 111 if prepare(added.item) then
112 module:set_status("core", "OK");
113 end
112 end, module.load); 114 end, module.load);
113 115
114 -- Ensure only valid items are added in events 116 -- Ensure only valid items are added in events
115 local services_mt = { 117 local services_mt = {
116 __index = getmetatable(array()).__index; 118 __index = getmetatable(array()).__index;