-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspritMon.rb
More file actions
executable file
·76 lines (64 loc) · 1.77 KB
/
spritMon.rb
File metadata and controls
executable file
·76 lines (64 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env ruby
require 'json'
require 'net/http'
#config
lat = 48.714692
long = 9.089853
radius = 4
showOnly = ['ElaBo', 'PuQi', '6L8MF']
displayName = { "ElaBo" => 'JET Industriestrasse', "PuQi" => "Aral RobertKochStrasse", "6L8MF" => "Shell Industriestrasse" }
hostname=`hostname -f`.gsub("\n", "")
interval=-60
class Tankstelle
attr_accessor :id, :diesel, :e5, :e10, :name, :strasse, :ort
def initialize(id, diesel, e5, e10, name, strasse, ort)
@id = id
@diesel = diesel
@e5 = e5
@e10 = e10
@name = name
@strasse = strasse
@ort = ort
end
end
def getData(lat, long, radius)
url = "http://www.tanke-guenstig.de/Benzinpreise/ajax/area?c=#{lat}%2C#{long}&r=#{radius}"
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
result = JSON.parse(data)
if result.has_key? 'Error'
raise "web service error"
end
return result
end
data = getData(lat, long, radius)
objects = data['d'].map { |tk| Tankstelle.new( tk['h'], tk['pr']['d'], tk['pr']['e5'], tk['pr']['e10'], tk['na'], tk['addr']['street'], tk['addr']['city'] ) }
config = (ARGV[0] == "config")
dump = (ARGV[0] == "dump")
collectd = (ARGV[0] == "collectd")
if config then
print "graph_title Benzinpreise\n"
print "graph_vlabel EUR\n"
print "graph_scale yes\n"
print "graph_category car\n"
end
objects.each {|t|
if displayName[t.id] then
t.name = displayName[t.id]
end
if dump then
p t
else
if showOnly.include? t.id then
if collectd then
print "PUTVAL #{hostname}/benzinpreis-sb/absolute-#{t.name.gsub(" ","_")} interval=#{interval} N:#{t.diesel.gsub(".", "")}\n"
else
if config then
print "#{t.id}.label #{t.name}\n"
else
print "#{t.id}.value #{t.diesel}\n"
end
end
end
end
}