executable_mjru-infa 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env bash
  2. set -e
  3. set -o pipefail
  4. MYSQL_USER="${MYSQL_USER:-root}"
  5. MYSQL_PASSWORD="${MYSQL_PASSWORD:-$(pass show majordomo/public/maxscale.intr/root)}"
  6. MYSQL_SERVER="${MYSQL_SERVER:-maxscale.intr}"
  7. help_main()
  8. {
  9. echo "\
  10. Usage: mjru-infa COMMANDS ARGS...
  11. Run COMMANDS with ARGS
  12. COMMAND must be one of the sub-commands listed below:
  13. server
  14. switch
  15. user
  16. site
  17. Report bugs to: go.wigust@gmail.com."
  18. }
  19. case "$1" in
  20. --help)
  21. help_main
  22. ;;
  23. server)
  24. mysql -s -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_SERVER" billing <<EOF \
  25. | awk '{$NF = "https://billing2.intr/servers/edit/"$NF; print}' \
  26. | expand -t1 | column -t
  27. SELECT equip_datacenters.name AS dc, equip_racks.name AS rack, equip_servers.name AS name, equip_servers.dcid AS dcid, equip_servers.datacenter_number AS dcnum, equip_servers.equip_server_id AS bil
  28. FROM equip_servers, equip_racks, equip_datacenters
  29. WHERE equip_servers.equip_rack_id = equip_racks.equip_rack_id AND equip_racks.equip_datacenter_id = equip_datacenters.equip_datacenter_id
  30. ORDER BY equip_racks.name;
  31. EOF
  32. ;;
  33. client)
  34. mysql -s -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_SERVER" billing <<EOF
  35. SELECT equip_servers.name,clients.email
  36. FROM colo_accounts, equip_servers, clients
  37. WHERE colo_accounts.equip_server_id = equip_servers.equip_server_id AND clients.client_id = colo_accounts.client_id AND equip_servers.name LIKE "mj%";
  38. EOF
  39. ;;
  40. disks)
  41. mysql -s -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_SERVER" billing <<EOF
  42. SELECT equip_components.install_date,equip_components.capacity,equip_servers.name,equip_components.description
  43. FROM equip_components,equip_servers
  44. WHERE equip_servers.equip_server_id=equip_components.equip_server_id
  45. AND (equip_components.type='hdd' or equip_components.type='raid')
  46. AND (equip_servers.equip_server_type_id='5' or equip_servers.equip_server_type_id='3' OR equip_servers.equip_server_type_id='2')
  47. ORDER BY equip_components.install_date;
  48. EOF
  49. ;;
  50. switch)
  51. mysql -s -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_SERVER" billing <<EOF \
  52. | awk '{$NF = "https://billing2.intr/switch/edit/"$NF; print}' \
  53. | expand -t1 | column -t
  54. SELECT equip_datacenters.name AS dc, equip_racks.name AS rack, equip_switches.snmp_ip, equip_switches.vendor, equip_switches.model AS name, equip_switches.speed, equip_switches.equip_switch_id FROM equip_switches, equip_racks, equip_datacenters WHERE equip_switches.equip_rack_id = equip_racks.equip_rack_id AND equip_racks.equip_datacenter_id = equip_datacenters.equip_datacenter_id ORDER BY equip_racks.name;
  55. EOF
  56. ;;
  57. user)
  58. mysql -s -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_SERVER" billing <<EOF \
  59. | awk '{$NF = "https://billing2.intr/servers/edit/"$NF; print}' \
  60. | expand -t1 | column -t
  61. SELECT equip_datacenters.name AS dc, equip_racks.name AS rack, equip_servers.name AS name, equip_servers.dcid AS dcid, equip_servers.datacenter_number AS dcnum, equip_servers.equip_server_id AS bil
  62. FROM equip_servers, equip_racks, equip_datacenters
  63. WHERE equip_servers.equip_rack_id = equip_racks.equip_rack_id AND equip_racks.equip_datacenter_id = equip_datacenters.equip_datacenter_id AND equip_servers.name LIKE 'mj%'
  64. ORDER BY equip_racks.name;
  65. EOF
  66. ;;
  67. site)
  68. curl --silent https://www.majordomo.ru/sitemap.xml | xq --raw-output '.urlset.url[] | .loc' | sort --unique
  69. ;;
  70. ip-addresses)
  71. while read line
  72. do
  73. echo $line
  74. done < <(
  75. mysql -N -s -q -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_SERVER" billing <<EOF
  76. SELECT address,mask FROM equip_ip_networks WHERE public=1 AND address!='78.108.81.0' AND address!='78.108.84.0';
  77. EOF
  78. )
  79. ;;
  80. ip-assigned)
  81. mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_SERVER" billing <<EOF
  82. SELECT vds_accounts_ipaddresses.vds_account_id,equip_ip_addresses.address
  83. FROM vds_accounts, vds_accounts_ipaddresses, equip_ip_addresses
  84. WHERE vds_accounts_ipaddresses.equip_ip_address_id=equip_ip_addresses.equip_ip_address_id
  85. GROUP BY vds_accounts_ipaddresses.equip_ip_address_id
  86. LIMIT 350;
  87. EOF
  88. ;;
  89. ip)
  90. mysql -s -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_SERVER" billing <<EOF | jq -s | jq 'reduce .[] as $d (null; .[$d.name] += [$d.address])'
  91. SELECT CONCAT('{ "name": "', equip_servers.name, '", "address": "',equip_ip_addresses.address, '" }')
  92. FROM equip_servers, equip_servers_ipaddresses, equip_ip_addresses
  93. WHERE equip_servers.equip_server_id=equip_servers_ipaddresses.equip_server_id
  94. AND equip_servers_ipaddresses.equip_ip_address_id=equip_ip_addresses.equip_ip_address_id;
  95. EOF
  96. ;;
  97. vm)
  98. mysql -s -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_SERVER" billing <<EOF | sort --numeric-sort
  99. SELECT vds_accounts.vds_account_id AS host, equip_ip_addresses.address AS ip
  100. FROM equip_ip_addresses, vds_accounts
  101. WHERE vds_accounts.client_id = ${2:-17959} AND equip_ip_addresses.equip_ip_address_id = vds_accounts.equip_ip_address_id;
  102. EOF
  103. ;;
  104. *)
  105. help_main
  106. ;;
  107. esac