return alerts lock = LockFile(SMART_FILE) while not lock.i_am_locking(): try: lock.acquire(timeout=5) except LockTimeout: return alerts with open(SMART_FILE, 'rb') as f: try: data = pickle.loads(f.read()) except: data = {} msg = '' for msgs in data.itervalues(): if not msgs: continue msg += '<br />\n'.join(msgs) if msg: alerts.append(Alert(Alert.CRIT, msg)) lock.release() return alerts alertPlugins.register(SMARTAlert)
import os from django.utils.translation import ugettext as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class UpdateFailedAlert(BaseAlert): interval = 60 def run(self): alerts = [] if os.path.exists('/data/update.failed'): alerts.append( Alert( Alert.CRIT, _('Update failed. Check /data/update.failed for further ' 'details.'), )) return alerts alertPlugins.register(UpdateFailedAlert)
def run(self): alerts = [] for vol in Volume.objects.all(): if vol.is_upgraded is not True: alerts.append(Alert( Alert.WARN, _( 'New feature flags are available for volume %s. Refer ' 'to the "Upgrading a ZFS Pool" section of the User ' 'Guide for instructions.' ) % vol.vol_name, )) proc = subprocess.Popen( "zfs upgrade | grep FILESYSTEM", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf8', ) output = proc.communicate()[0].strip(' ').strip('\n') if output: alerts.append(Alert(Alert.WARN, _( 'ZFS filesystem version is out of date. Consider upgrading' ' using "zfs upgrade" command line.' ))) return alerts alertPlugins.register(VolumeVersionAlert)
import os from django.utils.translation import ugettext as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class NFSBindAlert(BaseAlert): def run(self): if os.path.exists('/tmp/.nfsbindip_notfound'): return [ Alert( Alert.WARN, _('NFS services could not bind specific IPs, using wildcard'), ) ] alertPlugins.register(NFSBindAlert)
from freenasUI.middleware.notifier import notifier class BootVolumeStatusAlert(BaseAlert): name = 'BootVolumeStatus' def on_volume_status_not_healthy(self, state, status): return Alert( Alert.CRIT, _('The boot volume state is %(state)s: %(status)s') % { 'state': state, 'status': status, }, hardware=True, ) def run(self): alerts = [] state, status = notifier().zpool_status('freenas-boot') if state == 'HEALTHY': pass else: alerts.append( self.on_volume_status_not_healthy(state, status) ) return alerts alertPlugins.register(BootVolumeStatusAlert)
lock = LockFile(COLLECTD_FILE) while not lock.i_am_locking(): try: lock.acquire(timeout=5) except LockTimeout: return alerts with open(COLLECTD_FILE, 'rb') as f: try: data = pickle.loads(f.read()) except: data = {} lock.release() for k, v in list(data.items()): if v['Severity'] == 'WARNING': l = Alert.WARN else: l = Alert.CRIT if k == 'ctl-ha/disk_octets': msg = "CTL HA link is actively used, check initiators connectivity" else: msg = k alerts.append(Alert(l, msg)) return alerts alertPlugins.register(CollectdAlert)
import os from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class ServiceMonitor(BaseAlert): def run(self): alerts = [] for file in os.listdir("/tmp/"): if file.endswith(".service_monitor"): full_path = '/tmp/' + file with open(full_path, 'r') as _file: for alert_line in _file: alerts.append(Alert(Alert.WARN, alert_line)) return alerts alertPlugins.register(ServiceMonitor)
interval = 60 def run(self): alerts = [] try: update = Update.objects.order_by('-id')[0] except IndexError: update = Update.objects.create() path = notifier().get_update_location() if not path: return None try: updates = PendingUpdates(path) except: updates = None if updates: alerts.append( Alert( Alert.OK, _( 'There is a new update available! Apply it in System ' '-> Update tab.' ), ) ) return alerts alertPlugins.register(UpdateCheckAlert)
mibs = o.name.split('.', 3) if len(mibs) < 4: continue number, mib = mibs[2:4] try: major = int(o.value.split('.', 1)[0]) mps[number][mib] = major except: continue for number, mibs in mps.items(): firmware = mibs.get('firmware_version') driver = mibs.get('driver_version') if firmware != driver: alerts.append( Alert( Alert.WARN, _('Firmware version %(fwversion)s does not match driver ' 'version %(drversion)s for /dev/mps%(mps)s') % { 'fwversion': firmware, 'drversion': driver, 'mps': number, })) return alerts alertPlugins.register(LSIFirmwareAlert)
from freenasUI.system.alert import alertPlugins, Alert, BaseAlert from freenasUI.system.ixselftests import (ALERT_FILE, TEST_PASS, TEST_WARNING, TEST_FAIL, TEST_CRITICAL) class ixSelfTestAlert(BaseAlert): interval = 5 def run(self): alerts = [] regexp = re.compile(r"\[(.*)\] (.*)") if os.path.exists(ALERT_FILE): with open(ALERT_FILE) as f: for line in f: line = line.rstrip() # Line looks like [PASS|FAIL]<text>, maybe other tags match = regexp.match(line) lvl = Alert.WARN if match: if match.group(1) in (TEST_WARNING): lvl = Alert.WARN elif match.group(1) in (TEST_FAIL, TEST_CRITICAL): lvl = Alert.CRIT elif match.group(1) in (TEST_PASS): lvl = Alert.OK alerts.append(Alert(lvl, match.group(2))) else: alerts.append(Alert(lvl, line)) return alerts alertPlugins.register(ixSelfTestAlert)
if not os.path.exists(LICENSE_FILE): return None with open(LICENSE_FILE, 'rb') as f: data = f.read() try: license = License.load(data) except: return [Alert( Alert.CRIT, _('Unable to decode %s license') % get_sw_name(), )] end_date = license.contract_end if end_date < datetime.now().date(): return [Alert( Alert.CRIT, _('Your %s license has expired') % get_sw_name(), )] elif end_date - timedelta(days=30) < datetime.now().date(): return [Alert( Alert.WARN, _( 'Your %(sw_name)s license is going to expire in %(date)s' ) % { 'sw_name': get_sw_name(), 'date': end_date, } )] alertPlugins.register(LicenseExpiredAlert)
from django.utils.translation import ugettext_lazy as _ from freenasUI.middleware.notifier import notifier from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class MultipathAlert(BaseAlert): def run(self): not_optimal = [] for mp in notifier().multipath_all(): if mp.status != 'OPTIMAL': not_optimal.append(mp.name) if not_optimal: return [ Alert( Alert.CRIT, _('The following multipaths are not optimal: %s') % ( ', '.join(not_optimal), ) ) ] alertPlugins.register(MultipathAlert)
self.__count[iface.name] += 1 if self.__count[iface.name] > 2: alerts.append( Alert( Alert.CRIT, _('These ports are not ACTIVE on LAGG interface %(name)s: %(ports)s. Please check cabling and switch.' ) % { 'name': iface.name, 'ports': ', '.join(inactive) }, )) # For FAILOVER protocol we should have one ACTIVE port elif len( active ) != 1 and iface.protocol == netif.AggregationProtocol.FAILOVER: # Only alert if this has happened more than twice, see #24160 self.__count[iface.name] += 1 if self.__count[iface.name] > 2: alerts.append( Alert( Alert.CRIT, _('There are no ACTIVE ports on LAGG interface %(name)s. Please check cabling and switch.' ) % {'name': iface.name}, )) else: self.__count[iface.name] = 0 return alerts alertPlugins.register(LAGGStatus)
import os from django.utils.translation import ugettext as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert PORTAL_IP_FILE = '/var/tmp/iscsi_portal_ip' class PortalIPAlert(BaseAlert): def run(self): if not os.path.exists(PORTAL_IP_FILE): return None with open(PORTAL_IP_FILE) as f: ips = f.read().split('\n') ips = [y for y in ips if bool(y)] return [ Alert( Alert.WARN, _('The following IPs are bind to iSCSI Portal but were not' ' found in the system: %s') % (', '.join(ips)) ) ] alertPlugins.register(PortalIPAlert)
import os from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class SSLAlert(BaseAlert): def run(self): if os.path.exists('/tmp/alert_invalid_ssl_nginx'): return [ Alert( Alert.WARN, 'HTTP SSL certificate is not valid, failling back to HTTP' ), ] alertPlugins.register(SSLAlert)
import os from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class ADAlert(BaseAlert): def run(self): alerts = [] if os.path.exists('/tmp/.adalert'): alerts.append(Alert(Alert.WARN, "ActiveDirectory did not bind to the domain")) return alerts alertPlugins.register(ADAlert)
import os from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class LDAPStatusAlert(BaseAlert): def run(self): alerts = [] if os.path.exists('/tmp/.ldap_status_alert'): alerts.append(Alert(Alert.WARN, "LDAP did not bind to the domain")) return alerts alertPlugins.register(LDAPStatusAlert)
alerts.append(Alert( Alert.CRIT, _('You need to upgrade the volume %s') % vol.vol_name, )) else: proc = subprocess.Popen([ "zpool", "get", "-H", "-o", "property,value", "all", str(vol.vol_name), ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) data = proc.communicate()[0].strip('\n') for line in data.split('\n'): if not line.startswith('feature') or '\t' not in line: continue prop, value = line.split('\t', 1) if value not in ('active', 'enabled'): alerts.append(Alert( Alert.WARN, _( 'You need to upgrade the volume %s' ) % vol.vol_name, )) break return alerts alertPlugins.register(VolumeVersionAlert)
from freenasUI.system.alert import alertPlugins, Alert, BaseAlert from lockfile import LockFile VMWARESNAPDELETE_FAILS = '/var/tmp/.vmwaresnapdelete_fails' class VMWareSnapDeleteFailAlert(BaseAlert): def run(self): try: with LockFile(VMWARESNAPDELETE_FAILS) as lock: with open(VMWARESNAPDELETE_FAILS, 'rb') as f: fails = pickle.load(f) except: return None alerts = [] for snapname, vms in fails.items(): alerts.append(Alert(Alert.WARN, _( 'VMWare snapshot deletion %(snap)s failed for the following VMs: ' '%(vms)s' ) % { 'snap': snapname, 'vms': ', '.join(vms), })) return alerts alertPlugins.register(VMWareSnapDeleteFailAlert)
encoding='utf8') data = proc.communicate()[0] if proc.returncode != 0: continue try: cap = int(data.strip('\n').replace('%', '')) except ValueError: continue msg = _( 'The capacity for the volume \'%(volume)s\' is currently at ' '%(capacity)d%%, while the recommended value is below 80%%.') level = None if cap >= 90: level = Alert.CRIT elif cap >= 80: level = Alert.WARN if level: alerts.append( Alert( level, msg % { 'volume': pool, 'capacity': cap, }, )) return alerts alertPlugins.register(ZpoolCapAlert)
import os from django.utils.translation import ugettext as _ from freenasUI.middleware.notifier import GELI_REKEY_FAILED from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class VolRekeyAlert(BaseAlert): def run(self): alerts = [] if os.path.exists(GELI_REKEY_FAILED): alerts.append(Alert(Alert.CRIT, _( 'Encrypted volume failed to rekey some disks. Please make ' 'sure you have working recovery keys, check logs files and ' 'correct the error as it may result to data loss.' ))) return alerts alertPlugins.register(VolRekeyAlert)
VMWARELOGIN_FAILS = '/var/tmp/.vmwarelogin_fails' class VMWareLoginFailAlert(BaseAlert): def run(self): try: with LockFile(VMWARELOGIN_FAILS) as lock: with open(VMWARELOGIN_FAILS, 'rb') as f: fails = pickle.load(f) except: return None alerts = [] for oid, errmsg in list(fails.items()): vmware = VMWarePlugin.objects.filter(id=oid) if not vmware.exists(): continue vmware = vmware[0] alerts.append(Alert(Alert.WARN, _( 'VMWare %(vmware)s failed to login to snapshot: %(err)s' % { 'vmware': vmware, 'err': errmsg, } ))) return alerts alertPlugins.register(VMWareLoginFailAlert)
from django.utils.translation import ugettext as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert from freenasUI.system.models import Settings class HTTPDBindAlert(BaseAlert): def run(self): address = Settings.objects.all().order_by('-id')[0].stg_guiaddress with open('/usr/local/etc/nginx/nginx.conf') as f: # XXX: this is parse the file instead of slurping in the contents # (or in reality, just be moved somewhere else). if (f.read().find('0.0.0.0') != -1 and address not in ('0.0.0.0', '')): # XXX: IPv6 return [ Alert( Alert.WARN, _('The WebGUI Address could not bind to %s; using ' 'wildcard') % (address,), ) ] alertPlugins.register(HTTPDBindAlert)
import os from django.utils.translation import ugettext as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class UpdateFailedAlert(BaseAlert): interval = 60 def run(self): alerts = [] if os.path.exists('/data/update.failed'): alerts.append( Alert( Alert.CRIT, _( 'Update failed. Check /data/update.failed for further ' 'details.' ), ) ) return alerts alertPlugins.register(UpdateFailedAlert)
import os from django.utils.translation import ugettext as _ from freenasUI.middleware.notifier import GELI_REKEY_FAILED from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class VolRekeyAlert(BaseAlert): def run(self): alerts = [] if os.path.exists(GELI_REKEY_FAILED): alerts.append( Alert( Alert.CRIT, _('Encrypted volume failed to rekey some disks. Please make ' 'sure you have working recovery keys, check logs files and ' 'correct the error as it may result to data loss.'))) return alerts alertPlugins.register(VolRekeyAlert)
from freenasUI.system.alert import alertPlugins, Alert, BaseAlert from lockfile import LockFile VMWARE_FAILS = '/var/tmp/.vmwaresnap_fails' class VMWareSnapFailAlert(BaseAlert): def run(self): try: with LockFile(VMWARE_FAILS) as lock: with open(VMWARE_FAILS, 'rb') as f: fails = pickle.load(f) except: return None alerts = [] for snapname, vms in fails.items(): alerts.append( Alert( Alert.WARN, _('VMWare snapshot %(snap)s failed for the following VMs: ' '%(vms)s') % { 'snap': snapname, 'vms': ', '.join(vms), })) return alerts alertPlugins.register(VMWareSnapFailAlert)
return None if ( hasattr(notifier, 'failover_status') and notifier().failover_status() == 'BACKUP' ): return None systemdataset, basename = notifier().system_dataset_settings() if not systemdataset.sys_pool: return [ Alert( Alert.WARN, "No system pool configured, please configure one in " "Settings->System Dataset->Pool" ), ] if os.path.exists('/var/db/samba4/.alert_cant_migrate'): return [ Alert( Alert.WARN, "Multiple legacy samba4 datasets detected. Auto-migration " "to /mnt/%s/.system/samba4 cannot be done. Please perform " "this step manually and then delete the now-obsolete " "samba4 datasets and /var/db/samba4/.alert_cant_migrate" % systemdataset.sys_pool ), ] alertPlugins.register(Samba4Alert)
if 'freenas' in systemname.lower() and boardname == 'C2750D4I': mcinfo = pipeopen("/usr/local/bin/ipmitool mc info").communicate()[0] reg = re.search(r'Firmware Revision.*: (\S+)', mcinfo, flags=re.M) if not reg: return alerts fwver = reg.group(1) try: fwver = [int(i) for i in fwver.split('.')] except ValueError: log.warn('Failed to parse BMC firmware version: {}'.format(fwver)) return alerts if len(fwver) < 2 or not(fwver[0] == 0 and fwver[1] < 30): return alerts alerts.append( Alert( Alert.CRIT, _( 'FreeNAS Mini Critical IPMI Firmware Update - Your ' 'Mini has an available IPMI firmware update, please ' 'click <a href="%s" target="_blank">here</a> for ' 'installation instructions' ) % 'https://support.ixsystems.com/index.php?/Knowledgebase/Article/View/287', ) ) return alerts alertPlugins.register(FreeNASBMCAlert)
import os from django.utils.translation import ugettext_lazy as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert PORTAL_IP_FILE = '/var/tmp/iscsi_portal_ip' class PortalIPAlert(BaseAlert): def run(self): if not os.path.exists(PORTAL_IP_FILE): return None with open(PORTAL_IP_FILE) as f: ips = f.read().split('\n') ips = filter(lambda y: bool(y), ips) return [ Alert( Alert.WARN, _('The following IPs are bind to iSCSI Portal but were not' ' found in the system: %s') % (', '.join(ips)) ) ] alertPlugins.register(PortalIPAlert)
class ixSelfTestAlert(BaseAlert): interval = 5 def run(self): alerts = [] regexp = re.compile(r"\[(.*)\] (.*)") if os.path.exists(ALERT_FILE): with open(ALERT_FILE) as f: for line in f: line = line.rstrip() # Line looks like [PASS|FAIL]<text>, maybe other tags match = regexp.match(line) lvl = Alert.WARN if match: if match.group(1) in (TEST_WARNING): lvl = Alert.WARN elif match.group(1) in (TEST_FAIL, TEST_CRITICAL): lvl = Alert.CRIT elif match.group(1) in (TEST_PASS): lvl = Alert.OK alerts.append(Alert(lvl, match.group(2))) else: alerts.append(Alert(lvl, line)) return alerts alertPlugins.register(ixSelfTestAlert)
from freenasUI.system.models import Advanced class Samba4Alert(BaseAlert): def run(self): if not Volume.objects.all().exists(): return None advanced = Advanced.objects.all()[0] if not advanced.adv_system_pool: return [ Alert( Alert.WARN, "No system pool configured, please configure one in " \ "Settings->Advanced->System dataset pool" ), ] if os.path.exists('/var/db/samba4/.alert_cant_migrate'): return [ Alert( Alert.WARN, "Multiple legacy samba4 datasets detected. Auto-migration to " \ "/mnt/%s/.system/samba4 cannot be done. Please perform this step " \ "manually and then delete the now-obsolete samba4 datasets and " \ "/var/db/samba4/.alert_cant_migrate" % advanced.adv_system_pool ), ] alertPlugins.register(Samba4Alert)
import os from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class ADAlert(BaseAlert): def run(self): alerts = [] if os.path.exists('/tmp/.adalert'): alerts.append( Alert(Alert.WARN, "ActiveDirectory did not bind to the domain")) return alerts alertPlugins.register(ADAlert)
from freenasUI.system.alert import alertPlugins, Alert, BaseAlert from lockfile import LockFile VMWARE_FAILS = '/var/tmp/.vmwaresnap_fails' class VMWareSnapFailAlert(BaseAlert): def run(self): try: with LockFile(VMWARE_FAILS) as lock: with open(VMWARE_FAILS, 'rb') as f: fails = pickle.load(f) except: return None alerts = [] for snapname, vms in list(fails.items()): alerts.append(Alert(Alert.WARN, _( 'VMWare snapshot %(snap)s failed for the following VMs: ' '%(vms)s' ) % { 'snap': snapname, 'vms': ', '.join(vms), })) return alerts alertPlugins.register(VMWareSnapFailAlert)
from freenasUI.system.alert import alertPlugins, Alert, BaseAlert from lockfile import LockFile VMWARESNAPDELETE_FAILS = '/var/tmp/.vmwaresnapdelete_fails' class VMWareSnapDeleteFailAlert(BaseAlert): def run(self): try: with LockFile(VMWARESNAPDELETE_FAILS) as lock: with open(VMWARESNAPDELETE_FAILS, 'rb') as f: fails = pickle.load(f) except: return None alerts = [] for snapname, vms in fails.items(): alerts.append( Alert( Alert.WARN, _('VMWare snapshot deletion %(snap)s failed for the following VMs: ' '%(vms)s') % { 'snap': snapname, 'vms': ', '.join(vms), })) return alerts alertPlugins.register(VMWareSnapDeleteFailAlert)
], stdout=subprocess.PIPE, stderr=subprocess.PIPE) data = proc.communicate()[0] if proc.returncode != 0: continue try: cap = int(data.split('\t')[4].replace('%', '')) except ValueError: continue msg = _( 'The capacity for the volume \'%(volume)s\' is currently at ' '%(capacity)d%%, while the recommended value is below 80%%.' ) level = None if cap >= 90: level = Alert.CRIT elif cap >= 80: level = Alert.WARN if level: alerts.append( Alert( level, msg % { 'volume': vol.vol_name, 'capacity': cap, }, ) ) return alerts alertPlugins.register(ZpoolCapAlert)
if not os.path.exists(SMART_FILE): return alerts lock = LockFile(SMART_FILE) while not lock.i_am_locking(): try: lock.acquire(timeout=5) except LockTimeout: return alerts with open(SMART_FILE, 'rb') as f: try: data = pickle.loads(f.read()) except: data = {} for msgs in data.itervalues(): if not msgs: continue for msg in msgs: if msg is None: continue alerts.append(Alert(Alert.CRIT, msg, hardware=True)) lock.release() return alerts alertPlugins.register(SMARTAlert)
from freenasUI.middleware.notifier import notifier class BootVolumeStatusAlert(BaseAlert): __metaclass__ = HookMetaclass __hook_reverse_order__ = False name = 'BootVolumeStatus' def on_volume_status_not_healthy(self, state, status): return Alert( Alert.CRIT, _('The boot volume state is %(state)s: %(status)s') % { 'state': state, 'status': status, }, hardware=True, ) def run(self): alerts = [] state, status = notifier().zpool_status('freenas-boot') if state == 'HEALTHY': pass else: alerts.append(self.on_volume_status_not_healthy(state, status)) return alerts alertPlugins.register(BootVolumeStatusAlert)
try: major = int(o.value.split('.', 1)[0]) mpr[number][mib] = major except: continue for number, mibs in mpr.items(): firmware = mibs.get('firmware_version') driver = mibs.get('driver_version') # For the 93xx controllers the firmware package # is always one version behind the driver package # version...why, because Avago hates us. if firmware != (driver - 1): alerts.append(Alert( Alert.WARN, _( 'Firmware version %(fwversion)s does not match driver ' 'version %(drversion)s for /dev/mpr%(mpr)s. Please ' 'flash controller to P%(drversion)s IT firmware.' ) % { 'fwversion': firmware, 'drversion': (driver - 1), 'mpr': number, } )) return alerts alertPlugins.register(MPRFirmwareAlert)
mibs = o.name.split('.', 3) if len(mibs) < 4: continue number, mib = mibs[2:4] try: major = int(o.value.split('.', 1)[0]) mpr[number][mib] = major except: continue for number, mibs in mpr.items(): firmware = mibs.get('firmware_version') driver = mibs.get('driver_version') if firmware != driver: alerts.append( Alert( Alert.WARN, _('Firmware version %(fwversion)s does not match driver ' 'version %(drversion)s for /dev/mpr%(mpr)s') % { 'fwversion': firmware, 'drversion': driver, 'mpr': number, })) return alerts alertPlugins.register(MPRFirmwareAlert)
from django.utils.translation import ugettext as _ from freenasUI.middleware.notifier import notifier from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class MultipathAlert(BaseAlert): def run(self): not_optimal = [] for mp in notifier().multipath_all(): if mp.status != 'OPTIMAL': not_optimal.append(mp.name) if not_optimal: return [ Alert( Alert.CRIT, _('The following multipaths are not optimal: %s') % (', '.join(not_optimal), )) ] alertPlugins.register(MultipathAlert)
from django.utils.translation import ugettext as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert from freenasUI.storage.models import Replication class ReplicationStatusAlert(BaseAlert): def run(self): qs = Replication.objects.filter(repl_enabled=True) alerts = [] for repl in qs: if repl.repl_lastresult in ('Succeeded', 'Up to date', 'Waiting', 'Running', '', None): continue alerts.append(Alert( Alert.CRIT, _('Replication %(replication)s failed: %(message)s') % { 'replication': repl, 'message': repl.repl_lastresult, }, )) return alerts alertPlugins.register(ReplicationStatusAlert)
VMWARELOGIN_FAILS = '/var/tmp/.vmwarelogin_fails' class VMWareLoginFailAlert(BaseAlert): def run(self): try: with LockFile(VMWARELOGIN_FAILS) as lock: with open(VMWARELOGIN_FAILS, 'rb') as f: fails = pickle.load(f) except: return None alerts = [] for oid, errmsg in list(fails.items()): vmware = VMWarePlugin.objects.filter(id=oid) if not vmware.exists(): continue vmware = vmware[0] alerts.append( Alert( Alert.WARN, _('VMWare %(vmware)s failed to login to snapshot: %(err)s' % { 'vmware': vmware, 'err': errmsg, }))) return alerts alertPlugins.register(VMWareLoginFailAlert)
from django.utils.translation import ugettext as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert from freenasUI.storage.models import Replication class ReplicationStatusAlert(BaseAlert): def run(self): qs = Replication.objects.filter(repl_enabled=True) alerts = [] for repl in qs: if repl.repl_lastresult.get('msg') in ('Succeeded', 'Up to date', 'Waiting', 'Running', '', None): continue alerts.append( Alert( Alert.CRIT, _('Replication %(replication)s failed: %(message)s') % { 'replication': repl, 'message': repl.repl_lastresult.get('msg'), }, )) return alerts alertPlugins.register(ReplicationStatusAlert)
for name, flags in iface.ports: if netif.LaggPortFlags.ACTIVE not in flags: inactive.append(name) else: active.append(name) # ports that are not ACTIVE and LACP if inactive and iface.protocol == netif.AggregationProtocol.LACP: # Only alert if this has happened more than twice, see #24160 self.__count[iface.name] += 1 if self.__count[iface.name] > 2: alerts.append(Alert( Alert.CRIT, _('These ports are not ACTIVE on LAGG interface %(name)s: %(ports)s. Please check cabling and switch.') % {'name': iface.name, 'ports': ', '.join(inactive)}, )) # For FAILOVER protocol we should have one ACTIVE port elif len(active) != 1 and iface.protocol == netif.AggregationProtocol.FAILOVER: # Only alert if this has happened more than twice, see #24160 self.__count[iface.name] += 1 if self.__count[iface.name] > 2: alerts.append(Alert( Alert.CRIT, _('There are no ACTIVE ports on LAGG interface %(name)s. Please check cabling and switch.') % {'name': iface.name}, )) else: self.__count[iface.name] = 0 return alerts alertPlugins.register(LAGGStatus)
import os from django.utils.translation import ugettext as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert from freenasUI.system.models import Settings class HTTPDBindAlert(BaseAlert): def run(self): address = Settings.objects.all().order_by('-id')[0].stg_guiaddress with open('/usr/local/etc/nginx/nginx.conf') as f: # XXX: this is parse the file instead of slurping in the contents # (or in reality, just be moved somewhere else). if f.read().find('0.0.0.0') != -1 and address not in ('0.0.0.0', ''): # XXX: IPv6 return [ Alert( Alert.WARN, _('The WebGUI Address could not bind to %s; using ' 'wildcard') % (address, ), ) ] alertPlugins.register(HTTPDBindAlert)
while not lock.i_am_locking(): try: lock.acquire(timeout=5) except LockTimeout: return alerts with open(COLLECTD_FILE, 'rb') as f: try: data = pickle.loads(f.read()) except: data = {} lock.release() for k, v in list(data.items()): if v['Severity'] == 'WARNING': l = Alert.WARN else: l = Alert.CRIT if k == 'ctl-ha/disk_octets': msg = "CTL HA link is actively used, check initiators connectivity" else: msg = k alerts.append(Alert(l, msg)) return alerts alertPlugins.register(CollectdAlert)
alerts = [] mps = defaultdict(dict) for o in sysctl.filter('dev.mps'): mibs = o.name.split('.', 3) if len(mibs) < 4: continue number, mib = mibs[2:4] try: major = int(o.value.split('.', 1)[0]) mps[number][mib] = major except: continue for number, mibs in mps.items(): firmware = mibs.get('firmware_version') driver = mibs.get('driver_version') if firmware != driver: alerts.append(Alert( Alert.WARN, _( 'Firmware version %s does not match driver version %s ' 'for /dev/mps%s' ) % (firmware, driver, number) )) return alerts alertPlugins.register(LSIFirmwareAlert)
if 'freenas' in systemname.lower() and boardname == 'C2750D4I': mcinfo = pipeopen( "/usr/local/bin/ipmitool mc info").communicate()[0] reg = re.search(r'Firmware Revision.*: (\S+)', mcinfo, flags=re.M) if not reg: return alerts fwver = reg.group(1) try: fwver = [int(i) for i in fwver.split('.')] except ValueError: log.warn( 'Failed to parse BMC firmware version: {}'.format(fwver)) return alerts if len(fwver) < 2 or not (fwver[0] == 0 and fwver[1] < 30): return alerts alerts.append( Alert( Alert.CRIT, _('FreeNAS Mini Critical IPMI Firmware Update - Your ' 'Mini has an available IPMI firmware update, please ' 'click <a href="%s" target="_blank">here</a> for ' 'installation instructions') % 'https://support.ixsystems.com/index.php?/Knowledgebase/Article/View/287', )) return alerts alertPlugins.register(FreeNASBMCAlert)
import os from django.utils.translation import ugettext as _ from freenasUI.system.alert import alertPlugins, Alert, BaseAlert class NFSBindAlert(BaseAlert): def run(self): if os.path.exists('/tmp/.nfsbindip_notfound'): return [ Alert( Alert.WARN, _('NFS services could not bind specific IPs, using wildcard' ), ) ] alertPlugins.register(NFSBindAlert)