Class: StaticImperituroard

Inherits:
Object
  • Object
show all
Defined in:
lib/imperituroard/projects/static.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(telegram_api_url, telegram_chat_id, telegram_log) ⇒ StaticImperituroard

Returns a new instance of StaticImperituroard.



13
14
15
16
17
18
19
# File 'lib/imperituroard/projects/static.rb', line 13

def initialize(telegram_api_url,
               telegram_chat_id,
               telegram_log)
  @telegram = Telegram_2.new(telegram_api_url, telegram_chat_id, telegram_log)
  @cps_ipam_connector = PHPipamcps.new

end

Instance Attribute Details

#cps_ipam_connectorObject

Returns the value of attribute cps_ipam_connector.



11
12
13
# File 'lib/imperituroard/projects/static.rb', line 11

def cps_ipam_connector
  @cps_ipam_connector
end

#telegramObject

Returns the value of attribute telegram.



11
12
13
# File 'lib/imperituroard/projects/static.rb', line 11

def telegram
  @telegram
end

Instance Method Details

#mts_2_delete_addressObject

mts_2_delete_address



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/imperituroard/projects/static.rb', line 395

def mts_2_delete_address

  #formirovanie request ID
  o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
  request_id = (0...50).map {o[rand(o.length)]}.join
  mess = "HAproxy input Request ID: #{request_id}, RemoteIP: #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}, requested mts_2_delete_address procedure with such parameter as msisdn: #{params[:msisdn]}"

  logger.info mess
  telegram.telegram_message2(mess)

  begin

    p '1'
    #opredelenie adresa po msisdn
    dfd = DatabaseMethods2.new
    ipaddr = dfd.phpipam_get_address(params[:msisdn])

    #udalenie addresa iz bazi phpipam
    php = PHPipam.new
    respo = php.deleteip(ipaddr)

    p '2'
    #udalenie podseti iz bazi phpipam
    begin
      php.deletesubnet(params[:msisdn])
    rescue
      p 'f'
    end

    code = ''
    resp1 = ''
    if respo == '200'
      code = '200'
      resp1 = 'Request completed successfully'
    else
      if respo == '404'
        resp1 = 'Address not found'
        code = '404'
      else
        code = '500'
        resp1 = 'Error'
      end
    end

    #udalenie atributa iz CPS
    cpsxxx = PHPipamcps.new
    cpsxxx.del_attribute(params[:msisdn])

    #clear session
    begin
      cpsxxx11345 = PHPipamcps.new
      cpsxxx11345.stop_session(params[:msisdn])
    rescue
      p 'f'
    end

    #formirovanie otveta
    output = {:answercode => code, :message => resp1}
    mess = "HAproxy output Request ID: #{request_id}, RemoteIP:  #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}, requested mts_2_delete_address procedure with such parameter as msisdn: #{params[:msisdn]}  and recieved #{output} response"
    logger.info mess
    telegram.telegram_message2(mess)
    render :soap => output

  rescue
    mess = "HAproxy output error Request ID: #{request_id}, RemoteIP:  #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}, requested mts_2_delete_address procedure with such parameter as msisdn: #{params[:msisdn]}  and recieved ERROR. Something wrong. response"
    logger.info mess
    telegram.telegram_message2(mess)
    raise SOAPError, 'ERROR. Something wrong.'
  end

end

#mts_3_technical_reconnectObject

mts_3_technical_reconnect



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/imperituroard/projects/static.rb', line 468

def mts_3_technical_reconnect

  o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
  request_id = (0...50).map {o[rand(o.length)]}.join


  output={}


  begin


    dfd = DatabaseMethods2.new
    ipaddr = dfd.phpipam_get_address(params[:msisdn])

    if ipaddr == '1'
      raise SOAPError, 'ERROR. Address not found in phpipam.'
    end

    cpsxxx = PHPipamcps.new
    cpsxxx.del_attribute(params[:msisdn])
    begin

      sended_ipaddress = ipaddr
      prefix=""
      gateway=""
      subnet=""
      editdate=""
      hostname=""
      region=""
      broadcast=""
      netmask=""
      wildcardmask=""
      minhostip=""
      maxhostip=""
      numberofhosts=""
      sectionid=""
      description=""
      note=""
      substype = ""
      ipcount = ""
      ipversion = ""

      code =""
      resp1 =""

      php = PHPipam.new
      respo = php.getaddressinfo2(sended_ipaddress)
      p respo
      if respo[:code] == '404'
        resp1 = 'Address not found'
        code = '404'
      elsif respo[:code] == '500'
        code = '500'
        resp1 = 'Error'
      else
        #attributes from procedure getaddressinfo2 to procedure for adding avp to cps
        gateway = respo[:gateway]
        subnet = respo[:submask]
        substype = respo[:substype],
            ipcount = respo[:ipcount],
            ipversion = respo[:ipversion]

        resp1 = 'Request completed successfully'
        code = '200'
      end

      cpsxxx1 = PHPipamcps.new

      resppp = ""

      p params[:msisdn]
      p ipaddr
      p subnet
      p gateway
      p substype

      begin
        if substype[0].to_i == 0
          resppp = cpsxxx1.add_attribute(params[:msisdn], ipaddr, subnet, gateway)
        elsif substype[0].to_i == 1
          resppp = cpsxxx1.add_attribute1(params[:msisdn], ipaddr, subnet, gateway)
        elsif substype[0].to_i == 2
          resppp = cpsxxx1.add_attribute2(params[:msisdn], ipaddr, subnet, gateway)
        elsif substype[0].to_i == 3
          resppp = cpsxxx1.add_attribute3(params[:msisdn], ipaddr, subnet, gateway)
        end
      rescue
        thr21 = Thread.new do
          begin
            telegram('ERROR. Something wrong with CPS.')
          rescue
            p 'f'
          end
        end

        raise SOAPError, 'ERROR. Something wrong with CPS.'
      end

      p ipcount

      p params[:msisdn]
      if ipcount.to_i>1
        p 'qwerty'
        dfd2 = DatabaseMethods2.new
        prrr = dfd2.phpipam_get_address_pre(params[:msisdn])
        resppp = cpsxxx1.add_attribute_prefix(params[:msisdn], prrr)
      end


      code = ''
      resp1 = ''
      if resppp == '0'
        code = '200'
        resp1 = 'Request completed successfully'
      else
        if resppp == '404'
          resp1 = 'Address not found'
          code = '404'
        else
          code = '500'
          resp1 = 'Error'
        end
      end
      output = {:answercode => code, :message => resp1}

        # if resppp=="0"
        #   logger.info "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}  requested mts_1_add_new_address procedure and output: #{output}"
        #
        #   #render :soap => output
        # else
        #
        #   logger.info "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}  requested mts_1_add_new_address procedure and output cant insert address to CPS."
        #
        #   raise SOAPError, "ERROR. cant insert address to CPS."
        # end

    rescue
      raise SOAPError, 'ERROR. Something wrong.'
    end

    #cpsxxx = PHPipamcps.new
    #resppp = cpsxxx.reconnect(params[:msisdn])


    output = {:answercode => '200', :message => 'Request completed successfully'}

    #output = {:answercode => "200", :message => "Request completed successfully"}

    mess = "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_3_technical_reconnect procedure with such parameter as: MSISDN: #{params[:msisdn]}, and recieved #{output} response"
    logger.info mess
    thr29 = Thread.new do
      begin
        telegram(mess)
      rescue
        p 'f'
      end
    end
    render :soap => output
  rescue
    puts 'SOAP mts_3_technical_reconnect errorMethod'
    mess = 'ERROR. Something wrong gen.'
    logger.info mess
    telegram.telegram_message2(mess)

    raise SOAPError, 'ERROR. Something wrong gen.'
  end


end

#mts_4_change_attrObject

mts_4_change_attr



640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'lib/imperituroard/projects/static.rb', line 640

def mts_4_change_attr


  type = params[:type]
  msisdn = params[:msisdn]
  region = params[:region]
  iptype = 'ip'
  description = params[:description]
  prefixlength = '32'
  note = params[:note]
  begin
    php = PHPipam.new
    substype = 'ip'
    ipcount = '1'
    ipversion = 'IPv4'
    respo = php.insertip(type, iptype, region, prefixlength, description, note, msisdn, substype, ipcount, ipversion)
    parse = respo.split('---')
    addr = parse[0]
    mask = parse[1]
    gateway = parse[2]

    if addr!='unknown' && mask!='unknown' && gateway!='unknown'
      output = {:answercode => '200', :message => 'Request completed successfully', :stataddress => addr, :network => mask, :gateway => gateway}
    else
      output = {:answercode => '407', :message => 'No available address', :stataddress => '', :network => '', :gateway => ""}
    end
    logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}  requested mts_4_change_attr procedure with such parameter as: type of service: #{params[:type]}, MSISDN: #{params[:msisdn]}, region: #{params[:region]}, description: #{params[:description]}, note: #{params[:note]} and recieved #{output} response"
    render :soap => output
  rescue
    puts 'SOAP mts_4_change_attr errorMethod'
    raise SOAPError, 'ERROR. Something wrong.'
  end

end

#mts_5_save_avpObject

mts_5_save_avp



676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/imperituroard/projects/static.rb', line 676

def mts_5_save_avp

  o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
  request_id = (0...50).map {o[rand(o.length)]}.join


  begin
    cpsxx11 = PHPipamcps.new
    cpsxx11.getavp_backup_tomongo(params[:msisdn])

    mess12 = "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_5_save_avp procedure with such parameter as: MSISDN: #{params[:msisdn]}, and processed success"
    logger.info mess12
    telegram.telegram_message2(mess12)

    output = {:answercode => "200", :message => "Request completed successfully"}
    render :soap => output

  rescue
    mess12 = "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_5_save_avp procedure with such parameter as: MSISDN: #{params[:msisdn]}, and recieved ERROR. Failed to backup avp from CPS response"
    logger.info mess12
    telegram.telegram_message2(mess12)
    raise SOAPError, 'ERROR. Failed to backup avp from CPS'
  end

end

#mts_7_technical_reconnectObject

mts_7_technical_reconnect



703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
# File 'lib/imperituroard/projects/static.rb', line 703

def mts_7_technical_reconnect

  o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
  request_id = (0...50).map {o[rand(o.length)]}.join


  begin
    p 'dfs'
    tee = PHPipamcps.new
    t = Phpipam.new

    p '0'
    li = t.form_attr_list(params[:msisdn])
    p li

    p '1'
    ans = ''
    mess =''
    if li != 'notfound'
      ans = tee.return_backup_tomongo(params[:msisdn], li)
      mess = 'Request completed successfully'
    else
      ans ='404'
      mess = 'Not found backup'
    end

  rescue
    mess12 = "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_7_technical_reconnect procedure with such parameter as: MSISDN: #{params[:msisdn]}, and recieved ERROR. something wrong"
    logger.info mess12
    telegram.telegram_message2(mess12)

    raise SOAPError, 'ERROR. mts_7_technical_reconnect something wrong'
  end


  output= {:answercode => ans, :message => mess}

  mess12 = "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_7_technical_reconnect procedure with such parameter as: MSISDN: #{params[:msisdn]}, and recieved SUCCESS #{output.to_s}"
  logger.info mess12
  telegram.telegram_message2(mess12)
  render :soap => output
end

#mts_add_new_addrObject

mts_1_add_new_address



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
75
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
106
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/imperituroard/projects/static.rb', line 24

def mts_add_new_addr

  begin

    prefix = 'not implemented'

    #request id generation for logging
    o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
    request_id = (0...50).map {o[rand(o.length)]}.join

    #logging before processing
    mess1 = "input Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure with such parameter as: type of service: #{params[:type]}, MSISDN: #{params[:msisdn]}, region: #{params[:region]}, description: #{params[:description]}, note: #{params[:note]}, ipcount: #{params[:ipcount].to_s}, ipversion: #{params[:ipversion].to_s} "
    logger.info mess1
    telegram.telegram_message2(mess1)

    #checking if msisdn exist in database
    begin
      dfd = DatabaseMethods2.new
      che = dfd.phpipam_get_address(params[:msisdn])

      mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and processed from database: #{che}"
      logger.info mess


          telegram.telegram_message2(mess)

    rescue

      mess = "Request ID: error. cant get address from database, Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and processed from database: #{che}"
      logger.info mess

      telegram.telegram_message2(mess)

    end

    # if che=1 - address not exist in database
    if che=='1'

      #type of subscriber
      #type - tip abonenta (0 - obychnyj abonent fizicheskoe lico, 1 - government, 2 - ord, 3 - government ord filter)
      type = params[:type]

      #subscribers msisdn
      msisdn = params[:msisdn]

      #region Minsk, Brest, Gomel etc.
      region = params[:region]

      #old parameter. not need now
      iptype = "ip"

      #description - lyuboj tekst. predlagaetsya zdes ukazyvat adres abonenta
      description = params[:description]

      #note - vtoroj deskripshn. tozhe lyuboj tekst pri neobxodimosti
      note = params[:note]

      prefixmask = AdditionalImperituroard::stat_parse_ip_num(params[:ipcount])

      #adding ip address to phpipam
      #first iteration. If one ip address


      #ip address inserting to phpipam procedure
      begin
        php = PHPipam.new
        respo = php.insertip("FTTx", iptype, region, prefixmask, description, note, msisdn, params[:type], params[:ipcount].to_s, params[:ipversion].to_s)
        #parse = respo.split("---")
        p respo
        addr = respo[:address]
        mask = respo[:netmask]
        gateway = respo[:gateway]

        if addr!="unknown" && mask!="unknown" && gateway!="unknown"
          output = {:answercode => "200", :message => "Request completed successfully", :stataddress => addr, :network => mask, :gateway => gateway, :prefix => prefix}
        else
          mess = "Output error. Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output errorMethod, No available addresses."
          logger.info mess

          telegram.telegram_message2(mess)

          raise SOAPError, "ERROR. No available addresses."
        end
        mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and recieved #{output.to_s} response"
        logger.info mess

        telegram.telegram_message2(mess)

      rescue
        mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output errorMethod, Cant get ip address from phpipam. "
        logger.info mess

        telegram.telegram_message2(mess)
        raise SOAPError, "ERROR. Request ID: '#{request_id}' Cant get ip address from phpipam."
      end


      p prefixmask
      begin
        if prefixmask<32
          p "stata"
          php1 = PHPipam.new
          rere = php1.ins_prefix_ip("prefix", region, msisdn, prefixmask, note, description, php1.gettoken)

          prefix = rere[:prefix]
          output[:prefix] = prefix

          cpsxxx = PHPipamcps.new
          resppp = cpsxxx.add_attribute_prefix(msisdn, rere[:prefix])
          if resppp=="0"
            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output: #{output.to_s}"
            logger.info mess

            telegram.telegram_message2(mess)
          else

            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output cant insert address to CPS."
            logger.info mess

            telegram.telegram_message2(mess)
            raise SOAPError, "ERROR. cant insert address to CPS."
          end

        elsif prefixmask==32

        else
          raise SOAPError, "ERROR. Unknown parameter."
        end

      rescue
        mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output errorMethod, Cant insert prefix framed route into CPS. "
        logger.info mess

        telegram.telegram_message2(mess)

        raise SOAPError, "ERROR. Request ID: '#{request_id}' Cant insert prefix into CPS."
      end

      #inserting address to cps
      begin
        if params[:type]=="0"
          cpsxxx = PHPipamcps.new
          p resppp = cpsxxx.add_attribute(msisdn, addr, mask, gateway)
          if resppp=="0"
            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output: #{output.to_s}"
            logger.info mess
            telegram.telegram_message2(mess)

            begin
              cps_ipam_connector.stop_session(params[:msisdn])
            rescue
              p "f"
            end

            render :soap => output
          else

            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output cant insert address to CPS."
            logger.info mess

            telegram.telegram_message2(mess)

            raise SOAPError, "ERROR. cant insert address to CPS."
          end

        elsif params[:type]=="1"
          cpsxxx = PHPipamcps.new
          resppp = cpsxxx.add_attribute1(msisdn, addr, mask, gateway)
          p resppp
          if resppp.to_s=="0"
            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output: #{output.to_s}"
            logger.info mess
            p "p1"

            telegram.telegram_message2(mess)

            p "p2"

            begin
              cps_ipam_connector.stop_session(params[:msisdn])
            rescue
              p "f"
            end

            render :soap => output
          else

            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output cant insert address to CPS."
            logger.info mess

            telegram.telegram_message2(mess)
            p "Errrrr"
            raise SOAPError, "ERROR. cant insert address to CPS."
          end

        elsif params[:type]=="2"
          cpsxxx = PHPipamcps.new
          p resppp = cpsxxx.add_attribute2(msisdn, addr, mask, gateway)
          if resppp=="0"

            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output: #{output.to_s}"
            logger.info mess

            telegram.telegram_message2(mess)

            begin
              cps_ipam_connector.stop_session(params[:msisdn])
            rescue
              p "f"
            end


            render :soap => output
          else

            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output cant insert address to CPS."
            logger.info mess

            telegram.telegram_message2(mess)
            p "Errrrr1"
            raise SOAPError, "ERROR. cant insert address to CPS."
          end

        elsif params[:type]=="3"
          cpsxxx = PHPipamcps.new
          p resppp = cpsxxx.add_attribute3(msisdn, addr, mask, gateway)
          if resppp=="0"
            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output: #{output.to_s}"
            logger.info mess

            telegram.telegram_message2(mess)

            begin
              cps_ipam_connector.stop_session(params[:msisdn])
            rescue
              p "f"
            end

            render :soap => output
          else

            mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output cant insert address to CPS."
            logger.info mess

            telegram.telegram_message2(mess)

            p "Errrrr2"
            raise SOAPError, "ERROR. cant insert address to CPS."
          end
        else
          mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output ERROR. Unknown parameter."
          logger.info mess

          telegram.telegram_message2(mess)
          raise SOAPError, "ERROR. Unknown parameter."
        end


      rescue
        mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output cant insert address to CPS. Unknown error"

        logger.info mess

        telegram.telegram_message2(mess)

        p "Errrrr5"
        raise SOAPError, "ERROR. cant insert address to CPS. Unknown error"
      end


    else

      #objavlenie peremennix
      sended_ipaddress = che
      prefix = ''
      gateway = ''
      subnet = ''
      editdate = ''
      hostname = ''
      region = ''
      broadcast = ''
      netmask = ''
      wildcardmask = ''
      minhostip = ''
      maxhostip = ''
      numberofhosts = ''
      sectionid = ''
      description = ''
      note = ''
      code = ''
      resp1 = ''

      #get ip address from phpipam database
      begin
        php = PHPipam.new
        p respo = php.getaddressinfo(sended_ipaddress)
        if respo == '404'
          resp1 = 'Address not found'
          code = '404'
        elsif respo == '500'
          code = '500'
          resp1 = 'Error'
        else
          para = respo.split("---")
          prefix = para[0]
          gateway = para[1]
          subnet = para[2]
          editdate = para[3]
          hostname = para[4]
          region = para[5]
          broadcast = para[6]
          netmask = para[7]
          wildcardmask = para[8]
          minhostip = para[9]
          maxhostip = para[10]
          numberofhosts = para[11]
          sectionid = para[12]
          description = para[13]
          note = para[14]
          resp1 = 'Request completed successfully'
          code = '200'
        end
        output = {:answercode => '200', :message => 'Address already exists', :stataddress => sended_ipaddress, :network => netmask, :gateway => gateway}

        begin
          dfd = DatabaseMethods2.new
          che = dfd.phpipam_get_address_pre(params[:msisdn])
          if che=='1'
            output[:prefix]= 'not implemented'
          else
            output[:prefix]=che
          end
        rescue

          telegram.telegram_message2('ERROR. With getting prefix from database')




          raise SOAPError, 'ERROR. With getting prefix from database'
        end

        mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output: #{output.to_s}"
        logger.info mess

        telegram.telegram_message2(mess)

        begin
          cps_ipam_connector.stop_session(params[:msisdn])
        rescue
          p 'f'
        end

        render :soap => output
      rescue
        mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output ERROR Unknown error. can't get ip address from phpipam API"
        logger.info mess
        telegram.telegram_message2(mess)
        raise SOAPError, "ERROR. Unknown error. can't get ip address from phpipam API"
      end
    end
  rescue
    mess = "Request ID: '#{request_id}' HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Forwarded-For']}  requested mts_1_add_new_address procedure and output FATALITY ERROR"
    logger.info mess
    telegram.telegram_message2(mess)
    raise SOAPError, 'ERROR. FATAL FATAL FATAL'
  end
end