imperituroard 0.5.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/imperituroard.gemspec +3 -0
- data/lib/.DS_Store +0 -0
- data/lib/imperituroard.rb +97 -71
- data/lib/imperituroard/.DS_Store +0 -0
- data/lib/imperituroard/platforms/cps/cps_multiple_thread_req.rb +0 -0
- data/lib/imperituroard/platforms/staros/get_data_ssh.rb +54 -0
- data/lib/imperituroard/platforms/staros/staros_automation.rb +95 -0
- data/lib/imperituroard/platforms/staros/staros_automation_fun.rb +37 -0
- data/lib/imperituroard/platforms/staros/staros_parser.rb +141 -0
- data/lib/imperituroard/projects/dns.rb +1 -1
- data/lib/imperituroard/projects/iot.rb +191 -30
- data/lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb +22 -8
- data/lib/imperituroard/projects/iot/mongoconnector.rb +177 -2
- data/lib/imperituroard/projects/mhub.rb +2 -0
- data/lib/imperituroard/projects/mhub/infobip.rb +1 -1
- data/lib/imperituroard/projects/mhub/sk.rb +171 -157
- data/lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb +124 -12
- data/lib/imperituroard/projects/ukaz60.rb +140 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/belgim.rb +48 -9
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/dns.rb +0 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/dns_update.rb +0 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/fortigate.rb +43 -4
- data/lib/imperituroard/projects/ukaz60/staros.rb +141 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/ukaz60_add_func.rb +159 -4
- data/lib/imperituroard/version.rb +1 -1
- metadata +28 -8
- data/lib/imperituroard/projects/dns/ukaz60.rb +0 -87
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
|
3
|
+
class StarosAutomationFun
|
4
|
+
|
5
|
+
attr_accessor :ignore_y
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@ignore_y = 1 #1-yes, 0-no
|
9
|
+
end
|
10
|
+
|
11
|
+
def staros_massive_command(staros_hosts, staros_login, staros_password, command_array)
|
12
|
+
|
13
|
+
|
14
|
+
staros_thr_pool_222 = []
|
15
|
+
|
16
|
+
staros_hosts.each do |ggsn|
|
17
|
+
staros_thr_pool_222 << Thread.new do
|
18
|
+
|
19
|
+
Net::SSH.start(ggsn[1], staros_login, :password => staros_password) do |session|
|
20
|
+
|
21
|
+
gg = session.exec!("context AAA")
|
22
|
+
p gg
|
23
|
+
gg1 = session.exec!("show subscribers summary")
|
24
|
+
p gg1
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
staros_thr_pool_222.each(&:join)
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
class StarosParser_2
|
2
|
+
|
3
|
+
|
4
|
+
#parser for staros ECS configuration
|
5
|
+
def ecs_config_parser(config_string_array)
|
6
|
+
|
7
|
+
out_ans = {}
|
8
|
+
parsed_config = {"config" => {"active-charging service" => []}}
|
9
|
+
config_string_array.shift
|
10
|
+
|
11
|
+
# {"config" => {"active-charging service" => [{"ECS-SVC" => {"root" => [], "host-pool"=>{"1b1.nekurims.top"=>["ip 185.59.101.182/32"]}, "ruledef"=>{"VKONTAKTE_CDN_b"=>[]}}}}]}
|
12
|
+
|
13
|
+
flag_inter_ecs_name = 0
|
14
|
+
current_ecs_name = ""
|
15
|
+
current_section = "root"
|
16
|
+
current_section_name = ""
|
17
|
+
section_flag = 0
|
18
|
+
section_deep = 0
|
19
|
+
ecs_number = 0
|
20
|
+
for aaa in config_string_array
|
21
|
+
if section_deep == 0 && aaa[0..22] == "active-charging service" #&& flag_inter_ecs_name == 0
|
22
|
+
ecs_name_regexp = /active-charging service (\S+)/
|
23
|
+
current_ecs_name = aaa.match(ecs_name_regexp)[1]
|
24
|
+
#p current_ecs_name
|
25
|
+
parsed_config["config"]["active-charging service"].push({current_ecs_name => {"root" => [],
|
26
|
+
"host-pool" => {},
|
27
|
+
"port-map" => {},
|
28
|
+
"ruledef" => {},
|
29
|
+
"access-ruledef" => {},
|
30
|
+
"group-of-ruledefs" => {},
|
31
|
+
"packet-filter" => {},
|
32
|
+
"edr-format" => {},
|
33
|
+
"xheader-format" => {},
|
34
|
+
"charging-action" => {},
|
35
|
+
"rulebase" => {},
|
36
|
+
"fw-and-nat policy" => {}
|
37
|
+
}})
|
38
|
+
flag_inter_ecs_name = 1
|
39
|
+
section_deep = 1
|
40
|
+
current_section = "root"
|
41
|
+
else
|
42
|
+
if aaa == "exit" && section_deep == 2
|
43
|
+
section_flag = 0
|
44
|
+
section_deep = section_deep - 1
|
45
|
+
current_section = "root"
|
46
|
+
elsif aaa[0..9] == "host-pool " && section_flag == 0 && section_deep == 1
|
47
|
+
current_section = "host-pool"
|
48
|
+
ecs_hostpool_regexp = /host-pool\s+(.+)/
|
49
|
+
current_section_name = aaa.match(ecs_hostpool_regexp)[1]
|
50
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
51
|
+
section_flag = 1
|
52
|
+
section_deep = section_deep + 1
|
53
|
+
elsif aaa[0..8] == "port-map " && section_flag == 0 && section_deep == 1
|
54
|
+
current_section = "port-map"
|
55
|
+
ecs_portmap_regexp = /port-map\s+(.+)/
|
56
|
+
current_section_name = aaa.match(ecs_portmap_regexp)[1]
|
57
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
58
|
+
section_flag = 1
|
59
|
+
section_deep = section_deep + 1
|
60
|
+
elsif aaa[0..7] == "ruledef " && section_flag == 0 && section_deep == 1
|
61
|
+
current_section = "ruledef"
|
62
|
+
ecs_ruldef_regexp = /ruledef\s+(.+)/
|
63
|
+
current_section_name = aaa.match(ecs_ruldef_regexp)[1]
|
64
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
65
|
+
section_flag = 1
|
66
|
+
section_deep = section_deep + 1
|
67
|
+
elsif aaa[0..14] == "access-ruledef " && section_flag == 0 && section_deep == 1
|
68
|
+
current_section = "access-ruledef"
|
69
|
+
ecs_accruldef_regexp = /access-ruledef\s+(.+)/
|
70
|
+
current_section_name = aaa.match(ecs_accruldef_regexp)[1]
|
71
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
72
|
+
section_flag = 1
|
73
|
+
section_deep = section_deep + 1
|
74
|
+
elsif aaa[0..17] == "group-of-ruledefs " && section_flag == 0 && section_deep == 1
|
75
|
+
current_section = "group-of-ruledefs"
|
76
|
+
ecs_grruldef_regexp = /group-of-ruledefs\s+(.+)/
|
77
|
+
current_section_name = aaa.match(ecs_grruldef_regexp)[1]
|
78
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
79
|
+
section_flag = 1
|
80
|
+
section_deep = section_deep + 1
|
81
|
+
elsif aaa[0..13] == "packet-filter " && section_flag == 0 && section_deep == 1
|
82
|
+
current_section = "packet-filter"
|
83
|
+
ecs_packfil_regexp = /packet-filter\s+(.+)/
|
84
|
+
current_section_name = aaa.match(ecs_packfil_regexp)[1]
|
85
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
86
|
+
section_flag = 1
|
87
|
+
section_deep = section_deep + 1
|
88
|
+
elsif aaa[0..10] == "edr-format " && section_flag == 0 && section_deep == 1
|
89
|
+
current_section = "edr-format"
|
90
|
+
ecs_edrformat_regexp = /edr-format\s+(.+)/
|
91
|
+
current_section_name = aaa.match(ecs_edrformat_regexp)[1]
|
92
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
93
|
+
section_flag = 1
|
94
|
+
section_deep = section_deep + 1
|
95
|
+
elsif aaa[0..14] == "xheader-format " && section_flag == 0 && section_deep == 1
|
96
|
+
current_section = "xheader-format"
|
97
|
+
ecs_xheader_regexp = /xheader-format\s+(.+)/
|
98
|
+
current_section_name = aaa.match(ecs_xheader_regexp)[1]
|
99
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
100
|
+
section_flag = 1
|
101
|
+
section_deep = section_deep + 1
|
102
|
+
elsif aaa[0..15] == "charging-action " && section_flag == 0 && section_deep == 1
|
103
|
+
current_section = "charging-action"
|
104
|
+
ecs_xheader_regexp = /charging-action\s+(.+)/
|
105
|
+
current_section_name = aaa.match(ecs_xheader_regexp)[1]
|
106
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
107
|
+
section_flag = 1
|
108
|
+
section_deep = section_deep + 1
|
109
|
+
elsif aaa[0..8] == "rulebase " && section_flag == 0 && section_deep == 1
|
110
|
+
current_section = "rulebase"
|
111
|
+
ecs_xheader_regexp = /rulebase\s+(.+)/
|
112
|
+
current_section_name = aaa.match(ecs_xheader_regexp)[1]
|
113
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
114
|
+
section_flag = 1
|
115
|
+
section_deep = section_deep + 1
|
116
|
+
elsif aaa[0..17] == "fw-and-nat policy " && section_flag == 0 && section_deep == 1
|
117
|
+
current_section = "fw-and-nat policy"
|
118
|
+
ecs_xheader_regexp = /fw-and-nat policy\s+(.+)/
|
119
|
+
current_section_name = aaa.match(ecs_xheader_regexp)[1]
|
120
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
|
121
|
+
section_flag = 1
|
122
|
+
section_deep = section_deep + 1
|
123
|
+
elsif section_flag == 1 && current_section != "root" && current_section != "end" && section_deep == 2
|
124
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name].push(aaa)
|
125
|
+
elsif current_section == "root" && section_deep == 1 && aaa != "end"
|
126
|
+
parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name]["root"].push(aaa)
|
127
|
+
elsif aaa == "end"
|
128
|
+
section_flag = 0
|
129
|
+
section_deep = 0
|
130
|
+
current_section = "end"
|
131
|
+
p "end"
|
132
|
+
else
|
133
|
+
p aaa
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
parsed_config
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
|
@@ -17,34 +17,44 @@ class IotFunctions_2
|
|
17
17
|
|
18
18
|
attr_accessor :mongoip,
|
19
19
|
:mongoport,
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
#:iotip,
|
21
|
+
#:mongo_database,
|
22
|
+
#:iotplatform_ip,
|
23
|
+
#:iotplatform_port,
|
24
24
|
:cert_path,
|
25
25
|
:key_path,
|
26
26
|
:mongo_client,
|
27
27
|
:add_functions_connector,
|
28
|
-
|
29
|
-
|
28
|
+
#:real_ip, #real ip address of procedure caller
|
29
|
+
#:remote_ip, #ip address of balancer
|
30
30
|
:hua_aceanconnect_connector,
|
31
31
|
:internal_func
|
32
32
|
|
33
|
-
def initialize(mongoip,
|
34
|
-
|
33
|
+
def initialize(mongoip,
|
34
|
+
mongoport,
|
35
|
+
iotip,
|
36
|
+
mongo_database,
|
37
|
+
iotplatform_ip,
|
38
|
+
iotplatform_port,
|
39
|
+
cert_path,
|
40
|
+
key_path,
|
41
|
+
telegram_api_url,
|
42
|
+
telegram_chat_id
|
43
|
+
#real_ip, remote_ip
|
44
|
+
)
|
35
45
|
@mongoip = mongoip
|
36
46
|
@mongoport = mongoport
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
47
|
+
#@iotip = iotip
|
48
|
+
#@mongo_database = mongo_database
|
49
|
+
#@iotplatform_ip = iotplatform_ip
|
50
|
+
#@iotplatform_port = iotplatform_port
|
41
51
|
@cert_path = cert_path
|
42
52
|
@key_path = key_path
|
43
53
|
@mongo_client = MongoIot.new(mongoip, mongoport, mongo_database)
|
44
54
|
@add_functions_connector = AdditionalFunc.new(telegram_api_url, telegram_chat_id)
|
45
|
-
|
46
|
-
|
47
|
-
@hua_aceanconnect_connector = HuaIot.new(iotplatform_ip, iotplatform_port, cert_path, key_path)
|
55
|
+
#@real_ip = real_ip
|
56
|
+
#@remote_ip = remote_ip
|
57
|
+
@hua_aceanconnect_connector = HuaIot.new(iotplatform_ip, iotplatform_port, cert_path, key_path, mongoip, mongoport, mongo_database)
|
48
58
|
@internal_func = InternalFunc.new
|
49
59
|
end
|
50
60
|
|
@@ -57,7 +67,7 @@ class IotFunctions_2
|
|
57
67
|
#massive commands
|
58
68
|
#+++
|
59
69
|
#iot logic added
|
60
|
-
def add_device_to_prof_2(login, imei_list)
|
70
|
+
def add_device_to_prof_2(login, imei_list, real_ip, remote_ip)
|
61
71
|
input_json = {:login => login, :imei_list => imei_list}
|
62
72
|
resp_out = {}
|
63
73
|
begin
|
@@ -211,7 +221,7 @@ class IotFunctions_2
|
|
211
221
|
# imei
|
212
222
|
# imei_list =[41234,23452345,132412]
|
213
223
|
#++
|
214
|
-
def device_find_2(login, imei_list)
|
224
|
+
def device_find_2(login, imei_list, real_ip, remote_ip)
|
215
225
|
input_json = {:login => login, :imei_list => imei_list}
|
216
226
|
ime_list_approved = []
|
217
227
|
ime_list_notapproved = []
|
@@ -274,7 +284,7 @@ class IotFunctions_2
|
|
274
284
|
#massive commands
|
275
285
|
#im_list = [{"imei_old"=>7967843245667, "imei_new"=>7967843245665}]
|
276
286
|
#++
|
277
|
-
def imei_replace_2(login, im_list)
|
287
|
+
def imei_replace_2(login, im_list, real_ip, remote_ip)
|
278
288
|
input_json = {:login => login, :imei_list => im_list}
|
279
289
|
resp_out = {}
|
280
290
|
|
@@ -449,7 +459,7 @@ class IotFunctions_2
|
|
449
459
|
#login="test"
|
450
460
|
#+++
|
451
461
|
#IOT logic added
|
452
|
-
def device_remove_2(login, imei)
|
462
|
+
def device_remove_2(login, imei, real_ip, remote_ip)
|
453
463
|
|
454
464
|
input_json = {:login => login, :imei_list => imei}
|
455
465
|
resp_out = {}
|
@@ -533,7 +543,7 @@ class IotFunctions_2
|
|
533
543
|
#newdevice_list=[{:imei=>7967843245665, :address=>"Golubeva51"}]
|
534
544
|
#+++
|
535
545
|
#iot platform integration completed
|
536
|
-
def device_add_address_2(login, newdevice_list)
|
546
|
+
def device_add_address_2(login, newdevice_list, real_ip, remote_ip)
|
537
547
|
#add_functions_connector.telegram_message(newdevice_list.to_s)
|
538
548
|
p newdevice_list
|
539
549
|
p "gas"
|
@@ -615,7 +625,7 @@ class IotFunctions_2
|
|
615
625
|
#msisdn
|
616
626
|
#newdevice_list=[{:imei=>7967843245665, :attributes=>{:address=>"Golubeva51", :profile=>"wqeqcqeqwev", :msisdn=>375298766719, :imsi=>25702858586756875}}]
|
617
627
|
#+
|
618
|
-
def add_service_2(login, device_list)
|
628
|
+
def add_service_2(login, device_list, real_ip, remote_ip)
|
619
629
|
resp_out = {}
|
620
630
|
not_processed = []
|
621
631
|
processed = []
|
@@ -690,7 +700,7 @@ class IotFunctions_2
|
|
690
700
|
|
691
701
|
#7 procedure for subscriber autorization
|
692
702
|
# save data to mongodb
|
693
|
-
def autorize_subscriber_2(login, password)
|
703
|
+
def autorize_subscriber_2(login, password, real_ip, remote_ip)
|
694
704
|
input_json = {:login => login, :password => password}
|
695
705
|
resp_out = {}
|
696
706
|
thr7 = Thread.new do
|
@@ -722,7 +732,7 @@ class IotFunctions_2
|
|
722
732
|
|
723
733
|
|
724
734
|
#8 get available profiles by login
|
725
|
-
def get_available_prof_2(login)
|
735
|
+
def get_available_prof_2(login, real_ip, remote_ip)
|
726
736
|
|
727
737
|
input_params = {:login => login}
|
728
738
|
resp_out = {}
|
@@ -773,7 +783,7 @@ class IotFunctions_2
|
|
773
783
|
end
|
774
784
|
|
775
785
|
#9 get available device types by login
|
776
|
-
def get_available_types_2(login)
|
786
|
+
def get_available_types_2(login, real_ip, remote_ip)
|
777
787
|
|
778
788
|
input_params = {:login => login}
|
779
789
|
resp_out = {}
|
@@ -830,7 +840,7 @@ class IotFunctions_2
|
|
830
840
|
|
831
841
|
|
832
842
|
#10 get available device types by login and profile. procedure update
|
833
|
-
def get_available_types2_2(login, profile)
|
843
|
+
def get_available_types2_2(login, profile, real_ip, remote_ip)
|
834
844
|
|
835
845
|
input_params = {:login => login}
|
836
846
|
resp_out = {}
|
@@ -887,7 +897,7 @@ class IotFunctions_2
|
|
887
897
|
|
888
898
|
|
889
899
|
#11 get info for device type
|
890
|
-
def get_info_data_type_2(type)
|
900
|
+
def get_info_data_type_2(type, real_ip, remote_ip)
|
891
901
|
|
892
902
|
input_params = {:type => type}
|
893
903
|
output_answ = {}
|
@@ -917,7 +927,7 @@ class IotFunctions_2
|
|
917
927
|
|
918
928
|
|
919
929
|
#12 get info for profile
|
920
|
-
def get_info_data_profile_2(profile)
|
930
|
+
def get_info_data_profile_2(profile, real_ip, remote_ip)
|
921
931
|
|
922
932
|
input_params = {:profile => profile}
|
923
933
|
output_answ = {}
|
@@ -946,6 +956,157 @@ class IotFunctions_2
|
|
946
956
|
end
|
947
957
|
|
948
958
|
|
959
|
+
#set_data_replace
|
960
|
+
#13
|
961
|
+
# {"autorization"=>{"login"=>"test", "token"=>"token"}, "datalist"=>[{"imei"=>"524523654366", "new_profile"=>"3", "new_type"=>"1000001"}, {"imei"=>"53623413423", "new_profile"=>"1", "new_type"=>"1000003"}]}
|
962
|
+
# answer = {:code=>200, :result=>"Success", :body=>{:processednum=>1, :failednum=>1, :deviceserr=>[{:failedimei=>524523654366}]}}
|
963
|
+
def set_data_replace_2(soapgw_params, real_ip, remote_ip)
|
964
|
+
input_params = {:soapgw_params => soapgw_params, :real_ip => real_ip, :remote_ip => remote_ip}
|
965
|
+
output_answ = {}
|
966
|
+
failes_list = []
|
967
|
+
answ_to_soapgw = {}
|
968
|
+
not_processed_list = []
|
969
|
+
processed_list = []
|
970
|
+
|
971
|
+
inp_login = soapgw_params["autorization"]["login"]
|
972
|
+
inp_dev_list = soapgw_params["datalist"]
|
973
|
+
|
974
|
+
inp_dev_list.each do |curr_dev|
|
975
|
+
begin
|
976
|
+
if curr_dev["imei"] != [] && curr_dev["imei"] != nil && curr_dev["imei"] != ""
|
977
|
+
list_checked = mongo_client.check_imei_exists([curr_dev["imei"].to_i])
|
978
|
+
if list_checked[:code] == 200 && list_checked[:body][:exists] != [] && list_checked[:body][:not_exists] == []
|
979
|
+
|
980
|
+
#step1 checking permission for writing for imei list
|
981
|
+
prof_name1 = mongo_client.get_profile_name_from_imei(curr_dev["imei"].to_i)
|
982
|
+
if prof_name1[:code] == 200
|
983
|
+
prof_new_id = mongo_client.get_profile_universal(curr_dev["new_profile"])["profile_id"]
|
984
|
+
|
985
|
+
get_login_info = mongo_client.check_login_prof_perm_id_one(inp_login, prof_name1[:body]["profile_id"])
|
986
|
+
if get_login_info[:code] == 200
|
987
|
+
get_login_info_new = mongo_client.check_login_prof_perm_id_one(inp_login, prof_new_id)
|
988
|
+
if get_login_info_new[:code] == 200
|
989
|
+
|
990
|
+
cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
|
991
|
+
cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["device_type"], curr_dev["new_type"])
|
992
|
+
|
993
|
+
p cur_comp1
|
994
|
+
p cur_comp2
|
995
|
+
if cur_comp1[:is_the_same] && cur_comp2[:is_the_same]
|
996
|
+
#the same. Nothing to do
|
997
|
+
processed_list.append(curr_dev)
|
998
|
+
########
|
999
|
+
else
|
1000
|
+
|
1001
|
+
credentials_old = mongo_client.get_iot_oceanconn_credent_2(prof_name1[:body]["profile"])
|
1002
|
+
credentials_new = mongo_client.get_iot_oceanconn_credent_2(prof_new_id)
|
1003
|
+
#########
|
1004
|
+
if credentials_old[:code] == 200 && credentials_new[:code] == 200
|
1005
|
+
imei_data = mongo_client.get_imei_info_from_db([curr_dev["imei"].to_i])
|
1006
|
+
if imei_data[:body] != []
|
1007
|
+
ans = {}
|
1008
|
+
if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
|
1009
|
+
|
1010
|
+
model_data = mongo_client.get_device_type_info_universal(curr_dev["new_type"])
|
1011
|
+
|
1012
|
+
#####all checks completed. then process data#####
|
1013
|
+
ans_old = hua_aceanconnect_connector.remove_one_device_from_iot(credentials_old[:body][:app_id], credentials_old[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
|
1014
|
+
|
1015
|
+
if ans_old[:code].to_i == 200 || ans_old[:code].to_i == 202 || ans_old[:code].to_i == 204
|
1016
|
+
begin
|
1017
|
+
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials_new[:body][:app_id],
|
1018
|
+
credentials_new[:body][:secret],
|
1019
|
+
curr_dev["imei"].to_i,
|
1020
|
+
curr_dev["imei"].to_s,
|
1021
|
+
prof_name1[:body]["description"],
|
1022
|
+
model_data[:body]["device_type"],
|
1023
|
+
curr_dev["new_profile"],
|
1024
|
+
model_data[:body]["ManufacturerID"],
|
1025
|
+
model_data[:body]["ManufacturerNAME"],
|
1026
|
+
model_data[:body]["model"]
|
1027
|
+
)
|
1028
|
+
|
1029
|
+
if resss[:code]=="200"
|
1030
|
+
|
1031
|
+
if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
|
1032
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
|
1033
|
+
else
|
1034
|
+
new_id_iot = resss[:body]
|
1035
|
+
new_profile_id = prof_new_id
|
1036
|
+
now_date = DateTime.now
|
1037
|
+
#finished success. update database
|
1038
|
+
attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
|
1039
|
+
|
1040
|
+
answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
|
1041
|
+
|
1042
|
+
if answ_mongo[:code] != 200
|
1043
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
|
1044
|
+
else
|
1045
|
+
processed_list.append(curr_dev)
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
#added_on_iot_platf.append(s1)
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
else
|
1052
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
|
1053
|
+
end
|
1054
|
+
rescue
|
1055
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
|
1056
|
+
end
|
1057
|
+
end
|
1058
|
+
else
|
1059
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
|
1060
|
+
end
|
1061
|
+
else
|
1062
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get info from database"})
|
1063
|
+
end
|
1064
|
+
else
|
1065
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
|
1066
|
+
end
|
1067
|
+
end
|
1068
|
+
else
|
1069
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "New profile modification not permitted"})
|
1070
|
+
end
|
1071
|
+
else
|
1072
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Old profile modification not permitted"})
|
1073
|
+
end
|
1074
|
+
else
|
1075
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown current profile"})
|
1076
|
+
end
|
1077
|
+
else
|
1078
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Device not exists"})
|
1079
|
+
end
|
1080
|
+
else
|
1081
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "IMEI can't be nil"})
|
1082
|
+
end
|
1083
|
+
rescue
|
1084
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
|
1085
|
+
end
|
1086
|
+
|
1087
|
+
end
|
1088
|
+
|
1089
|
+
err_li = []
|
1090
|
+
if not_processed_list.length > 0
|
1091
|
+
not_processed_list.each do |err_l|
|
1092
|
+
err_li.append({:failedimei => err_l[:imei]})
|
1093
|
+
end
|
1094
|
+
end
|
1095
|
+
|
1096
|
+
if processed_list.length > 0
|
1097
|
+
soap_answ = {:code=>200, :result=>"Success", :body=>{:processednum => processed_list.length, :failednum => not_processed_list.length, :deviceserr => err_li}}
|
1098
|
+
else
|
1099
|
+
soap_answ = {:code=>202, :result=>"Nothing done", :body=>{:processednum => 0, :failednum => not_processed_list.length, :deviceserr => err_li}}
|
1100
|
+
end
|
1101
|
+
|
1102
|
+
output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => soap_answ, :not_processed_list => not_processed_list, :processed_list => processed_list}}
|
1103
|
+
mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
|
1104
|
+
output_answ
|
1105
|
+
|
1106
|
+
end
|
1107
|
+
|
1108
|
+
|
1109
|
+
#14
|
949
1110
|
#additional procedure for checking status on iot platform
|
950
1111
|
def get_info_by_imeilist_from_iot(login, imei_list)
|
951
1112
|
resp_out={}
|
@@ -998,10 +1159,10 @@ class IotFunctions_2
|
|
998
1159
|
p resp_out[:body]
|
999
1160
|
p "resp_out[:body][\"devices\"]"
|
1000
1161
|
|
1001
|
-
if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices"=>nil}
|
1162
|
+
if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices" => nil}
|
1002
1163
|
p "step1111"
|
1003
1164
|
p resp_out_1[:body]["devices"]
|
1004
|
-
resp_out[:body] = {
|
1165
|
+
resp_out[:body] = {'devices' => resp_out_1[:body]["devices"]}
|
1005
1166
|
p "step22222"
|
1006
1167
|
else
|
1007
1168
|
if resp_out_1[:body]["devices"] != nil
|
@@ -1037,7 +1198,7 @@ class IotFunctions_2
|
|
1037
1198
|
end
|
1038
1199
|
|
1039
1200
|
|
1040
|
-
def
|
1201
|
+
def test1278493
|
1041
1202
|
#ddd = MongoIot.new(mongoip, mongoport, mongo_database)
|
1042
1203
|
#ddd.get_profiles_by_login("test")
|
1043
1204
|
|