require 'net/ssh'

staros_thr_1233 = []
conf = {}

staros_hosts = {
    #5700
}

def printer (config)
  for gggg1 in config

    p ""
    p ""
    p "##{gggg1[0]}"
    for jjj in gggg1[1]
      p jjj
    end
  end
end

staros_hosts.each do |ggsn|
  staros_thr_1233 << Thread.new do

    p ggsn

    begin

      conf[ggsn[0]] = []

      Net::SSH.start(ggsn[1], "ывапывап", :password => "пыапыва") do |ssh|
        staros_answer = ssh.exec!("show configuration context Ga | grep edr")

        regexp = /file name (\S+) rotation volume (\d+) rotation time \d+ storage-limit \d+ headers edr-format-name compression gzip file-sequence-number rulebase-seq-num/

        ggg = staros_answer.match(regexp)
        conf[ggsn[0]].push("configure")
        conf[ggsn[0]].push("context Ga")
        conf[ggsn[0]].push("edr-module active-charging-service charging")
        conf[ggsn[0]].push("file name #{ggg[1]} rotation volume 40000000 rotation time 600 storage-limit 536870912 headers edr-format-name compression gzip file-sequence-number rulebase-seq-num")
        conf[ggsn[0]].push("end")

        #config
        # staros_answer1 = ssh.exec!("configure")
        # p staros_answer1
        # staros_answer2 = ssh.exec!("context Ga")
        # p staros_answer2
        # staros_answer3 = ssh.exec!("edr-module active-charging-service charging")
        # p staros_answer3
        # staros_answer4 = ssh.exec!("file name #{ggg[1]} rotation volume 40000000 rotation time 600 storage-limit 536870912 headers edr-format-name compression gzip file-sequence-number rulebase-seq-num")
        # p staros_answer4
        # staros_answer5 = ssh.exec!("end")
        # p staros_answer5

        #check
        staros_answer7 = ssh.exec!("show configuration | grep hostname")
        reggg = /system hostname (\S+)/
        hostname_this = staros_answer7.match(reggg)[1]

        staros_answer8 = ssh.exec!("show configuration context Ga | grep edr")
        regexp2 = /file name (\S+) rotation volume (\d+) rotation time \d+ storage-limit \d+ headers edr-format-name compression gzip file-sequence-number rulebase-seq-num/

        ggg2 = staros_answer8.match(regexp2)

        a1 = ggg2[1].gsub("edr-", "")
        #p a1
        #p hostname_this
        #p ggg2

        if a1 != hostname_this
          p "incorrect: #{hostname_this}"
        end


        if ggg2[2] == "40000000"
        else
          p "incorrect value: #{hostname_this}"
        end

      end

    rescue

      p "#{ggsn[0]} ERROR"

    end

  end
end
staros_thr_1233.each(&:join)

#p conf


#printer(conf)