using saltstack how to write a custom beacon

339 Views Asked by At

using saltstack how to write a custom beacon that will generate event if the state of service/agent in linux changes. that is from running to stopped

#!/bin/python
import psutil
def status(service):
for proc in psutil.process_iter():
    if proc.name() == service:
       result=True
       return result

This piece of code will check if service/agent is running.if running it will return true else none.I want to make this code part of custom beacon and if result is none custom beacon should trigger event to event bus system.this is for linux environment.

1

There are 1 best solutions below

0
laocius On

You don't need to write your custom module, SaltStack already has a built-in service beacon. All you need to do is define the beacon.

beacons:
  service:
    - services:
        nginx:
          onchangeonly: True
          delay: 30
          uncleanshutdown: /run/nginx.pid