FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


os:linux:check:index.html



Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
os:linux:check:index.html [2018/02/03 10:53]
kurihara [check.py]
os:linux:check:index.html [2019/02/11 00:41] (current)
kurihara
Line 1: Line 1:
 [[:index.html#OS Management|Top#OS Management]] [[:index.html#OS Management|Top#OS Management]]
-====== Check OS Status (check.py) ======+====== Check Linux Status with Fabric (check.py) ======
  
 $FHHOME/fabfile/check.py $FHHOME/fabfile/check.py
Line 7: Line 7:
 \\ \\
  
-===== Operation =====+===== Operation with Fabric ===== 
 +==== Print list of possible commands  ====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -l |grep check+$ fab -l |grep -F check
 +    check.check_ssh_hostname                check_ssh_hostname:localuser,key,... 
 +    check.nmap                              fab  ope.nmap:22,x.x.x.x 
 +    check.ntpsync 
 +    check.ping_gw                           use  %s/scripts/check_ping_gw.sh 
 +    check.reboot_check                      use  %s/scripts/check_reboot.sh 
 +    check.reboot_diff 
 +    check.systemctl_service_enable_disable 
 +</sxh>
  
-$ fab -H $H auth.pro  check.xxxx+ 
 +==== Example ==== 
 + 
 +<sxh bash toolbar:false gutter:false> 
 +$ fab -H $H   check.xxxx
 </sxh> </sxh>
  
-==== Ref. Remote Shell Commands ====+\\ 
 +==== Fabric one-line Task Examples ====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- systemctl get-default +$ fab -H $H  -- systemctl get-default 
-$ FAB -H $H auth.pro -- systemctl set-default multi-user.target  # CUI+$ FAB -H $H  -- systemctl set-default multi-user.target  # CUI
 </sxh> </sxh>
  
Line 31: Line 45:
 from fabric.api import * from fabric.api import *
 from fabric.contrib import files from fabric.contrib import files
 +from datetime import datetime
  
 FHHOME=os.environ["FHHOME"] FHHOME=os.environ["FHHOME"]
Line 38: Line 53:
 # check.ntpsync # check.ntpsync
 #------------------------------------------------------------------ #------------------------------------------------------------------
-@task+@task 
 def ntpsync(): def ntpsync():
     sudo("which ntpq > /dev/null 2>&1 && ntpq -p")     sudo("which ntpq > /dev/null 2>&1 && ntpq -p")
Line 46: Line 61:
 #------------------------------------------------------------------ #------------------------------------------------------------------
 # check.nmap # check.nmap
-#     fab auth.pro check.nmap:22,x.x.x.x+#     fab  check.nmap:22,x.x.x.x
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
 def nmap(port, remote): def nmap(port, remote):
-    """fab auth.pro ope.nmap:22,x.x.x.x"""+    """ope.nmap:22,x.x.x.x"""
     run("nmap -Pn -sT -p %s %s " % (port, remote))     run("nmap -Pn -sT -p %s %s " % (port, remote))
  
 #------------------------------------------------------------------ #------------------------------------------------------------------
-check_ssh:localuser,key,remoteuser,remotehost+check_ssh_hostname:localuser,key,remoteuser,remotehost
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
-def check_ssh(localuser, key, remoteuser, remotehost): +def check_ssh_hostname(localuser, key, remoteuser, remotehost): 
-    """ check_ssh:localuser,key,remoteuser,remotehost"""+    """ check_ssh_hostname:localuser,key,remoteuser,remotehost"""
     sudo ('su - %s -c "ssh -i %s %s@%s hostname"' % (localuser, key, remoteuser, remotehost))     sudo ('su - %s -c "ssh -i %s %s@%s hostname"' % (localuser, key, remoteuser, remotehost))
  
Line 71: Line 86:
 @task @task
 def reboot_check(): def reboot_check():
 +    """ use  %s/scripts/check_reboot.sh """
     date = datetime.now().strftime('%Y%m%d_%H%M')     date = datetime.now().strftime('%Y%m%d_%H%M')
     outfile = "check_reboot.%s"  % (date)     outfile = "check_reboot.%s"  % (date)
 + 
     run("test -d scripts || mkdir scripts")     run("test -d scripts || mkdir scripts")
     put("%s/scripts/check_reboot.sh" % FHHOME, scripts/check_reboot.sh, mode=0755)     put("%s/scripts/check_reboot.sh" % FHHOME, scripts/check_reboot.sh, mode=0755)
Line 94: Line 110:
 @task @task
 def ping_gw(): def ping_gw():
 +    """ use  %s/scripts/check_ping_gw.sh """
     run("test -d scripts || mkdir scripts")     run("test -d scripts || mkdir scripts")
     put("%s/scripts/check_ping_gw.sh" % FHHOME, "scripts/check_ping_gw.sh", mode=0755)     put("%s/scripts/check_ping_gw.sh" % FHHOME, "scripts/check_ping_gw.sh", mode=0755)
Line 105: Line 122:
 #------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
 # CentOS7 # CentOS7
 +# check.systemctl_service_enable_disable
 #------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
 @task @task
-def check_systemctl_service():+def systemctl_service_enable_disable():
     sudo('systemctl list-unit-files -t service --no-pager |egrep "enable|disable" |sort -k 3')     sudo('systemctl list-unit-files -t service --no-pager |egrep "enable|disable" |sort -k 3')
 + 
  
 </sxh> </sxh>
Line 117: Line 135:
  
 |<100% 200px ->| |<100% 200px ->|
-| [[os:check:scripts:check_reboot.sh.html]]     | +| [[os:linux:check:scripts:check_reboot.sh.html]]     | 
-| [[os:check:scripts:check_ping_gw.sh.html]]  |   |+| [[os:linux:check:scripts:check_ping_gw.sh.html]]  |   |
  
  


os/linux/check/index.html.1517622821.txt.gz · Last modified: 2018/02/03 10:53 by kurihara