from datetime import datetime from flask import jsonify from flask_jwt_extended import jwt_required from interfaces import dispatcher, AppBlueprint from walkoff.events import WalkoffEvent from walkoff.security import jwt_required_in_query from walkoff.sse import InterfaceSseStream, create_interface_channel_name metrics_stream = InterfaceSseStream('HelloWorld', 'metrics') blueprint = AppBlueprint('HelloWorldPage__', __name__, streams=[metrics_stream]) hello_world_channel_names = {} def retrieve_actions(): return {action: blueprint.cache.get(channel_name) for action, channel_name in hello_world_channel_names.items()} @dispatcher.on_app_actions('HelloWorld', events=WalkoffEvent.ActionStarted, weak=False) def handle_action_start(data): action_name = data['action_name'] if action_name not in hello_world_channel_names: hello_world_channel_names[action_name] = \ create_interface_channel_name('HelloWorld', 'action_{}'.format(action_name)) blueprint.cache.incr(hello_world_channel_names[action_name])
from interfaces import dispatcher, AppBlueprint from walkoff.events import WalkoffEvent from flask import Blueprint, jsonify, request from flask_jwt_extended import jwt_required import json blueprint = AppBlueprint(blueprint=Blueprint('Bro_Demo', __name__)) analysis_data = {'dns': None, 'http': None} analysis_filenames = { 'dns': "dnsWalkoffBroAnalysis.json", 'http': "httpWalkoffBroAnalysis.json" } @dispatcher.on_app_actions('Bro', actions=['make http netmap'], events=WalkoffEvent.ActionExecutionSuccess) def get_netmap(data): global netmap global netmap_filename netmap_filename = data['data']['result'] with open(netmap_filename, 'r') as f: netmap = json.load(f) @dispatcher.on_app_actions('Bro', actions=['analyze log'], events=WalkoffEvent.ActionExecutionSuccess) def get_analysis(data):
import random from gevent import sleep from gevent import spawn from gevent.event import Event, AsyncResult from interfaces import AppBlueprint from walkoff.sse import InterfaceSseStream counter_stream = InterfaceSseStream('Sample', 'counter') random_stream = InterfaceSseStream('Sample', 'random') blueprint = AppBlueprint('HelloWorldPage', __name__, streams=(counter_stream, random_stream)) blueprint2 = AppBlueprint('HelloWorldPage2', __name__, url_prefix='/<string:action>') __sync_signal = Event() random_event_result = AsyncResult() def load(*args, **kwargs): return {} # These blueprints will be registered with the Flask app and can be used to make your own endpoints. @blueprint.route('/test_blueprint') def test_basic_blueprint(): # This can be called using the url /apps/HelloWorld/test_blueprint
from interfaces import dispatcher, AppBlueprint from core.events import WalkoffEvent from flask import Blueprint, jsonify, Response from flask_jwt_extended import jwt_required from gevent import sleep from gevent.event import AsyncResult, Event import json from datetime import datetime from server.security import jwt_required_in_query from core.helpers import create_sse_event blueprint = AppBlueprint(blueprint=Blueprint('HelloWorldPage__', __name__)) hello_world_action_count = {} action_event_json = AsyncResult() action_signal = Event() action_event_id_counter = 0 @dispatcher.on_app_actions('HelloWorld', events=WalkoffEvent.ActionStarted, weak=False) def handle_action_start(data): global hello_world_action_count action_name = data['action_name'] if action_name not in hello_world_action_count: hello_world_action_count[action_name] = 1 else:
from interfaces import dispatcher, AppBlueprint from walkoff.events import WalkoffEvent from flask import Blueprint, jsonify import json blueprint = AppBlueprint(blueprint=Blueprint('NOVAS_Demo', __name__)) latest_graph = "WalkoffDemoGraph.json" @dispatcher.on_app_actions('Nmap', actions=['graph from results'], events=WalkoffEvent.ActionExecutionSuccess) def get_latest_graph(data): global latest_graph latest_graph = data['arguments'][3]['value'] @blueprint.blueprint.route('/demo', methods=['GET']) def read_and_send_graph(): try: global latest_graph with open(latest_graph) as f: r = jsonify(json.load(f)) return r, 200 except IOError: return None, 461
import time import random from flask import Blueprint, Response from interfaces import AppBlueprint from threading import Thread from gevent.event import Event, AsyncResult from gevent import sleep blueprint = AppBlueprint(blueprint=Blueprint('HelloWorldPage', __name__)) blueprint2 = AppBlueprint(blueprint=Blueprint('HelloWorldPage2', __name__), rule='/<string:action>') __sync_signal = Event() random_event_result = AsyncResult() def load(*args, **kwargs): return {} # These blueprints will be registered with the Flask app and can be used to make your own endpoints. @blueprint.blueprint.route('/test_blueprint') def test_basic_blueprint(): # This can be called using the url /apps/HelloWorld/test_blueprint return 'successfully called basic blueprint' def random_number_receiver(): while True: data = random_event_result.get() yield 'data: %s\n\n' % data