<commit_before>#! /usr/bin/env ruby
#
#   metrics-unifi.rb
#
# DESCRIPTION:
#   This plugin collects metrics from a Unifi wireless controller
#
# OUTPUT:
#   metric data
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#
# USAGE:
#   metrics-unifi.rb -c unifi.int.mycompany.co -u admin -p unifipassword
#
# NOTES:
#
#
# LICENSE:
#   Copyright <NAME> <<EMAIL>>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/metric/cli'
require 'socket'
require 'unifi/api'

# Collect unifi metrics
class UnifiMetrics < Sensu::Plugin::Metric::CLI::Graphite
  option :scheme,
         description: 'Metric naming scheme, text to prepend to metric',
         short: '-s SCHEME',
         long: '--scheme SCHEME',
         default: "#{Socket.gethostname}.unifi"

  option :controller,
         description: 'Unifi AP controller hostname',
         short: '-c HOSTNAME',
         long: '--controller HOSTNAME',
         default: 'unifi'

  option :username,
         description: 'Username',
         short: '-u USERNAME',
         long: '--username USERNAME',
         default: 'admin'

  option :password,
         description: 'Password',
         short: '-p PASSWORD',
         long: '--password PASSWORD',
         required: true

  option :port,
         description: 'Port',
         short: '-P PORT',
         long: '--port PORT',
         default: 8443

  option :unifi_version,
         description: 'Unifi API version',
         short: '-V VERSION',
         long: '--unifi-version VERSION',
         default: 'v4'

  def unifi_stats
    unifi = Unifi::Api::Controller.new(config[:controller], config[:username], config[:password], config[:port], config[:unifi_version])
    aps = unifi.get_aps

    metrics = Hash.new(0)

    aps.each do |ap|
      metrics['total'] += ap['num_sta']
      metrics['guests'] += ap['guest-num_sta']
      metrics['users'] += ap['user-num_sta']
    end

    metrics
  end

  def run
    metrics = unifi_stats
    metrics.each do |metric, value|
      output "#{config[:scheme]}.#{metric}", value
    end
    ok
  end
end<commit_msg>remove a variable used once<commit_after>#! /usr/bin/env ruby
#
#   metrics-unifi.rb
#
# DESCRIPTION:
#   This plugin collects metrics from a Unifi wireless controller
#
# OUTPUT:
#   metric data
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#
# USAGE:
#   metrics-unifi.rb -c unifi.int.mycompany.co -u admin -p unifipassword
#
# NOTES:
#
#
# LICENSE:
#   Copyright <NAME> <<EMAIL>>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/metric/cli'
require 'socket'
require 'unifi/api'

# Collect unifi metrics
class UnifiMetrics < Sensu::Plugin::Metric::CLI::Graphite
  option :scheme,
         description: 'Metric naming scheme, text to prepend to metric',
         short: '-s SCHEME',
         long: '--scheme SCHEME',
         default: "#{Socket.gethostname}.unifi"

  option :controller,
         description: 'Unifi AP controller hostname',
         short: '-c HOSTNAME',
         long: '--controller HOSTNAME',
         default: 'unifi'

  option :username,
         description: 'Username',
         short: '-u USERNAME',
         long: '--username USERNAME',
         default: 'admin'

  option :password,
         description: 'Password',
         short: '-p PASSWORD',
         long: '--password PASSWORD',
         required: true

  option :port,
         description: 'Port',
         short: '-P PORT',
         long: '--port PORT',
         default: 8443

  option :unifi_version,
         description: 'Unifi API version',
         short: '-V VERSION',
         long: '--unifi-version VERSION',
         default: 'v4'

  def unifi_stats
    unifi = Unifi::Api::Controller.new(config[:controller], config[:username], config[:password], config[:port], config[:unifi_version])
    aps = unifi.get_aps

    metrics = Hash.new(0)

    aps.each do |ap|
      metrics['total'] += ap['num_sta']
      metrics['guests'] += ap['guest-num_sta']
      metrics['users'] += ap['user-num_sta']
    end

    metrics
  end

  def run
    unifi_stats.each do |metric, value|
      output "#{config[:scheme]}.#{metric}", value
    end
    ok
  end
end
{'fraction_non_alphanumeric': 0.13666197843413033, 'fraction_numerical': 0.0028129395218002813, 'mean_word_length': 2.585714285714286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4374519', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1369, 'n_words': 369}