megaclisas-status: Handle Windows when checking permissions

This commit is contained in:
Adam Cecile 2016-09-19 10:01:36 +02:00
parent 1af2d222f9
commit a87f5a9d18
1 changed files with 8 additions and 4 deletions

View File

@ -9,6 +9,8 @@ import os
import re import re
import sys import sys
import pdb import pdb
if sys.platform == 'win32':
import ctypes
def_megaclipath = "/opt/MegaRAID/MegaCli/MegaCli64" def_megaclipath = "/opt/MegaRAID/MegaCli/MegaCli64"
@ -39,10 +41,12 @@ def print_usage():
# We need root access to query # We need root access to query
if __name__ == '__main__': if __name__ == '__main__':
myuid = os.geteuid() try:
if myuid != 0: root_or_admin = os.geteuid() == 0
print '# This script requires Administrator privs (Current EUID: '+str(myuid)+'! e.g :\r' except AttributeError:
print 'sudo '+str(sys.argv[0])+'\r' root_or_admin = ctypes.windll.shell32.IsUserAnAdmin() !=0
if not root_or_admin:
print '# This script requires Administrator privileges'
sys.exit(5) sys.exit(5)
# Check command line arguments to enable nagios or not # Check command line arguments to enable nagios or not