0

私は自分の場所にデータセンターのようなセットアップをしました。したがって、基本的には、フィルターパラメーターを使用してデータセンター名を含めるlogstash confファイルを作成しています

for eg:-

10.21.53.x :- APP1 {10.21.53. belongs to APP1 datacenter and so on}
10.92.252.x :- APP2
10.23.252.x :- APP3

I am trying to write an erb template where 
>>if the ip address matches "10.21.53.x" the variable should be set as APP1
>>if the ip address matches "10.92.252.x" the variable should be set as APP2
>>if the ip address matches "10.23.252.x" the variable should be set as APP3
4

1 に答える 1

0

私は分割を使用するという概念を使用しましたが、うまくいったようです。

>>> a
'192.168.23.23'
>>> a
'192.168.23.23'
>>> a.split()
['192.168.23.23']
>>> a.split(".")
['192', '168', '23', '23']
>>> a.split(".")[0]
'192'
>>> a.split(".")[1]
'168'
>>> if a.split(".")[1] == 168:
...  print "hey"
...
>>> if a.split(".")[1] == '168':
...  print "hey"
...
hey

join を再度使用して、ip の 3 つのオクテットすべてを比較しました

>>> ".".join(a.split(".")[:3])
'192.168.23'

このコードを使用してchef-shellに書き込み、それに応じてテストしました

node["ネットワーク"]["インターフェース"]["eth1"]["アドレス"].select { |アドレス、データ| data["家族"] == "inet" }.keys.join.split(".")[0,3].join(".")

于 2016-08-24T17:44:42.943 に答える