192 | | experiment-generated measurement reaches a specific value. In the above script, an event will be triggered when Node A is able to ping all the other nodes in the topology. It will then trigger a ping event to itself on Node A. If a ping with the IP address of Node A is also seen on the graph, the experiment ran successfully. |
| 192 | experiment-generated measurement reaches a specific value. In the script below, MY_EVENT is the user-defined event. The function will be called every 0.5 seconds. It queries the specified stats and checks if Node A is able to ping all other nodes. The event will be triggered once that condition is satisfied. Then, ping application to itself is started on Node A. If a ping with the IP address of Node A is also seen on the graph, the experiment ran successfully. |
| 193 | |
| 194 | {{{ |
| 195 | #!ruby |
| 196 | defEvent(:MY_EVENT, every: 0.5) do |
| 197 | # Query for some measurements... |
| 198 | # returns an array where each element is a hash representing a row from the DB |
| 199 | query = ms('ping').select { [ :remote] } |
| 200 | data = defQuery(query) |
| 201 | # Alternatively the above line could also be: |
| 202 | # data = defQuery('select oml_ts_client, value from signalgen_sin') |
| 203 | # |
| 204 | # Also if you want to rename 'oml_ts_client' to 'ts' |
| 205 | # query = ms('sin').select { [ oml_ts_client.as(:ts), :value ] } |
| 206 | # data = defQuery('select oml_ts_client as ts, value from signalgen_sin') |
| 207 | |
| 208 | triggered = false |
| 209 | if !data.nil? && !(last_row = data.pop).nil? # Make sure we have some data |
| 210 | next if peak_list.include?(last_row[:remote]) # Do nothing if we have seen this sample before |
| 211 | if !peak_list.include?(last_row[:remote]) |
| 212 | peak_list << last_row[:remote] # record that sample, so we dont trigger on it again |
| 213 | end |
| 214 | if peak_list.include?('192.168.1.9')&&peak_list.include?('192.168.1.7')&&peak_list.include?('192.168.1.8') |
| 215 | |
| 216 | triggered = true |
| 217 | end |
| 218 | end |
| 219 | triggered |
| 220 | end |
| 221 | onEvent :MY_EVENT do |
| 222 | #group('switch').exec("ping www.google.com") |
| 223 | group('Source3').startApplications |
| 224 | end |
| 225 | |
| 226 | }}} |