Beispiel #1
0
    def delete(self, jwt, command_id):
        if command_id is None:
            return jsonify(error=True)

        command = Command.get_by_id(command_id)
        if command is None:
            return jsonify(error=True)
        else:
            try:
                # check if services exist related to this command
                services = Service.get_all_by_command_name(command.command_name)
                if services is not None and len(services) > 0:
                    return jsonify(error=True,msg="Failed to delete because there are services that's using the command!")

                deleteNagiosCommandsConfigFile(command)
                db.session.delete(command)
                db.session.commit()
                return jsonify(error=False)
            except Exception as e:
                db.session.rollback()
                syncNagiosAllConfigWithDb()
                return jsonify(error=True, msg=str(e))
            finally:
                db.session.close()
        return jsonify(error=True)