Class: Ukaz60All_2
- Inherits:
-
Object
- Object
- Ukaz60All_2
- Defined in:
- lib/imperituroard/projects/ukaz60.rb
Instance Attribute Summary collapse
-
#belgim_connector ⇒ Object
Returns the value of attribute belgim_connector.
-
#belgim_login ⇒ Object
Returns the value of attribute belgim_login.
-
#belgim_password ⇒ Object
Returns the value of attribute belgim_password.
-
#belgim_url ⇒ Object
Returns the value of attribute belgim_url.
-
#forti_connector ⇒ Object
Returns the value of attribute forti_connector.
-
#staros_connector ⇒ Object
Returns the value of attribute staros_connector.
-
#telegram_messanger ⇒ Object
Returns the value of attribute telegram_messanger.
-
#ukaz60_add_func ⇒ Object
Returns the value of attribute ukaz60_add_func.
Instance Method Summary collapse
- #forti_process(get_belgim_data) ⇒ Object
-
#initialize(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url, ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir, staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts) ⇒ Ukaz60All_2
constructor
A new instance of Ukaz60All_2.
- #no_pasaran ⇒ Object
- #staros_process(get_belgim_data) ⇒ Object
Constructor Details
#initialize(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url, ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir, staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts) ⇒ Ukaz60All_2
Returns a new instance of Ukaz60All_2.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 20 def initialize(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url, ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir, staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts ) @telegram_messanger = Telegram_2.new(telegram_api_url, telegram_chat_id) @belgim_login = belgim_login @belgim_password = belgim_password @belgim_url = belgim_url @ukaz60_add_func = AddFuncUkaz60_2.new @belgim_connector = Belgim_2.new(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url) @forti_connector = FortiUkaz60_2.new(ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir) @staros_connector = Ukaz60Staros_2.new(staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts) end |
Instance Attribute Details
#belgim_connector ⇒ Object
Returns the value of attribute belgim_connector.
11 12 13 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 11 def belgim_connector @belgim_connector end |
#belgim_login ⇒ Object
Returns the value of attribute belgim_login.
11 12 13 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 11 def belgim_login @belgim_login end |
#belgim_password ⇒ Object
Returns the value of attribute belgim_password.
11 12 13 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 11 def belgim_password @belgim_password end |
#belgim_url ⇒ Object
Returns the value of attribute belgim_url.
11 12 13 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 11 def belgim_url @belgim_url end |
#forti_connector ⇒ Object
Returns the value of attribute forti_connector.
11 12 13 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 11 def forti_connector @forti_connector end |
#staros_connector ⇒ Object
Returns the value of attribute staros_connector.
11 12 13 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 11 def staros_connector @staros_connector end |
#telegram_messanger ⇒ Object
Returns the value of attribute telegram_messanger.
11 12 13 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 11 def telegram_messanger @telegram_messanger end |
#ukaz60_add_func ⇒ Object
Returns the value of attribute ukaz60_add_func.
11 12 13 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 11 def ukaz60_add_func @ukaz60_add_func end |
Instance Method Details
#forti_process(get_belgim_data) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 49 def forti_process(get_belgim_data) forti_answer = {} begin format_for_forti = forti_connector.prepare_url_config_fortigate(get_belgim_data) if format_for_forti[:code] == 200 url_uploading = forti_connector.upload_url(format_for_forti[:body][:to_fortigate]) if url_uploading[:code] == 200 #update_fortigate_ansible = forti_connector.update_weburl_fortigate update_fortigate_ansible = forti_connector.update_weburl_fortimanager if update_fortigate_ansible[:code] == 200 forti_answer = {:code => 200, :result => "Fortigate processed", :data => update_fortigate_ansible[:body][:body], :num_uploaded_to_forti => format_for_forti[:body][:num_list]} else forti_answer = {:code => update_fortigate_ansible[:code], :result => update_fortigate_ansible[:result]} end forti_connector.clean_tmp_folders else forti_answer = {:code => 401, :result => "Failed for uploading data to ansible server"} end else forti_answer = {:code => 400, :result => "Error while processing data"} end rescue forti_answer = {:code => 507, :result => "Unknown error with Forti"} end forti_answer end |
#no_pasaran ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 107 def no_pasaran answer_output = {} forti_answer = {} staros_answer = {} begin get_belgim_data = belgim_connector.belgim_ukaz60_get #p get_belgim_data if get_belgim_data[:code] == 200 thr_forti = Thread.new do forti_answer = self.forti_process(get_belgim_data) end thr_staros = Thread.new do staros_answer = staros_process(get_belgim_data) end thr_staros.join thr_forti.join answer_output = {:code => 200, :result => "No pasaran", :fortigate => forti_answer, :staros => staros_answer, :info_belgim => get_belgim_data[:number]} else answer_output = {:code => 404, :result => "Failed to receive data from Belgim"} end rescue answer_output = {:code => 507, :result => "no_pasaran: Unknown SDK error"} end telegram_messanger.(JSON.pretty_generate(answer_output)) answer_output end |
#staros_process(get_belgim_data) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/imperituroard/projects/ukaz60.rb', line 76 def staros_process(get_belgim_data) output_starprocess = {} begin #get data from staros staros_blocks_current = staros_connector.get_all_staros_ukaz60 if staros_blocks_current[:code] == 200 #compare data with belgim answ = ukaz60_add_func.staros_compare_http(staros_blocks_current, get_belgim_data) p answ if answ[:code] == 200 #output_starprocess = {:code => 200, :result => "Staros processed", :data => {:block_me => answ[:body][:for_block][:notblocked_stat], :unblock_me =>answ[:body][:for_unblock][:for_unblock_stat]}} output_starprocess = ukaz60_add_func.format_star_processed_answ(answ)[:body][:to_message] else output_starprocess = answ end else output_starprocess = staros_blocks_current end rescue output_starprocess = {:code => 507, :result => "staros_process: Something wrong"} end output_starprocess end |