def run(): """Execute the plugin""" # Plugin arguments options = process_plugin_options() # Get the output of license manager command, catching errors try: if options.debug: output = backend.util.test_from_file("../tests/lstc_status.txt") else: output = backend.lstc.status("%s" % options.license) except backend.lstc.LstcStatusError as e: raise NagiosCritical("%s (code: %s, license: '%s') !" % (e.errmsg, e.retcode, e.license)) # Globals connected_users = [] for line in output: # Checking number of connected users connected_users_pattern = re.compile( r'^(?:\s+|)(\w+)\s+(\d+@[\w\d.]+)') connected_users_match = connected_users_pattern.search(line) if connected_users_match: connected_users.append((connected_users_match.group(1), connected_users_match.group(2))) # Checking for unknown errors if not connected_users: raise NagiosUnknown("Unexpected error ! Check with debug mode.") # Format Nagios output # -------------------- # nagios_output = "LSTC: There %s %d license%s used." nagios_longoutput = '' # Plural syntax if more than 1 user if len(connected_users) > 1: verb = 'are' plural = 's' else: verb = 'is' plural = '' # Output to Nagios nagios_output = nagios_output % (verb, len(connected_users), plural) if not options.nolongoutput: nagios_longoutput = '\n' for user in connected_users: nagios_longoutput += "User %s from host %s.\n" % (user[0], user[1]) raise NagiosOk(nagios_output + nagios_longoutput)
def run(): """Execute the plugin""" # Plugin arguments options = process_plugin_options() # Get the output of license manager command, catching errors try: if options.debug: output = backend.util.test_from_file("../tests/lstc_status.txt") else: output = backend.lstc.status("%s" % options.license) except backend.lstc.LstcStatusError as e: raise NagiosCritical("%s (code: %s, license: '%s') !" % (e.errmsg, e.retcode, e.license)) # Globals connected_users = [] for line in output: # Checking number of connected users connected_users_pattern = re.compile(r'^(?:\s+|)(\w+)\s+(\d+@[\w\d.]+)') connected_users_match = connected_users_pattern.search(line) if connected_users_match: connected_users.append((connected_users_match.group(1), connected_users_match.group(2))) # Checking for unknown errors if not connected_users: raise NagiosUnknown("Unexpected error ! Check with debug mode.") # Format Nagios output # -------------------- # nagios_output = "LSTC: There %s %d license%s used." nagios_longoutput = '' # Plural syntax if more than 1 user if len(connected_users) > 1: verb = 'are' plural = 's' else: verb = 'is' plural ='' # Output to Nagios nagios_output = nagios_output % (verb, len(connected_users), plural) if not options.nolongoutput: nagios_longoutput = '\n' for user in connected_users: nagios_longoutput += "User %s from host %s.\n" % (user[0], user[1]) raise NagiosOk(nagios_output + nagios_longoutput)
def run(): """Execute the plugin""" # Plugin arguments options = process_plugin_options() # Get the output of license manager command, catching errors try: if options.debug: output = backend.util.test_from_file("../tests/lum_status.txt") else: output = backend.lum.status("{0.license}".format(options)) except backend.lum.LumStatusError as e: raise NagiosCritical( "{0.errmsg} (code: {0.retcode}, license: '{0.license}') !".format( e)) # Find line showing state of license server servers_up = [] for line in output: server_state_line_pattern = re.compile(r"\s+ip:(.*)\s\(WIN32\)") server_state_line_match = server_state_line_pattern.search(line) if server_state_line_match: servers_up.append(server_state_line_match.group(1)) # Format output to Nagios nagios_longoutput = "" nagios_output = "" if len(servers_up) > 0: if not options.nolongoutput: for server in servers_up: nagios_longoutput += "\nServer up: {0}".format(server) if len(servers_up) > 1: nagios_output = "{0} servers are serving licenses.".format( len(servers_up)) else: nagios_output = "{0} server is serving license.".format( len(servers_up)) raise NagiosOk(nagios_output + nagios_longoutput) else: raise NagiosCritical("LUM status is not correct, please check !")
def run(): """Execute the plugin""" # Plugin arguments options = process_plugin_options() # Get the output of license manager command, catching errors try: if options.debug: output = backend.util.test_from_file("../tests/lum_status.txt") else: output = backend.lum.status("{0.license}".format(options)) except backend.lum.LumStatusError as e: raise NagiosCritical("{0.errmsg} (code: {0.retcode}, license: '{0.license}') !".format(e)) # Find line showing state of license server servers_up = [] for line in output: server_state_line_pattern = re.compile(r"\s+ip:(.*)\s\(WIN32\)") server_state_line_match = server_state_line_pattern.search(line) if server_state_line_match: servers_up.append(server_state_line_match.group(1)) # Format output to Nagios nagios_longoutput = "" nagios_output = "" if len(servers_up) > 0: if not options.nolongoutput: for server in servers_up: nagios_longoutput += "\nServer up: {0}".format(server) if len(servers_up) > 1: nagios_output = "{0} servers are serving licenses.".format(len(servers_up)) else: nagios_output = "{0} server is serving license.".format(len(servers_up)) raise NagiosOk(nagios_output + nagios_longoutput) else: raise NagiosCritical("LUM status is not correct, please check !")
def run(): """Execute the plugin""" # Plugin arguments # ---------------- # # Define custom arguments for this plugin using argparser argparser.add_option('-m', dest='mode', choices=('status', 'expire'), help='Mode for the plugins, either "status" (default) or "expire".') # Define common arguments to all plugins options = process_plugin_options() # Check mandatory arguments if not options.port: raise NagiosUnknown("Syntax error: missing port information !") if not options.mode: raise NagiosUnknown("Syntax error: missing mode information !") # Get the output of license manager command, catching errors try: output = backend.lmx.status_xml("%s" % options.license, options.port) except backend.lmx.LmxStatusError as e: raise NagiosCritical("%s (code: %s, license: '%s') !" % (e.errmsg, e.retcode, e.license)) # Process XML data xml_data = XML.parseString(output) all_features_tags = xml_data.getElementsByTagName('FEATURE') if not len(all_features_tags): raise NagiosCritical('Problem to query LM-X license manager on port %s from host %s !' % (options.port, options.license)) # Get all features and compute stats (used, free, total licenses...) features = backend.lmx.Features() for node_feature in all_features_tags: feature = node_feature.getAttribute('NAME') used_licenses = node_feature.getAttribute('USED_LICENSES') total_licenses = node_feature.getAttribute('TOTAL_LICENSES') expire_date = node_feature.getAttribute('END') feature = backend.lmx.Feature(feature, used_licenses, total_licenses, expire_date) features.append(feature) # Format Nagios output # -------------------- # # STATUS if options.mode == 'status': nagios_output = str(features) nagios_longoutput = '' nagios_perfdata = features.print_perfdata() # Must we show long output ? if not options.nolongoutput: nagios_longoutput = '\nFeatures details:\n\n' for feature in features: nagios_longoutput += '%s\n' % feature raise NagiosOk(nagios_output + nagios_longoutput + nagios_perfdata) # EXPIRATION elif options.mode == 'expire': days_remaining = features.calc_expired_license() if min(days_remaining.values()) > 15: raise NagiosOk('Features are up-to-date.') count = 0 nagios_output = '' nagios_longoutput = '\n' # Check first for expired licenses if 0 in days_remaining.values(): for feature in days_remaining: if not days_remaining[feature]: nagios_longoutput += '** %s is expired ! **\n' % feature count += 1 nagios_output = 'There are %d features expired !' % count # Do not show long output if specified if not options.nolongoutput: nagios_output += nagios_longoutput raise NagiosCritical(nagios_output) else: # Check for about to expire licenses for feature in days_remaining: if days_remaining[feature] > 0 and days_remaining[feature] <= 15: nagios_longoutput += '%s expires in %d day(s).\n' % (feature, days_remaining[feature]) count +=1 nagios_output = 'There are %d features about to expire !' % count # Do not show long output if specified if not options.nolongoutput: nagios_output += nagios_longoutput raise NagiosWarning(nagios_output)
def run(): """Execute the plugin""" # Plugin arguments options = process_plugin_options() # Get the output of lmutil / lmstat, catching errors try: if options.debug: output = backend.util.test_from_file("../tests/lmstat_expiration.txt") else: output = backend.flexlm.expiration("%s" % options.license, options.timeout) except backend.flexlm.FlexlmStatusError as e: raise NagiosCritical("%s (code: %s, license: '%s') !" % (e.errmsg, e.retcode, e.license)) # Some globals features_list = { 'uptodate': [], 'about_to_expire': [], 'expired': [], } # Store all features informations. nbfeature_expired = 0 # Counter for the number of expired. # feature. nbfeature_about_to_expire = 0 # Counter for the number of feature # about to expire. # Compile regexp used to check lmstat output regexp_feature_info = re.compile( r'^(?P<name>\w*).*(?P<expire_date>\d{2}-.{3}-\d{4})') # Retrieve features informations for line in output: # The feature dict contains the following keys: name, expire_date. # name: the feature name as string. # expire_date: the date string of the form "%d-%b-%Y" when this feature # will expire. feature = {} match_feature_info_line = regexp_feature_info.search(line) if match_feature_info_line: feature.update(match_feature_info_line.groupdict()) remaining_days = time_left(feature['expire_date']) if 0 < remaining_days < 15: nbfeature_about_to_expire += 1 features_list['about_to_expire'].append( (feature['name'], feature['expire_date'])) elif remaining_days <= 0: nbfeature_expired += 1 features_list['expired'].append(feature['name']) else: features_list['uptodate'].append((feature['name'], feature['expire_date'])) # Formating Nagios output # nagios_output = "" nagios_longoutput = "" # Checking if there is feature with problem, then output to Nagios if len(features_list['expired']) > 0: nagios_output = "There are %d licenses expired !\n" % len( features_list['expired']) if not options.nolongoutput: for feature in features_list['expired']: nagios_longoutput += "Feature '%s' is expired !\n" % feature raise NagiosCritical(nagios_output + nagios_longoutput) elif len(features_list['about_to_expire']) > 0: nagios_output = "There are %d licenses about to expire !\n" % len( features_list['about_to_expire']) if not options.nolongoutput: for feature in features_list['about_to_expire']: name, expire_date = feature nagios_longoutput += "Feature '%s' will expire on %s !\n" % ( name, expire_date) raise NagiosWarning(nagios_output + nagios_longoutput) else: nagios_output = "All features licenses are up to date.\n" if not options.nolongoutput: for feature in features_list['uptodate']: name, expire_date = feature nagios_longoutput += "Feature '%s' will expire on %s.\n" % ( name, expire_date) raise NagiosOk(nagios_output + nagios_longoutput)
def run(): """Execute the plugin""" # Plugin arguments options = process_plugin_options() # Get the output of lmutil / lmstat, catching errors try: if options.debug: output = backend.util.test_from_file("../tests/lmstat_status.txt") else: output = backend.flexlm.status("%s" % options.license, options.timeout, options.with_stat) except backend.flexlm.FlexlmStatusError as e: raise NagiosCritical("%s (code: %s, license: '%s') !" % (e.errmsg, e.retcode, e.license)) # Some globals all_feature_stats = [] # Store all features statistics feature_error = 0 # Counter for the number of feature in error total_license_available = 0 # The total license available (sum of total license issued for all features) total_license_used = 0 # The total license in use (sum of total license in use for all features) vendor_daemon = "" # Store the vendor daemon name # Compile regexp used to check output regexp_vendor_daemon = re.compile(r'\s*(.*): UP') regexp_feature_name = re.compile(r'^Users of (.*):') regexp_feature_stats = re.compile(r'^Users of .*: .* of (?P<total>\d+) .* issued; .* of (?P<in_use>\d+) .* in use') # Checking if Vendor daemon is UP for line in output: match = regexp_vendor_daemon.search(line) if match: vendor_daemon = match.group(1) if len(vendor_daemon) == 0: raise NagiosCritical("No vendor daemon is running !") if options.with_stat: # Retrieve features informations for line in output: feature = { 'name': '', 'in_use': '0', 'total': '0', 'status': '', } match_feature_line = regexp_feature_name.search(line) if match_feature_line: # Store feature name feature["name"] = match_feature_line.group(1) # Checking if this is possible to get stats from the feature match_feature_stats = regexp_feature_stats.search(line) if match_feature_stats: feature.update(match_feature_stats.groupdict()) feature["status"] = "OK" # Calculate some stats about license usage total_license_available += int(feature["total"]) total_license_used += int(feature["in_use"]) else: feature["status"] = "ERROR" feature_error+=1 all_feature_stats.append(feature) # Formating Nagios output # nagios_output = "" nagios_longoutput = "" nagios_perfdata = format_perfdata(all_feature_stats) # Output if errors are found in features if feature_error > 0: if not options.nolongoutput: for feature in all_feature_stats: if feature["status"] == "ERROR": nagios_longoutput += "Feature: %s\n" % feature["name"] nagios_output = "%s: %d feature(s) in error(s) !\n%s" % (vendor_daemon, feature_error, nagios_longoutput.rstrip('\n')) raise NagiosCritical(nagios_output + nagios_perfdata) # Output when everything is fine # if not options.nolongoutput: for feature in all_feature_stats: nagios_longoutput += "Feature '%s': %s / %s\n" % (feature["name"], feature["in_use"], feature["total"]) nagios_output = "%s: usage: %d / %d license(s) available.\n%s" % (vendor_daemon, total_license_used, total_license_available, nagios_longoutput.rstrip('\n')) raise NagiosOk(nagios_output + nagios_perfdata) else: raise NagiosOk("Vendor daemon %s is up !" % vendor_daemon)
def run(): """Execute the plugin""" # Plugin arguments options = process_plugin_options() # Get the output of lmutil / lmstat, catching errors try: if options.debug: output = backend.util.test_from_file( "../tests/lmstat_expiration.txt") else: output = backend.flexlm.expiration("%s" % options.license, options.timeout) except backend.flexlm.FlexlmStatusError as e: raise NagiosCritical("%s (code: %s, license: '%s') !" % (e.errmsg, e.retcode, e.license)) # Some globals features_list = { 'uptodate': [], 'about_to_expire': [], 'expired': [], } # Store all features informations. nbfeature_expired = 0 # Counter for the number of expired. # feature. nbfeature_about_to_expire = 0 # Counter for the number of feature # about to expire. # Compile regexp used to check lmstat output regexp_feature_info = re.compile( r'^(?P<name>\w*).*(?P<expire_date>\d{2}-.{3}-\d{4})') # Retrieve features informations for line in output: # The feature dict contains the following keys: name, expire_date. # name: the feature name as string. # expire_date: the date string of the form "%d-%b-%Y" when this feature # will expire. feature = {} match_feature_info_line = regexp_feature_info.search(line) if match_feature_info_line: feature.update(match_feature_info_line.groupdict()) remaining_days = time_left(feature['expire_date']) if 0 < remaining_days < 15: nbfeature_about_to_expire += 1 features_list['about_to_expire'].append( (feature['name'], feature['expire_date'])) elif remaining_days <= 0: nbfeature_expired += 1 features_list['expired'].append(feature['name']) else: features_list['uptodate'].append( (feature['name'], feature['expire_date'])) # Formating Nagios output # nagios_output = "" nagios_longoutput = "" # Checking if there is feature with problem, then output to Nagios if len(features_list['expired']) > 0: nagios_output = "There are %d licenses expired !\n" % len( features_list['expired']) if not options.nolongoutput: for feature in features_list['expired']: nagios_longoutput += "Feature '%s' is expired !\n" % feature raise NagiosCritical(nagios_output + nagios_longoutput) elif len(features_list['about_to_expire']) > 0: nagios_output = "There are %d licenses about to expire !\n" % len( features_list['about_to_expire']) if not options.nolongoutput: for feature in features_list['about_to_expire']: name, expire_date = feature nagios_longoutput += "Feature '%s' will expire on %s !\n" % ( name, expire_date) raise NagiosWarning(nagios_output + nagios_longoutput) else: nagios_output = "All features licenses are up to date.\n" if not options.nolongoutput: for feature in features_list['uptodate']: name, expire_date = feature nagios_longoutput += "Feature '%s' will expire on %s.\n" % ( name, expire_date) raise NagiosOk(nagios_output + nagios_longoutput)
def run(): """Execute the plugin""" # Plugin arguments options = process_plugin_options() # Get the output of lmutil / lmstat, catching errors try: if options.debug: output = backend.util.test_from_file("../tests/lmstat_status.txt") else: output = backend.flexlm.status("%s" % options.license, options.timeout, options.with_stat) except backend.flexlm.FlexlmStatusError as e: raise NagiosCritical("%s (code: %s, license: '%s') !" % (e.errmsg, e.retcode, e.license)) # Some globals all_feature_stats = [] # Store all features statistics feature_error = 0 # Counter for the number of feature in error total_license_available = 0 # The total license available (sum of total license issued for all features) total_license_used = 0 # The total license in use (sum of total license in use for all features) vendor_daemon = "" # Store the vendor daemon name # Compile regexp used to check output regexp_vendor_daemon = re.compile(r'\s*(.*): UP') regexp_feature_name = re.compile(r'^Users of (.*):') regexp_feature_stats = re.compile( r'^Users of .*: .* of (?P<total>\d+) .* issued; .* of (?P<in_use>\d+) .* in use' ) # Checking if Vendor daemon is UP for line in output: match = regexp_vendor_daemon.search(line) if match: vendor_daemon = match.group(1) if len(vendor_daemon) == 0: raise NagiosCritical("No vendor daemon is running !") if options.with_stat: # Retrieve features informations for line in output: feature = { 'name': '', 'in_use': '0', 'total': '0', 'status': '', } match_feature_line = regexp_feature_name.search(line) if match_feature_line: # Store feature name feature["name"] = match_feature_line.group(1) # Checking if this is possible to get stats from the feature match_feature_stats = regexp_feature_stats.search(line) if match_feature_stats: feature.update(match_feature_stats.groupdict()) feature["status"] = "OK" # Calculate some stats about license usage total_license_available += int(feature["total"]) total_license_used += int(feature["in_use"]) else: feature["status"] = "ERROR" feature_error += 1 all_feature_stats.append(feature) # Formating Nagios output # nagios_output = "" nagios_longoutput = "" nagios_perfdata = format_perfdata(all_feature_stats) # Output if errors are found in features if feature_error > 0: if not options.nolongoutput: for feature in all_feature_stats: if feature["status"] == "ERROR": nagios_longoutput += "Feature: %s\n" % feature["name"] nagios_output = "%s: %d feature(s) in error(s) !\n%s" % ( vendor_daemon, feature_error, nagios_longoutput.rstrip('\n')) raise NagiosCritical(nagios_output + nagios_perfdata) # Output when everything is fine # if not options.nolongoutput: for feature in all_feature_stats: nagios_longoutput += "Feature '%s': %s / %s\n" % ( feature["name"], feature["in_use"], feature["total"]) nagios_output = "%s: usage: %d / %d license(s) available.\n%s" % ( vendor_daemon, total_license_used, total_license_available, nagios_longoutput.rstrip('\n')) raise NagiosOk(nagios_output + nagios_perfdata) else: raise NagiosOk("Vendor daemon %s is up !" % vendor_daemon)