lib/imperituroard/projects/ukaz60/ukaz60_add_func.rb in imperituroard-1.1.7 vs lib/imperituroard/projects/ukaz60/ukaz60_add_func.rb in imperituroard-1.1.8
- old
+ new
@@ -152,10 +152,56 @@
add_functions.printer_texter(output_data, "debug")
output_data
end
+ def ansible_answer_parse_fmg(answer_string)
+ input_data = {:answer_string => answer_string}
+ output_data = {}
+
+ begin
+ answ_ans_parsed = answer_string.gsub("\n", " ")
+ result_out = {}
+ #result_out = []
+ num_ok = 0
+ num_failed = 0
+ #final_checks = /(fortimanager1)\s+:\s+ok=(\d)\s+changed=(\d)\s+unreachable=(\d)\s+failed=(\d)\s+/
+ final_checks = /(fortimanager1)\s+:\s+ok=(\d+)\s+changed=(\d+)\s+unreachable=(\d+)\s+failed=(\d+)\s+/
+
+ #p answ_ans_parsed
+ processed_data = answ_ans_parsed.scan(final_checks)
+ #p processed_data
+ if processed_data!=[] && processed_data!=""
+ for aaa in processed_data
+ begin
+ if aaa[1].to_i>0 && aaa[3].to_i==0 && aaa[4].to_i==0
+ result_out[aaa[0]] = {:ok => aaa[1], :changed => aaa[2], :unreachable => aaa[3], :failed => aaa[4], :result => "Ok"}
+ #result_out.push({aaa[0] => "Ok"})
+ num_ok = num_ok + 1
+ else
+ result_out[aaa[0]] = {:ok => aaa[1], :unreachable => aaa[3], :failed => aaa[4], :result => "Failed"}
+ #result_out.push({aaa[0] => "Failed"})
+ num_failed = num_failed + 1
+ end
+ rescue
+ result_out["unknown"] = aaa.to_s
+ #result_out.push({"unknown" => aaa.to_s})
+ num_failed = num_failed + 1
+ end
+ end
+ output_data = {:code => 200, :result => "ansible_answer_parse: Request completed successfully", :body => {:list => result_out, :num_ok => num_ok, :num_failed => num_failed}}
+ else
+ output_data = {:code => 400, :result => "ansible_answer_parse: Ansible returned empty data"}
+ end
+ rescue
+ output_data = {:code => 507, :result => "ansible_answer_parse: Unknown error"}
+ end
+ add_functions.printer_texter(output_data, "debug")
+ output_data
+ end
+
+
def https_to_forti_prep(domain)
f0 = domain.gsub("#", "")
f1 = f0.gsub("https://", "").split("/")
f1[0]
end
@@ -246,14 +292,14 @@
rescue
output_answ = {:code => 507, :result => "staros_compare_http: Unknown SDK error"}
end
#p JSON.pretty_generate(output_answ)
- p "staros_compare_http"
- p output_answ
+ #p "staros_compare_http"
+ #p output_answ
- p "temp data"
+ #p "temp data"
for i in output_answ[:body][:for_unblock][:for_unblock]["vit11asr2"]
#for i in output_answ[:body][:for_block][:not_blocked_belgim]["vit11asr2"]
p i
end
output_answ
@@ -278,10 +324,10 @@
else
notbl_equal = 1
end
end
- p notbl_equal
+ #p notbl_equal
if notbl_equal == 0
block_me = {:for_block_count => data[:body][:for_block][:notblocked_stat][compa_n_data]}
unblock_me = {:for_unblock_count => data[:body][:for_unblock][:for_unblock_stat][compa_n_data]}
if block_me[:for_block_count] != 0 && unblock_me[:for_unblock_count] != 0