diff --git a/scripts/mail-alarm b/scripts/mail-alarm index e0e39aa32d8..99be5c44de8 100755 --- a/scripts/mail-alarm +++ b/scripts/mail-alarm @@ -241,7 +241,7 @@ class CpuUsageAlarmETG(EmailTextGenerator): period="%d" % self.alarm_trigger_period, level="%.1f" % (self.alarm_trigger_level * 100.0), brand_console=branding.BRAND_CONSOLE, - cls_name=(self.cls == "Host") and "Server" or "VM", + cls_name=(self.cls == "Host" or self.params["is_control_domain"]) and "Server" or "VM", ) @@ -321,11 +321,14 @@ class MemoryUsageAlarmETG(EmailTextGenerator): super(MemoryUsageAlarmETG, self).__init__(mail_language, "memory_usage_alarm") if alarm_trigger_period is None: alarm_trigger_period = 60 - if cls != "Host": + if cls == "Host": + self.params = get_host_params(obj_uuid, session) + elif cls == "VM": + self.params = get_VM_params(obj_uuid, session) + else: raise Exception( - "programmer error - this alarm should only be available for hosts" + "programmer error - this alarm should only be available for hosts and VMs" ) - self.params = get_host_params(obj_uuid, session) self.cls = cls self.value = value self.alarm_trigger_period = alarm_trigger_period @@ -351,7 +354,7 @@ class MemoryUsageAlarmETG(EmailTextGenerator): body_pattern = ( 'Free memory on {cls} "{name_label}" has been on average {value} KiB for the last {period} seconds.\n' "This alarm is set to be triggered when free memory is less than {level} KiB.\n\n" - 'For Alarm Settings, please log into your {brand_console} Console and click on "Server"->\n' + 'For Alarm Settings, please log into your {brand_console} Console and click on "{cls_name}"->\n' '"Properties"->"Alerts"\n' ) @@ -362,6 +365,7 @@ class MemoryUsageAlarmETG(EmailTextGenerator): period="%d" % self.alarm_trigger_period, level="%d" % self.alarm_trigger_level, brand_console=branding.BRAND_CONSOLE, + cls_name=(self.cls == "Host" or self.params["is_control_domain"]) and "Server" or "VM", ) @@ -823,7 +827,8 @@ class XapiMessage: self.mail_language, self.session, ) - elif name == "memory_free_kib": + elif name in ["memory_free_kib", # for Host + "memory_internal_free"]: # for VM etg = MemoryUsageAlarmETG( self.cls, self.obj_uuid, diff --git a/scripts/mail-languages/en-US.json b/scripts/mail-languages/en-US.json index d0ddd70e091..b5d6e29a844 100644 --- a/scripts/mail-languages/en-US.json +++ b/scripts/mail-languages/en-US.json @@ -10,7 +10,7 @@ }, "memory_usage_alarm":{ "subject":"[{pool_name}] {product_brand} Alarm: Memory usage on {cls} \"{name_label}\"", - "body":"Free memory on {cls} \"{name_label}\" has been on average {value} KiB for the last {period} seconds.\nThis alarm is set to be triggered when free memory is less than {level} KiB.\n\nFor Alarm Settings, please log into your {brand_console} Console and click on \"Server\"->\n\"Properties\"->\"Alerts\"\n" + "body":"Free memory on {cls} \"{name_label}\" has been on average {value} KiB for the last {period} seconds.\nThis alarm is set to be triggered when free memory is less than {level} KiB.\n\nFor Alarm Settings, please log into your {brand_console} Console and click on \"{cls_name}\"->\n\"Properties\"->\"Alerts\"\n" }, "disk_usage_alarm":{ "subject":"[{pool_name}] {product_brand} Alarm: Disk usage on VM \"{name_label}\"", diff --git a/scripts/mail-languages/ja-JP.json b/scripts/mail-languages/ja-JP.json index 44b727dfe00..83bbdde34c1 100644 --- a/scripts/mail-languages/ja-JP.json +++ b/scripts/mail-languages/ja-JP.json @@ -10,7 +10,7 @@ }, "memory_usage_alarm":{ "subject":"[{pool_name}] {product_brand} アラート: {cls} \"{name_label}\" のメモリ使用率", - "body":"{cls} \"{name_label}\" の空きメモリは最近の {period} 秒で平均 {value} KiB です。\nこのアラートは空きメモリが {level} KiB を下回ると発するように設定されています。\n\n[アラート設定] は、{brand_console} コンソールにログインして次の順にをクリックしてください。\n[サーバー] -> [プロパティ] -> [アラート]\n" + "body":"{cls} \"{name_label}\" の空きメモリは最近の {period} 秒で平均 {value} KiB です。\nこのアラートは空きメモリが {level} KiB を下回ると発するように設定されています。\n\n[アラート設定] は、{brand_console} コンソールにログインして次の順にをクリックしてください。\n[{cls_name}] -> [プロパティ] -> [アラート]\n" }, "disk_usage_alarm":{ "subject":"[{pool_name}] {product_brand} アラート: VM \"{name_label}\" のディスク使用量", diff --git a/scripts/mail-languages/zh-CN.json b/scripts/mail-languages/zh-CN.json index 1bcdcd0b99c..4f6c6dcc11d 100644 --- a/scripts/mail-languages/zh-CN.json +++ b/scripts/mail-languages/zh-CN.json @@ -10,7 +10,7 @@ }, "memory_usage_alarm":{ "subject":"[{pool_name}] {product_brand} 警报: {cls}“{name_label}”的内存使用量", - "body":"{cls}“{name_label}”上的可用内存在过去 {period} 秒内处于平均值 {value} KiB。\n此警报设置为在可用内存低于 {level} KiB 时触发。\n\n要查看警报设置,请登录您的 {brand_console} 控制台并单击“服务器”->\n“属性”->“警报”\n" + "body":"{cls}“{name_label}”上的可用内存在过去 {period} 秒内处于平均值 {value} KiB。\n此警报设置为在可用内存低于 {level} KiB 时触发。\n\n要查看警报设置,请登录您的 {brand_console} 控制台并单击“{cls_name}”->\n“属性”->“警报”\n" }, "disk_usage_alarm":{ "subject":"[{pool_name}] {product_brand} 警报: VM“{name_label}”上的磁盘使用率", diff --git a/scripts/perfmon b/scripts/perfmon index c8955d17d41..a84c8eb5d61 100644 --- a/scripts/perfmon +++ b/scripts/perfmon @@ -694,6 +694,7 @@ class VMMonitor(ObjectMonitor): elif variable_name == "fs_usage": return "_$_DUMMY__" # match nothing elif variable_name == "log_fs_usage": return "_$_DUMMY__" # match nothing elif variable_name == "mem_usage": return "_$_DUMMY__" # match nothing + elif variable_name == "memory_internal_free": return variable_name else:raise XmlConfigException("variable %s: no default rrd_regex - please specify one" % variable_name) elif config_tag == 'alarm_trigger_period': return '60' # 1 minute elif config_tag == 'alarm_auto_inhibit_period': return '3600' # 1 hour @@ -702,7 +703,9 @@ class VMMonitor(ObjectMonitor): elif variable_name == "log_fs_usage": return '0.9' # trigger when 90% full elif variable_name == "mem_usage": return '0.95' # tigger when mem demanded is close to phy_mem else:raise XmlConfigException("variable %s: no default alarm_trigger_level - please specify one" % variable_name) - elif config_tag == 'alarm_trigger_sense': return 'high' # trigger if *above* + elif config_tag == 'alarm_trigger_sense': + if variable_name == "memory_internal_free": return "low" + else: return 'high' # trigger if *above* elif config_tag == 'alarm_priority': return '3' # Service degradation level defined in PR-1455 else:raise XmlConfigException("variable %s: no default available for tag %s" % (variable_name, config_tag)) diff --git a/scripts/test_mail-alarm.py b/scripts/test_mail-alarm.py index 4854c224ba9..2a918f5edbe 100644 --- a/scripts/test_mail-alarm.py +++ b/scripts/test_mail-alarm.py @@ -31,13 +31,14 @@ def nottest(obj): </variable> """ +test_vm_obj = {"name_label": "test_VM", "is_control_domain": False} def mock_setup(module): # Emulate functions with Mock module.log_err = log_err module.get_pool_name = mock.Mock(return_value="test_pool") module.get_sr_name_by_uuid = mock.Mock(return_value="test_sr") - module.get_VM_params = mock.Mock(return_value={"name_label": "test_VM"}) + module.get_VM_params = mock.Mock(return_value=test_vm_obj) module.get_host_params = mock.Mock(return_value={"name_label": "test_host"}) module.mail_language_pack_path = "./scripts/mail-languages" module.branding.PRODUCT_BRAND = "XenServer" @@ -144,15 +145,33 @@ def common_test_bad_input( os.remove(log_file_global) def test_good_mail_language(self): - # Test cpu_usage alarm - mail_subject_expected = ( - '[test_pool] XenServer Alarm: CPU usage on Host "test_host"' - ) - mail_body_expected = 'CPU usage on Host "test_host" has been on average 12.9% for the last 60 seconds.\nThis alarm is set to be triggered when CPU usage is more than 5.0%.\n\nFor Alarm Settings, please log into your XenCenter Console and click on "Server"->\n"Properties"->"Alerts"\n' + ## Test cpu_usage alarm + cpu_usage_alarm_subject = '[test_pool] XenServer Alarm: CPU usage on {cls} "{name_label}"' + cpu_usage_alarm_body = 'CPU usage on {cls} "{name_label}" has been on average 12.9% for the last 60 seconds.\nThis alarm is set to be triggered when CPU usage is more than 5.0%.\n\nFor Alarm Settings, please log into your XenCenter Console and click on "{cls_name}"->\n"Properties"->"Alerts"\n' + + # test Host + mail_subject_expected = cpu_usage_alarm_subject.format(cls='Host', name_label='test_host') + mail_body_expected = cpu_usage_alarm_body.format(cls='Host', name_label='test_host', cls_name='Server') self.common_test_good_input( "ALARM", "Host", "cpu_usage", mail_subject_expected, mail_body_expected ) + # test common VM + mail_subject_expected = cpu_usage_alarm_subject.format(cls='VM', name_label='test_VM') + mail_body_expected = cpu_usage_alarm_body.format(cls='VM', name_label='test_VM', cls_name='VM') + self.common_test_good_input( + "ALARM", "VM", "cpu_usage", mail_subject_expected, mail_body_expected + ) + + # test dom0 VM + test_vm_obj['is_control_domain'] = True + mail_subject_expected = cpu_usage_alarm_subject.format(cls='VM', name_label='test_VM') + mail_body_expected = cpu_usage_alarm_body.format(cls='VM', name_label='test_VM', cls_name='Server') + self.common_test_good_input( + "ALARM", "VM", "cpu_usage", mail_subject_expected, mail_body_expected + ) + test_vm_obj['is_control_domain'] = False + # Test network_usage alarm mail_subject_expected = ( '[test_pool] XenServer Alarm: Network usage on Host "test_host"' @@ -162,18 +181,32 @@ def test_good_mail_language(self): "ALARM", "Host", "network_usage", mail_subject_expected, mail_body_expected ) - # Test memory_free_kib alarm - mail_subject_expected = ( - '[test_pool] XenServer Alarm: Memory usage on Host "test_host"' + memory_usage_alarm_subject = '[test_pool] XenServer Alarm: Memory usage on {cls} "{name_label}"' + memory_usage_alarm_body = 'Free memory on {cls} "{name_label}" has been on average 0 KiB for the last 60 seconds.\nThis alarm is set to be triggered when free memory is less than 0 KiB.\n\nFor Alarm Settings, please log into your XenCenter Console and click on "{cls_name}"->\n"Properties"->"Alerts"' + + ## Test memory_free_kib alarm for Host + mail_subject_expected = memory_usage_alarm_subject.format(cls='Host', name_label='test_host') + mail_body_expected = memory_usage_alarm_body.format(cls='Host', name_label='test_host', cls_name='Server') + self.common_test_good_input( + "ALARM", "Host", "memory_free_kib", mail_subject_expected, mail_body_expected, ) - mail_body_expected = 'Free memory on Host "test_host" has been on average 0 KiB for the last 60 seconds.\nThis alarm is set to be triggered when free memory is less than 0 KiB.\n\nFor Alarm Settings, please log into your XenCenter Console and click on "Server"->\n"Properties"->"Alerts"' + + ## Test memory_internal_free alarm for VM + # test common VM + mail_subject_expected = memory_usage_alarm_subject.format(cls='VM', name_label='test_VM') + mail_body_expected = memory_usage_alarm_body.format(cls='VM', name_label='test_VM', cls_name='VM') self.common_test_good_input( - "ALARM", - "Host", - "memory_free_kib", - mail_subject_expected, - mail_body_expected, + "ALARM", "VM", "memory_internal_free", mail_subject_expected, mail_body_expected, + ) + + # test dom0 VM + test_vm_obj['is_control_domain'] = True + mail_subject_expected = memory_usage_alarm_subject.format(cls='VM', name_label='test_VM') + mail_body_expected = memory_usage_alarm_body.format(cls='VM', name_label='test_VM', cls_name='Server') + self.common_test_good_input( + "ALARM", "VM", "memory_internal_free", mail_subject_expected, mail_body_expected, ) + test_vm_obj['is_control_domain'] = False # Test disk_usage alarm mail_subject_expected = ( @@ -272,6 +305,9 @@ def test_bad_mail_language(self): self.common_test_bad_input( "ALARM", "Host", "cpu_usage", title_expected, subtitle_expected ) + self.common_test_bad_input( + "ALARM", "VM", "cpu_usage", title_expected, subtitle_expected + ) # Test network_usage alarm title_expected = "NetworkUsageAlarmETG" @@ -287,6 +323,13 @@ def test_bad_mail_language(self): "ALARM", "Host", "memory_free_kib", title_expected, subtitle_expected ) + # Test memory_internal_free alarm + title_expected = "MemoryUsageAlarmETG" + subtitle_expected = "memory_usage_alarm" + self.common_test_bad_input( + "ALARM", "VM", "memory_internal_free", title_expected, subtitle_expected + ) + # Test disk_usage alarm title_expected = "DiskUsageAlarmETG" subtitle_expected = "disk_usage_alarm"