Ejemplo n.º 1
0
    def put(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)

        if request.is_json and request.get_json(silent=True) is not None:
            try:
                post_data = request.get_json()

                command_line = post_data.get('command_line')

                if not command_line:
                    return jsonify(error=True,msg="Command line empty.")

                command.command_line = command_line

                writeNagiosCommandsConfigFile(command)
                if restartNagios() == False:
                    db.session.rollback()
                    syncNagiosAllConfigWithDb()
                    return jsonify(error=True, msg="Invalid process")
                    
                db.session.commit()
                return jsonify(data=command.serialize())
            except Exception as e:
                db.session.rollback()
                syncNagiosAllConfigWithDb()
                return jsonify(error=True, msg=str(e))
            finally:
                db.session.close()
        return jsonify(error=True)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def get(self, jwt, command_id):
        data = []

        #If no command_id is passed in get all commands.
        if command_id is None:
            commands = Command.get_all()
        else:
            commands = [Command.get_by_id(command_id)]

        #Loop over results and get json form of command to return.
        if commands is not None:
            for command in commands:
                data.append(command.serialize())
                pass
            return jsonify(data=data)
        else:
            return jsonify(data=[])