User Tools

Site Tools


язык_программирования_python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
язык_программирования_python [2025/05/27 10:46]
val [Черновик]
язык_программирования_python [2025/05/27 11:53] (current)
val
Line 177: Line 177:
 (venv1) server:~# ./​zab_set_map_name.py 2 "ISP 1" (venv1) server:~# ./​zab_set_map_name.py 2 "ISP 1"
 </​code>​ </​code>​
-===== Дополнительные материалы ===== 
  
-  * [[https://​pypi.org/​project/​ansible-output-parser/​]] +===== Zabbix LLD приложение =====
-  * [[https://​www.cyberciti.biz/​faq/​python-run-external-command-and-get-output/​]] +
- +
-==== Доступ к каталогу по http ==== +
- +
-  * [[https://​gist.github.com/​SeanPesce/​af5f6b7665305b4c45941634ff725b7a|SeanPesce/​https_server.py]] +
- +
-<​code>​ +
-dir$ python3 -m http.server 80 +
-</​code>​ +
- +
-==== Черновик ====+
  
   * [[https://​www.geeksforgeeks.org/​python-find-dictionary-matching-value-in-list/​]]   * [[https://​www.geeksforgeeks.org/​python-find-dictionary-matching-value-in-list/​]]
   * [[https://​docs-python.ru/​tutorial/​vstroennye-funktsii-interpretatora-python/​funktsija-next/​]]   * [[https://​docs-python.ru/​tutorial/​vstroennye-funktsii-interpretatora-python/​funktsija-next/​]]
 <​code>​ <​code>​
-gate.corp24.un:​~# apt install python3-xmltodict/​stable +gate# apt install python3-xmltodict/​stable
- +
  
 +gate# cat /​etc/​zabbix/​dhcp-pools.py
 +</​code><​code>​
 #​!/​usr/​bin/​env python3 #​!/​usr/​bin/​env python3
  
 +# Example usage:
 +# ./​dhcp-pools.py
 +# ./​dhcp-pools.py LAN1 defined|used
 +
 +from sys import argv
 import subprocess, xmltodict, json import subprocess, xmltodict, json
  
Line 206: Line 199:
 (output, err) = p.communicate() (output, err) = p.communicate()
 p_status = p.wait() p_status = p.wait()
-#​print(output.decode()) 
  
 o = xmltodict.parse(output) o = xmltodict.parse(output)
  
-#​lan=o['​dhcpstatus'​]['​shared-network'​][0]['​location'​] +if len(argv)==1: 
-#print(lan+  r=[] 
-r=[] +  for i in o['​dhcpstatus'​]['​shared-network'​]:​ 
-for i in o['​dhcpstatus'​]['​shared-network'​]:​ +    s={} 
-  s={} +    s["​{#​POOLNAME}"​]=i['​location'​] 
-  s["​{#​POOLNAME}"​]=i['​location'​] +    r.insert(1,​s) 
-  r.insert(1,​s) +  print(json.dumps(r)) 
- ​print(i['​location'​]) +else: 
- ​print(s)+  LANNAME=argv[1] 
 +  USDEF=argv[2] 
 +  res = next((sub for sub in o['​dhcpstatus'​]['​shared-network'​] if sub['​location'​] ​== LANNAME), None
 +  print(res[USDEF]) 
 +</​code>​
  
-#print(r) +===== Дополнительные материалы ===== 
-print(json.dumps(r))+ 
 +  * [[https://​pypi.org/​project/​ansible-output-parser/​]] 
 +  * [[https://​www.cyberciti.biz/​faq/​python-run-external-command-and-get-output/​]] 
 + 
 +==== Доступ к каталогу по http ==== 
 + 
 +  * [[https://​gist.github.com/​SeanPesce/​af5f6b7665305b4c45941634ff725b7a|SeanPesce/​https_server.py]] 
 + 
 +<​code>​ 
 +dir$ python3 -m http.server 80
 </​code>​ </​code>​
 +
 +==== Черновик ====
 +
язык_программирования_python.txt · Last modified: 2025/05/27 11:53 by val