diff options
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/agents_controller.rb | 74 | ||||
| -rw-r--r-- | app/controllers/events_controller.rb | 12 |
2 files changed, 84 insertions, 2 deletions
diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb new file mode 100644 index 0000000..a76a7ae --- /dev/null +++ b/app/controllers/agents_controller.rb @@ -0,0 +1,74 @@ +class AgentsController < ApplicationController + before_action :set_agent, only: [:show, :edit, :update, :destroy] + + # GET /agents + # GET /agents.json + def index + @agents = Agent.all + end + + # GET /agents/1 + # GET /agents/1.json + def show + end + + # GET /agents/new + def new + @agent = Agent.new + end + + # GET /agents/1/edit + def edit + end + + # POST /agents + # POST /agents.json + def create + @agent = Agent.new(agent_params) + + respond_to do |format| + if @agent.save + format.html { redirect_to @agent, notice: 'Agent was successfully created.' } + format.json { render :show, status: :created, location: @agent } + else + format.html { render :new } + format.json { render json: @agent.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /agents/1 + # PATCH/PUT /agents/1.json + def update + respond_to do |format| + if @agent.update(agent_params) + format.html { redirect_to @agent, notice: 'Agent was successfully updated.' } + format.json { render :show, status: :ok, location: @agent } + else + format.html { render :edit } + format.json { render json: @agent.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /agents/1 + # DELETE /agents/1.json + def destroy + @agent.destroy + respond_to do |format| + format.html { redirect_to agents_url, notice: 'Agent was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_agent + @agent = Agent.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def agent_params + params.require(:agent).permit(:hostname) + end +end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 96a51f0..6a8fe42 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,4 +1,6 @@ class EventsController < ApplicationController + before_action :load_agent + def index @events = Event.all end @@ -8,8 +10,8 @@ class EventsController < ApplicationController end def create - Publisher.publish("events", event_params) - redirect_to events_path, notice: 'Event was successfully created.' + Publisher.publish("events", event_params.merge({agent_id: @agent.id})) + redirect_to agent_events_path, notice: 'Event was successfully created.' end def destroy @@ -18,7 +20,13 @@ class EventsController < ApplicationController redirect_to events_url, notice: 'Event was successfully destroyed.' end + private + def event_params params.require(:event).permit(:name, :data) end + + def load_agent + @agent = Agent.find(params[:agent_id]) + end end |
