1

I have created a dashboard using us map widgets in dashing using following git link:

https://gist.github.com/jrunge/acd98d3d550911bdc4b5

Can anybody tell me how to create the custom job to populate data to be sent to widget? The JSON data follows this format

{
  "points": [
    {
      "id": 12345,
      "lat": 35,
      "lon": -70,
      "type": "red"
    },
    {
      "id": 678910,
      "lat": 35,
      "lon": -70,
      "type": "green"
    }
  ]
}

Do I need to create a shell script or command to populate the data.

sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
user3086014
  • 4,241
  • 5
  • 27
  • 56

2 Answers2

1

Just create a ruby script in jobs directory
jobs/us-map.rb

SCHEDULER.every '2s' do
  us_map_details = {
    "points": [
      {
        "id": 12345,
        "lat": 35,
        "lon": -70,
        "type": "red"
      },
      {
        "id": 678910,
        "lat": 35,
        "lon": -70,
        "type": "green"
      }
    ]
  }
  # You can change the hash us_map_details to add/change/remove points
  another_point = {"id": 1729, "lat": 30, "lon": -60, "type": "red" }
  us_map_details[:points] << another_point

  send_event('usmap', us_map_details) # This is where data is sent to dashboard
end  

The SCHEDULER object is an instance of rufus scheduler. You can populate data by populating us_map_details hash

sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
0

You have two way to populate a widget.

first is the Scheduler job. You can create one with the command

dashing generate job [Name_Of_Job]

Secondly, you can send data to the widget by using the curl command:

curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "text": "Hey, Look what I can do!" }' http://<%=request.host%>:<%=request.port%>/widgets/welcome
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Karatyus
  • 1
  • 3