Sha256: 879bc59c13c16ee4fe84d9f2d890be730c6fe50d6137bda33f78958842c014ef

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

# read the /etc/openvpn/openvpn-status.log file
require "zabbix-ruby-client/logger"
require "zabbix-ruby-client/plugin_base"

module ZabbixRubyClient
  module Plugins
    module Ovpn
      extend self
      extend ZabbixRubyClient::PluginBase

      def collect(*args)
        host = args[0]
        ovpnfile = args[1]
        info = get_info(ovpnfile)
        back = []
        if info
          time = Time.now.to_i
          back << "#{host} ovpn[received] #{time} #{info['received']}"
          back << "#{host} ovpn[sent] #{time} #{info['sent']}"
          back << "#{host} ovpn[count] #{time} #{info['count']}"
        end
        back
      end

    private

      def get_info(ovpnfile)
        ret = {}
        info = getlines(ovpnfile, "[^,]*,[^,]*,.* [0-9]{4}")
        if info
          received = 0
          sent = 0
          count = 0
          info.each do |line|
            if line[0] =~ /^[a-z]/
              back = line.split(',')
              received += back[2].to_i
              sent += back[3].to_i
              count += 1
            end
          end
          ret["received"] = received
          ret["sent"] = sent
          ret["count"] = count
          ret
        else
          false
        end
      end

    end
  end
end

ZabbixRubyClient::Plugins.register('ovpn', ZabbixRubyClient::Plugins::Ovpn)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.1.2 lib/zabbix-ruby-client/plugins/ovpn.rb
zabbix-ruby-client-0.1.1 lib/zabbix-ruby-client/plugins/ovpn.rb
zabbix-ruby-client-0.1.0 lib/zabbix-ruby-client/plugins/ovpn.rb
zabbix-ruby-client-0.0.23 lib/zabbix-ruby-client/plugins/ovpn.rb
zabbix-ruby-client-0.0.22 lib/zabbix-ruby-client/plugins/ovpn.rb
zabbix-ruby-client-0.0.21 lib/zabbix-ruby-client/plugins/ovpn.rb