本文整理汇总了Python中Output.Output.plugin_state方法的典型用法代码示例。如果您正苦于以下问题:Python Output.plugin_state方法的具体用法?Python Output.plugin_state怎么用?Python Output.plugin_state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Output.Output
的用法示例。
在下文中一共展示了Output.plugin_state方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stop_process
# 需要导入模块: from Output import Output [as 别名]
# 或者: from Output.Output import plugin_state [as 别名]
def stop_process(plugin, notify=True):
id = plugin.get("config", "plugin_id")
process = plugin.get("config", "process")
process_aux = plugin.get("config", "process_aux")
name = plugin.get("config", "name")
command = plugin.get("config", "shutdown")
# stop service
if command:
logger.info("Stopping service %s (%s): %s.." % (id, name, command))
logger.debug(commands.getstatusoutput(command))
# notify result to server
if notify:
time.sleep(1)
if not process:
logger.debug("plugin (%s) has an unknown state" % (name))
Output.plugin_state(Watchdog.PLUGIN_UNKNOWN_STATE_MSG % (id))
elif Watchdog.pidof(process, process_aux) is None:
logger.info(WATCHDOG_PROCESS_STOPPED % (process, id))
Output.plugin_state(Watchdog.PLUGIN_STOP_STATE_MSG % (id))
Watchdog.__pluginID_stoppedByServer.append(id)
logger.info("Plugin %s process :%s stopped by server..." % (id,name))
else:
logger.warning(WATCHDOG_ERROR_STOPPING_PROCESS % (process, id))
示例2: disable_process
# 需要导入模块: from Output import Output [as 别名]
# 或者: from Output.Output import plugin_state [as 别名]
def disable_process(plugin, notify=True):
id = plugin.get("config", "plugin_id")
name = plugin.get("config", "name")
# disable plugin
plugin.set("config", "enable", "no")
# notify to server
if notify:
logger.info("plugin (%s) is now disabled" % (name))
Output.plugin_state(Watchdog.PLUGIN_DISABLE_STATE_MSG % (id))
示例3: disable_process
# 需要导入模块: from Output import Output [as 别名]
# 或者: from Output.Output import plugin_state [as 别名]
def disable_process(plugin, notify=True):
id = plugin.get("config", "plugin_id")
name = plugin.get("config", "name")
# disable plugin
plugin.set("config", "enable", "no")
# notify to server
if notify:
logger.info("plugin (%s) is now disabled" % (name))
Output.plugin_state(PluginDisableState(id))
示例4: start_process
# 需要导入模块: from Output import Output [as 别名]
# 或者: from Output.Output import plugin_state [as 别名]
def start_process(plugin, notify=True):
id = plugin.get("config", "plugin_id")
process = plugin.get("config", "process")
process_aux = plugin.get("config", "process_aux")
name = plugin.get("config", "name")
command = plugin.get("config", "startup")
# start service
if command:
logger.info("Starting service %s (%s): %s.." % (id, name, command))
task = Task(command)
task.Run(1, 0)
timeout = 300
start = datetime.now()
plugin.start_time = float(time.time())
while not task.Done():
time.sleep(0.1)
now = datetime.now()
if (now - start).seconds > timeout:
task.Kill()
logger.warning("Could not start %s, returning after %s second(s) wait time." % (command, timeout))
# notify result to server
if notify:
if not process:
logger.debug("plugin (%s) has an unknown state" % (name))
Output.plugin_state(Watchdog.PLUGIN_UNKNOWN_STATE_MSG % (id))
elif Watchdog.pidof(process, process_aux) is not None:
logger.info(WATCHDOG_PROCESS_STARTED % (process, id))
Output.plugin_state(Watchdog.PLUGIN_START_STATE_MSG % (id))
for pid in Watchdog.__pluginID_stoppedByServer:
if pid == id:
Watchdog.__pluginID_stoppedByServer.remove(id)
break
else:
logger.warning(WATCHDOG_ERROR_STARTING_PROCESS % (process, id))
示例5: run
# 需要导入模块: from Output import Output [as 别名]
# 或者: from Output.Output import plugin_state [as 别名]
def run(self):
first_run = True
while not Watchdog.__shutdown_running:
tzone = str(self.conf.get("plugin-defaults", "tzone"))
if tzone in all_timezones:
agent_tz = timezone(tzone)
local_dt = agent_tz.localize(datetime.now())
str_tzone = time.strftime("%z")
matches = self.patternlocalized.match(str_tzone)
if type(matches) is not None:
tzone_symbol = matches.group("tzone_symbol")
tzone_hour = matches.group("tzone_hour")
tzone_min = matches.group("tzone_min")
tzone = (float(tzone_hour) * 60 + float(tzone_min)) / 60
if tzone_symbol == "-":
tzone = -1 * tzone
else:
tzone = 0
logger.info("Warning: TimeZone doesn't match: %s --set to 0" % tzone)
else:
logger.info("Warning: Agent invalid agent tzone: %s --set to 0" % tzone)
tzone = 0
t = datetime.now()
Output.plugin_state(self.AGENT_DATE % (str(mktime(t.timetuple())), tzone))
logger.info(self.AGENT_DATE % (str(time.mktime(t.timetuple())), tzone))
for plugin in self.plugins:
id = plugin.get("config", "plugin_id")
process = plugin.get("config", "process")
process_aux = plugin.get("config", "process_aux")
name = plugin.get("config", "name")
logger.debug("Checking process %s for plugin %s." \
% (process, name))
sttopedBySrv = False
for pid in Watchdog.__pluginID_stoppedByServer:
if pid == id:
sttopedBySrv = True
break
# 1) unknown process to monitoring
if not process:
logger.debug("plugin (%s) has an unknown state" % (name))
Output.plugin_state(self.PLUGIN_UNKNOWN_STATE_MSG % (id))
# 2) process is running
elif self.pidof(process, process_aux) is not None:
logger.debug("plugin (%s) is running" % (name))
Output.plugin_state(self.PLUGIN_START_STATE_MSG % (id))
# check for for plugin restart
self._restart_services(plugin)
# 3) process is not running
else:
logger.debug("plugin (%s) is not running" % (name))
Output.plugin_state(self.PLUGIN_STOP_STATE_MSG % (id))
# restart services (if start=yes in plugin
# configuration and plugin is enabled)
if plugin.getboolean("config", "start") and \
plugin.getboolean("config", "enable") and not sttopedBySrv:
self.start_process(plugin)
if self.pidof(process, process_aux) is not None and not first_run:
Stats.watchdog_restart(process)
# send plugin enable/disable state
if plugin.getboolean("config", "enable"):
logger.debug("plugin (%s) is enabled" % (name))
Output.plugin_state(self.PLUGIN_ENABLE_STATE_MSG % (id))
else:
logger.debug("plugin (%s) is disabled" % (name))
Output.plugin_state(self.PLUGIN_DISABLE_STATE_MSG % (id))
time.sleep(float(self.interval))
first_run = False