lib/zabbixapi/application.rb in zabbixapi-0.1.6.3 vs lib/zabbixapi/application.rb in zabbixapi-0.1.6.4
- old
+ new
@@ -1,8 +1,8 @@
module Zabbix
-
class ZabbixApi
+
def add_application(app_options)
app_options_default = {
'hostid' => nil,
'name' => nil
}
@@ -12,22 +12,29 @@
'params' => application
}
responce = send_request(message)
responce.empty? ? nil : responce['applicationids'][0].to_i
end
- end
- def get_app_id(host_id, app_name)
- message = {
- 'method' => 'application.get',
- 'params' => {
- 'filter' => {
- 'name' => app_name,
- 'hostid' => host_id
- }
- }
- }
- responce = send_request(message)
- responce.empty? ? nil : responce[0]['applicationid']
- end
+ def add_or_get_application(host_id, app_options)
+ unless a_id = get_app_id(host_id, app_options['name'])
+ a_id = add_application(app_options)
+ end
+ return a_id
+ end
+ def get_app_id(host_id, app_name)
+ message = {
+ 'method' => 'application.get',
+ 'params' => {
+ 'filter' => {
+ 'name' => app_name,
+ 'hostid' => host_id
+ }
+ }
+ }
+ responce = send_request(message)
+ responce.empty? ? nil : responce[0]['applicationid']
+ end
+
+ end
end