mjru.lisp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. (in-package :stumpwm)
  2. ;;;
  3. ;;; Variables
  4. ;;;
  5. (defvar mjru-webs
  6. ;; without web19
  7. (mapcar (lambda (x)
  8. (sb-unicode:lowercase (string x)))
  9. '(web15 web16 web17 web18
  10. web20 web21 web22 web23 web25 web26 web27 web28 web29
  11. web30 web31 web32 web33 web34 web35 web36 web37)))
  12. (defvar mjru-dh
  13. (mapcar (lambda (x)
  14. (sb-unicode:lowercase (string x)))
  15. '(dh1-mr dh2-mr dh3-mr dh4-mr)))
  16. (defvar mjru-vpn
  17. (mapcar (lambda (x)
  18. (concat "vpn-" (sb-unicode:lowercase (string x)) ".majordomo.ru"))
  19. '(miran dh office)))
  20. ;;;
  21. ;;; HMS
  22. ;;;
  23. (defvar *mjru-hms-current-stack* "")
  24. (defcommand mjru-hms-current-stack () ()
  25. (run-shell-command
  26. (format nil
  27. "~a | jq --join-output .active"
  28. (join
  29. (list "curl"
  30. "--user" (format nil "jenkins:~a"
  31. (password-store-show "majordomo/private/jenkins/jenkins"))
  32. "--request" "GET" "http://nginx1.intr:8080/hms")))
  33. t))
  34. (defcommand mjru-hms-current-stack-update () ()
  35. (setq *mjru-hms-current-stack* (mjru-hms-current-stack)))
  36. (defcommand mjru-mongo-production () ()
  37. (term-shell-command (concat "mongo mongodb://admin:"
  38. (password-store-show "majordomo/public/mongo/ci.intr/admin")
  39. "@hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/admin?replicaSet=hms-rs0")
  40. :scrollbar t
  41. :title "mongo-prod"))
  42. (defun mjru-mongo-development-command ()
  43. (concat "mongo mongodb://admin:"
  44. (password-store-show "majordomo/public/mongo/ci.intr/admin")
  45. "@ci.intr:27017/admin"))
  46. (defcommand mjru-mongo-development () ()
  47. (term-shell-command (mjru-mongo-development-command)
  48. :scrollbar t :title "mongo-dev"))
  49. (defcommand mjru-mongo-development-id-object () ()
  50. (let ((clipboard (get-x-selection)))
  51. (sb-thread:make-thread
  52. (lambda ()
  53. (message
  54. (run-shell-command (join (list (mjru-mongo-development-command)
  55. (format nil "--eval ~s"
  56. (format nil "load('~a/.mongorc.js'); search('~a')"
  57. (getenv "HOME") clipboard))))
  58. t))))))
  59. ;;;
  60. ;;; Monitoring
  61. ;;;
  62. (defcommand mjru-alerta-top () ()
  63. (term-shell-command (join (list "sh" "-c" (format nil "~s" "while true; do alerta top; sleep 5; done")))
  64. :title "alerta-top"
  65. :terminal 'st
  66. :font "Monospace:size=14"))
  67. (defcommand mjru-vnc-grafana () ()
  68. (run-shell-command "vncviewer 172.16.100.182:5900"))
  69. (defcommand mjru-alerta () ()
  70. (browse-url-firefox* "https://alerta.intr"
  71. :title "Alerta"))
  72. (defcommand mjru-grafana () ()
  73. (browse-url-firefox* "https://grafana.intr/"
  74. :title "Grafana"))
  75. (defcommand mjru-grafana-netflow () ()
  76. (browse-url-firefox* "https://grafana.intr/d/000000042/netflow?orgId=1&refresh=1m"
  77. :title "Netflow"))
  78. (defcommand mjru-grafana-upstream-interfaces () ()
  79. (browse-url-firefox* "https://grafana.intr/d/6QgXJjmik/upstream-interfaces-traffic?orgId=1"
  80. :title "Upstream interfaces"))
  81. (defcommand mjru-check-website () ()
  82. (browse-url-firefox* "https://www.uptrends.com/tools/uptime"))
  83. (defcommand mjru-zabbix () ()
  84. (browse-url-firefox* "https://zabbix.intr/dashboard.php?fullscreen=1"
  85. :title "Dashboard"))
  86. (defcommand mjru-kibana () ()
  87. (browse-url-firefox* "https://kibana.intr/"
  88. :title "Kibana"))
  89. (defcommand mjru-kibana-alerta () ()
  90. (run-shell-command "chromium --app=https://kibana.intr/goto/d63fb3a2e0b36deacc8f73f53cc14b4d"))
  91. (defcommand mjru-nexus () ()
  92. (browse-url-firefox* "http://nexus.intr"
  93. :title "Nexus"))
  94. (defcommand mjru-slack () ()
  95. (browse-url-firefox* "https://mjru.slack.com/"
  96. :title "Slack"))
  97. (defcommand mjru-cerb () ()
  98. (browse-url-firefox* "http://cerberus.intr/"
  99. :title "Cerberus"))
  100. (defcommand mjru-gitlab () ()
  101. (browse-url-firefox* "https://gitlab.intr/"
  102. :title "GitLab"))
  103. (defcommand mjru-jenkins () ()
  104. (browse-url-firefox* "https://jenkins.intr/"
  105. :title "Jenkins"))
  106. ;;;
  107. ;;; VNC
  108. ;;;
  109. (defcommand mjru-vnc () ()
  110. "Connect to Majordomo VNC"
  111. (run-shell-command "mjru-vnc"))
  112. (define-key *root-map* (kbd "V") "mjru-vnc")
  113. ;;;
  114. ;;; Switches
  115. ;;;
  116. (defun cisco-connect-command (host)
  117. (join (list "env" (format nil "TELNET_PASSWORD=~s" (password-store-show "majordomo/private/general"))
  118. "cisco-interact" host)))
  119. (defun cisco-connect (host)
  120. (term-shell-command (cisco-connect-command host)
  121. :title (format nil "telnet-~a" host)
  122. :scrollbar t))
  123. (defmacro define-mj-cisco (command)
  124. `(progn
  125. (defcommand ,command () ()
  126. (cisco-connect ,(sb-unicode:lowercase (string command))))))
  127. (define-mj-cisco sw1-mr11.intr)
  128. (define-mj-cisco sw1-mr12.intr)
  129. (define-mj-cisco sw2-mr12.intr)
  130. (define-mj-cisco sw1-mr14.intr)
  131. (define-mj-cisco sw1-mr116.intr)
  132. (define-mj-cisco sw1-mr143.intr)
  133. (define-mj-cisco sw1-dh507.intr)
  134. ;;;
  135. ;;; Hardware
  136. ;;;
  137. (defcommand mjru-ipmi (host) ((:string "Hostname: "))
  138. (run-shell-command (join (list (concat (getenv "HOME")
  139. "/.nix-profile/bin/ipmi")
  140. host))))
  141. (defcommand mjru-ipmiview () ()
  142. (run-shell-command (concat (getenv "HOME")
  143. "/.nix-profile.d/ipmiview/ipmiview/bin/IPMIView")))
  144. (defcommand mjru-ipkvm () ()
  145. (run-shell-command
  146. (join (list "firefox-esr-52" "-P" "esr52" "--new-instance"))))
  147. ;;;
  148. ;;; WEB
  149. ;;;
  150. (defcommand mjru-run-firefox () ()
  151. (gselect "1")
  152. (firefox)
  153. (renumber 2)
  154. (sleep 5)
  155. (sb-thread:make-thread
  156. (lambda ()
  157. (sleep 5)
  158. (gselect "3")
  159. (browse-url-firefox "https://grafana.intr/d/ogvzsY3mb/web-performance-panelized" t t)
  160. (browse-url-firefox "https://mjru.slack.com/" t t)
  161. (sleep 10)
  162. (gselect "5")
  163. (browse-url-firefox "https://jenkins.wugi.info/view/Failed/" t t)
  164. (sleep 5)
  165. (gselect "7")
  166. (browse-url-firefox "https://billing2.intr/servers?sort_by=name&sort_order=1&equip_server_type_id=3" t)
  167. (sleep 5)
  168. (gselect "8")
  169. (browse-url-firefox "https://alerta.intr" t)
  170. (browse-url-firefox "https://kibana.intr/goto/d63fb3a2e0b36deacc8f73f53cc14b4d" t t)
  171. (sleep 10)
  172. (gselect "1"))
  173. :name "mjru-run-firefox"))
  174. ;;;
  175. ;;; Tickets
  176. ;;;
  177. (defcommand mjru-cerb () ()
  178. (run-shell-command
  179. (join (list (concat "CERBERUS_KEY="
  180. (password-store-show "majordomo/private/cerberus.intr/api/notification/key"))
  181. (concat "CERBERUS_SECRET="
  182. (password-store-show "majordomo/private/cerberus.intr/api/notification/secret"))
  183. "cerb"))))
  184. ;;;
  185. ;;; SSH
  186. ;;;
  187. (defcommand mjru-xpanes-vpn-ssh () ()
  188. (term-shell-command (join `("xpanes -t -C 1 -c 'ssh {}'" ,@mjru-vpn))
  189. :title "xpanes-vpn-ssh"
  190. :font '("-fa" "Monospace" "-fs" "6")))
  191. (defcommand mjru-xpanes-dh-ssh () ()
  192. (term-shell-command (join `("xpanes -t -c 'ssh {}.intr'" ,@mjru-dh))
  193. :title "xpanes-dh-ssh"
  194. :font '("-fa" "Monospace" "-fs" "6")))
  195. (defcommand mjru-xpanes-web-ssh () ()
  196. (term-shell-command (join `("xpanes -t -c 'ssh {}.intr'" ,@mjru-webs))
  197. :title "xpanes-web-ssh"
  198. :font '("-fa" "Monospace" "-fs" "6")))
  199. (defcommand mjru-xpanes-web-top () ()
  200. (term-shell-command (join `("xpanes -c 'ssh -t {}.intr top'" ,@mjru-webs))
  201. :title "xpanes-web-top"
  202. :font '("-fa" "Monospace" "-fs" "6")))
  203. (defcommand mjru-xpanes-ssh-nginx () ()
  204. (term-shell-command (join `(,(xpanes-command "ssh -t {}")
  205. ,@'("nginx1-mr.intr" "nginx2-mr.intr")))
  206. :title "xpanes-routers"))
  207. (defcommand mjru-xpanes-ssh-ns () ()
  208. (term-shell-command (join `(,(xpanes-command "ssh -t {}")
  209. ,@'("ns1-mr.intr" "ns2-mr.intr" "ns1-dh.intr" "ns2-dh.intr")))
  210. :title "xpanes-routers"))
  211. (defcommand mjru-xpanes-routers () ()
  212. (term-shell-command (join `(,(xpanes-command "ssh -t {}")
  213. ,@'("router4.intr" "vpn-miran.majordomo.ru" "vpn-dh.majordomo.ru")))
  214. :title "xpanes-routers"))
  215. ;;;
  216. ;;; CI
  217. ;;;
  218. (defvar *mjru-jenkins-url*
  219. "https://jenkins.intr")
  220. (defcommand mjru-jenkins-webservices () ()
  221. (browse-url-firefox (format nil "~a/job/webservices" *mjru-jenkins-url*) t))
  222. (define-key *top-map* (kbd "M-s-W") "mjru-jenkins-webservices")
  223. (defcommand mjru-jenkins-group (group) ((:string "Group: "))
  224. (browse-url-firefox (format nil "~a/job/~a" *mjru-jenkins-url* group) t))
  225. ;;;
  226. ;;; Emacs
  227. ;;;
  228. (defcommand mjru-servers () ()
  229. (progn (run-shell-command "emacsclient --eval '(wi-installed-servers)'")
  230. (switch-to-emacs)))
  231. ;;;
  232. ;;; MySQL
  233. ;;;
  234. (defcommand mjru-xpanes-web-mycli () ()
  235. (term-shell-command (join `(,(xpanes-command
  236. (format nil "mycli --password ~a -d {}"
  237. (password-store-show "majordomo/private/web/mysql/root")))
  238. ,@mjru-webs))
  239. :title "xpanes-web-mycli"
  240. :font '("-fa" "Monospace" "-fs" "6")))
  241. ;;;
  242. ;;; Autotype
  243. ;;;
  244. (defcommand mjru-pass-eng () ()
  245. (if (y-or-n-p "Insert eng password and press Enter? ")
  246. (window-send-string
  247. (format nil "~a~%" (password-store-show "majordomo/private/ssh/eng")))))
  248. (defcommand mjru-pass-sup () ()
  249. (if (y-or-n-p "Insert sup password and press Enter? ")
  250. (window-send-string
  251. (format nil "~a~%" (password-store-show "majordomo/private/ssh/sup")))))
  252. (defcommand mjru-pass-route () ()
  253. (if (y-or-n-p "Insert router password and press Enter? ")
  254. (window-send-string
  255. (format nil "~a~%" (password-store-show "majordomo/private/ssh/router")))))
  256. (defcommand mjru-pass-ipmi () ()
  257. (if (y-or-n-p "Insert IPMI ADMIN password and press Enter? ")
  258. (window-send-string
  259. (format nil "~a" (password-store-show "majordomo/private/ipmi/ADMIN")))))
  260. (defcommand mjru-pass-gitlab-ssh () ()
  261. (if (y-or-n-p "Insert GitLab SSH password and press Enter? ")
  262. (window-send-string
  263. (format nil "~a" (password-store-show "majordomo/private/gitlab.intr/ssh/id_rsa_gitlab_intr")))))
  264. (defcommand mjru-pass-vnc () ()
  265. (if (y-or-n-p "Insert VNC SSH password and press Enter? ")
  266. (window-send-string
  267. (format nil "~a" (password-store-show "majordomo/public/kvm/vnc")))))
  268. ;;;
  269. ;;; Docker
  270. ;;;
  271. (defcommand mjru-docker-pull () ()
  272. (window-send-string (format nil "~a~%" "docker ps --format '{{ .Image }}' | grep master | sort -u | xargs -I{} docker pull {}")))
  273. (defcommand docker-firefox-esr-52 () ()
  274. (mapcar (lambda (command)
  275. (run-shell-command command))
  276. (list "xhost +local:"
  277. (join (list "docker" "run"
  278. "--network=host" "--rm"
  279. "--volume" "/etc/localtime:/etc/localtime:ro"
  280. "--volume" "/tmp/.X11-unix:/tmp/.X11-unix"
  281. "--user" "1000:997"
  282. "--env" "DISPLAY=$DISPLAY"
  283. "docker-registry.intr/utils/nix-docker-firefox-esr:master")))))
  284. ;;;
  285. ;;; Office
  286. ;;;
  287. (defun mjru-office-shedule-open (url)
  288. (run-shell-command (format nil "firefox --new-window ~a" url))
  289. ;; TODO: Wait for window appear
  290. (sb-thread:make-thread
  291. (lambda ()
  292. (sleep 3) ;Wait for password insert on "Office.majordomo - Mozilla Firefox".
  293. (when (string= (window-title (current-window)) (format nil "Страница пользователя — ~a" *browser-name*))
  294. (run-commands "delete")
  295. (run-shell-command (format nil "firefox --new-window ~a" url))))))
  296. (defcommand mjru-office-shedule-eng () ()
  297. (mjru-office-shedule-open "https://office.majordomo.ru/shedule2/10"))
  298. (defcommand mjru-office-shedule-sup () ()
  299. (mjru-office-shedule-open "https://office.majordomo.ru/shedule2/2"))
  300. ;;;
  301. ;;; Console
  302. ;;;
  303. (defcommand mjru-connect-br1-mr14.intr () ()
  304. (sb-thread:make-thread
  305. (lambda ()
  306. (sb-ext:run-program "/home/oleg/.guix-profile/bin/emacs"
  307. `("--name=emacs@br1-mr14.intr" "--eval" "(mjru-connect-br1-mr14.intr)")
  308. :input nil
  309. :output *standard-output*))))
  310. ;;;
  311. ;;; Rofi
  312. ;;;
  313. (defcommand rofi-billing2-server () ()
  314. "Open Rofi billing2 server."
  315. (let ((rofi-script (concat (getenv "HOME") "/.local/bin/rofi-billing2-server")))
  316. (run-rofi* (list "-modi" (concat "billing2:" rofi-script)
  317. "-show" "billing2"))))
  318. ;;;
  319. ;;; VPN
  320. ;;;
  321. (defvar *mjru-tapvpn-ip* "")
  322. (defcommand mjru-ip-address-vpn-update () ()
  323. (setq *mjru-tapvpn-ip* (network-address "tapvpn")))