class Ukaz60Staros_2

Attributes

staros_hosts[RW]
staros_platform_get[RW]
ukaz60_http_groups[RW]
ukaz60_https_groups[RW]

Public Class Methods

new(star_login, star_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts) click to toggle source
# File lib/imperituroard/projects/ukaz60/staros.rb, line 16
def initialize(star_login, star_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts)
  @staros_platform_get = StarosGet_2.new(star_login, star_password)
  @ukaz60_http_groups = ukaz60_http_groups
  @ukaz60_https_groups = ukaz60_https_groups
  @staros_hosts = staros_hosts
end

Public Instance Methods

get_all_staros_ukaz60() click to toggle source

procedure for get data from all MPC

# File lib/imperituroard/projects/ukaz60/staros.rb, line 103
def get_all_staros_ukaz60

  returned_data = {:mpc_data => [], :add_format => {}}
  get_all_staros_ukaz60_1 = []

  begin
    staros_hosts.each do |ggsn|
      get_all_staros_ukaz60_1 << Thread.new do
        begin
          mpc_data = self.get_data_staros(ggsn[1])
          returned_data[:mpc_data].push({:code => 200, :result => "Success", :hostname => ggsn[0], :host_ip => ggsn[1], :body => mpc_data})
          returned_data[:add_format][ggsn[0]] = mpc_data
        rescue
          returned_data[:mpc_data].push({:code => 507, :result => "Unknown thread error", :hostname => ggsn[0], :host_ip => ggsn[1], :body => {}})
        end
      end
    end
    get_all_staros_ukaz60_1.each(&:join)
    returned_data[:code] = 200
    returned_data[:result] = "get_all_staros_ukaz60: Success"
  rescue
    returned_data[:code] = 507
    returned_data[:result] = "get_all_staros_ukaz60: Unknown SDK error"
  end
  returned_data
end
get_data_staros(ip_staros) click to toggle source

get data from staros and return urls from staros

# File lib/imperituroard/projects/ukaz60/staros.rb, line 25
def get_data_staros(ip_staros)

  input_data = {:ip_staros => ip_staros}
  output_data = {}
  ecs_name = ""
  blocked_urls_http = []
  blocked_urls_https = []

  begin
    ecs_config_json = staros_platform_get.get_all_active_charging(ip_staros)

    if ecs_config_json[:code] == 200

      #get ecs name
      ecs_sss = ecs_config_json[:parsed_data]["config"]["active-charging service"][0]
      ecs_sss.each do |hhh|
        ecs_name = hhh[0]
      end

      regexp_ruldef = /add-ruledef priority \d+ ruledef (.+)/

      #for http urls
      begin
        ukaz60_http_groups.each do |rule|
          group_ruled_ukaz60 = ecs_config_json[:parsed_data]["config"]["active-charging service"][0][ecs_name]["group-of-ruledefs"][rule]

          group_ruled_ukaz60.each do |gr_rul_str|
            ruledef_name = gr_rul_str.match(regexp_ruldef)[1]
            rdef_config = ecs_config_json[:parsed_data]["config"]["active-charging service"][0][ecs_name]["ruledef"][ruledef_name]
            rdef_config.each do |g|
              if g[0..15] == "www url contains"
                blocked_urls_http.push({:url => g.gsub("www url contains ", ""), :ruledef => ruledef_name, :gr_of_ruledefs => rule, :gr_rul_str => gr_rul_str})
              end
            end
          end
        end
      rescue
        blocked_urls_http.push("failed")
      end

      for https_rule in ukaz60_https_groups
        group_rule_https = ecs_config_json[:parsed_data]["config"]["active-charging service"][0][ecs_name]["group-of-ruledefs"][https_rule]
      end

      output_data = {:code => 200, :result => "Success", :ecs_name => ecs_name, :blocked_urls_http => blocked_urls_http, :http_rules_num => blocked_urls_http.length}

    else
      output_data = ecs_config_json
    end
  rescue
    output_data = {:code => 507, :result => "get_data_staros: Unknown SDK error"}
  end
  output_data
  # Net::SSH.start("172.24.214.17", "starscript", :password => "$rfv3EDC") do |ssh|
  #   staros_answer = ssh.exec!("show configuration active-charging service all")
  #   p staros_answer
  #
  #   staros_answer = staros_answer.gsub("\n", "")
  #
  #   regexp_ukaz60_9 = /group-of-ruledefs Ukaz60-9_HTTP.+HTTP\s+#exit/
  #   regexp_ukaz60_https = /group-of-ruledefs Ukaz60_HTTPS.+HTTPS\s+#exit/
  #   regexp_ukaz60_7 = /group-of-ruledefs Ukaz60-7_HTTP.+HTTP\s+#exit/
  #
  #
  #
  #   group_ruled_ukaz60_9 = staros_answer.match(regexp_ukaz60_9)[0]
  #   group_ruled_ukaz60_https = staros_answer.match(regexp_ukaz60_https)[0]
  #   group_ruled_ukaz60_7 = staros_answer.match(regexp_ukaz60_7)[0]
  #
  #   p group_ruled_ukaz60_9
  #   p group_ruled_ukaz60_https
  #   p group_ruled_ukaz60_7
  #
  # end
end