wip: ldap & ng ideas

This commit is contained in:
2023-07-08 20:49:58 +02:00
parent da2fcadf1b
commit cdc75634e3
3 changed files with 168 additions and 0 deletions

View File

@@ -86,6 +86,38 @@ def sendToAllIcinga():
sendMessageToAllClients(message)
return ("","204")
@app.route('/smart-send', methods=["POST"])
@login_required
def smart_send_to_clients():
'''Send to clients based on querying the LDAP
requests MAY include:
- list of usernames under key "users"
- list of groups under key "groups"
- neither of the above to automatically target the configured administrators group"
retuest MUST include:
- message as STRING in field "msg"
OR
- supported struct of type "ICINGA|ZABBIX|GENERIC" (see docs) in field "data"
'''
instructions = flask.request.json
users = instructions.get("users")
groups = instructions.get("groups")
message = instructions.get("msg")
struct = instructions.get("data")
if struct:
try:
message = messagetools.load_struct(struct)
except messagetools.UnsupporedStruct() as e:
return (408, e.response())
persons = ldaptools.select_targets(users, groups, app.config["LDAP_ARGS"])
signal.bulk_dispatch(persons, message)
return (200, "OK")
@app.before_first_request
def init():
app.config["PASSWORD"] = os.environ["SIGNAL_API_PASS"]
@@ -99,8 +131,28 @@ if __name__ == "__main__":
parser.add_argument('--port', default="5000", help='Port on which to listen')
parser.add_argument("--signal-cli-bin", default=None, type=str,
help="Path to signal-cli binary if no in $PATH")
parser.add_argument('--ldap-server')
parser.add_argument('--ldap-base-dn')
parser.add_argument('--ldap-manager-dn')
parser.add_argument('--ldap-manager-password')
args = parser.parse_args()
# define ldap args #
ldap_args = {
"LDAP_SERVER" : args.ldap_server,
"LDAP_BIND_DN" : args.manager_dn,
"LDAP_BIND_PW" : args.manager_password,
"LDAP_BASE_DN" : args.ldap_base_dn,
}
if not any([value is None for value in ldap_args.values()]):
app.config["LDAP_ARGS"] = ldap_args
else:
app.config["LDAP_ARGS"] = None
app.config["SIGNAL_CLI_BIN"] = os.path.expanduser(args.signal_cli_bin)
app.config["PASSWORD"] = os.environ["SIGNAL_API_PASS"]