{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":30366,"path":"it-operations-management/event-management/create-maintenance-rule.md","title":"Create maintenance rules","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create maintenance rules\n\nUse maintenance rules to mark CIs in maintenance status. When in maintenance status, these CIs are excluded from impact calculation.\n\n## Before you begin\n\nRole required: evt\\_mgmt\\_admin\n\n## About this task\n\nYou can define rules to mark CIs that match the specified criteria as being in maintenance status. The marked CIs populate the Impact Maintenance CIs \\[em\\_impact\\_maint\\_ci\\] table.\n\n**Note:** When running maintenance rules, the cmdb\\_ci status of matching CIs is not changed. However, matching CIs are flagged in the em\\_impact\\_maint\\_ci table by these rules and this status is considered for impact and alert calculations.\n\nThe field flagged by this rule as being in maintenance status is the CMDB status field.\n\n**Note:** To activate a maintenance rule, select the **Active** field in the maintenance rule. To deactivate a maintenance rule, clear the **Active** field.\n\nThe maintenance rules provided with the base instance are:\n\n<table id=\"table_qvy_w5f_qz\"><thead><tr><th>\n\nDefault maintenance rule\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nCI in Change Window\n\n</td><td>\n\nWhere the CI has an active change window, the matching CIs are marked as being in maintenance status.The rule runs a query against the change request \\[change\\_request\\] table to determine whether the rule is applied. All these conditions in the change\\_request table must be met:\n\n-   **State** is one of these options: Scheduled, Implement, Work in Progress, or Open/New \\(state in \\(-2, -1, 1, 2\\)\\).\n-   **Approval** is Approved \\(approval = 'approved'\\).\n-   The change request window is active, that is, the current time is between **Planned start date** and **Planned end date**, or the current time is between **Actual start date** and **Actual end date**.\n-   The change request record is not an on-hold record \\(on\\_hold='false'\\).\n\n **Note:** All these conditions must be present for the CI to be placed in maintenance status by this rule. For example, if the **State** of the change request approval status is `Change is waiting for approval`, then the change is not added to the em\\_impact\\_maint\\_ci table.\n\n</td></tr><tr><td>\n\nMaintenance status of CI\n\n</td><td>\n\nCIs whose CMDB status field is **In Maintenance** are flagged by this rule as being in maintenance status.By default, retired CIs are not included in CIs that are **In Maintenance**. To include retired CIs:\n\n1.  Navigate to **All Properties**.\n2.  Select **New**.\n3.  Configure the **evt\\_mgmt.maintenance\\_rule\\_include\\_retired** property with **Value = true**.\n\n **Note:**\n\nIncluding thousands of retired CIs may decrease system performance.\n\n</td></tr></tbody>\n</table>## Procedure\n\n1.  Navigate to **All** &gt; **Event Management** &gt; **Rules** &gt; **Maintenance Rules**.\n\n2.  Click **New**.\n\n3.  Fill in the fields, as appropriate.\n\n<table id=\"table_osj_py4_dx\"><thead><tr><th>\n\nColumn heading\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nName\n\n</td><td>\n\nThe maintenance rule name.\n\n</td></tr><tr><td>\n\nActive\n\n</td><td>\n\nSelect to activate the maintenance rule.\n\n</td></tr><tr><td>\n\nAdvanced\n\n</td><td>\n\nSelect to enable the optional script section to display.\n\n</td></tr><tr><td>\n\nDescription\n\n</td><td>\n\nInformation that describes this maintenance rule.\n\n</td></tr><tr><td>\n\nFlag CIs that run on this host\n\n</td><td>\n\nSelect to flag all applications running on the recognized host as being in maintenance.\n\n</td></tr><tr><td>\n\nTable\n\n</td><td>\n\nSelect the table that contains the CI that you require.\n\n</td></tr><tr><td>\n\nFilter\n\n</td><td>\n\nSpecify how to select the data.\n\n</td></tr><tr><td>\n\nCI field name\n\n</td><td>\n\nSelect the CI from the list. The list is populated according to your selection in the **Table** field. If a CMDB table, or a table derived from CMDB, was selected, specify `sys_id` for the **CI field name**. Otherwise, specify the required CI field that you want to use. See the examples.\n\n</td></tr></tbody>\n</table>4.  Click **Submit**.\n\n\n## Example\n\nExample of a maintenance rule using a CMDB table.\n\nAssume that a company defines a CI as being in maintenance when the Operational Status of the CI is either **Repair in Progress** or **DR Standby**.\n\n\\[Omitted image \"create-maintenance-rule-example.jpeg\"\\] Alt text: Event Management rule\n\nExample of a maintenance rule using a table other than CMDB.\n\nAssume that a company uses Incident records to track maintenance. Any maintenance request is translated to an incident when it has a description that starts with “Performing maintenance on CI”. As long as the status of such an incident is open, this status indicates that the maintenance is in progress. For the **CI field name** field, specify a CI name from the table that was chosen, in this case **Incident**.\n\n\\[Omitted image \"create-maintenance-rule-not-cmdb.png\"\\] Alt text: Event Management table\n\nExample of a maintenance rule that uses the advanced script feature.\n\nIn the Maintenance Rule page, select the **Advanced** option. Customize the provided example script:\n\n```\nvar gr = new GlideRecord('cmdb_ci');\ngr.addQuery('name', 'your_name_here');\ngr.query();\nwhile (gr.next()){\n result.push(gr.sys_id +'');}\n```\n\nThe advanced script must always return a text string that represents an array of CI IDs, for example, \\['sys\\_id1','sys\\_id2','sys\\_id3'\\]. Ensure that every possible execution path returns a value. If the script does not return a value, the maintenance calculator job fails with an exception.\n\nYou can use this script as an example to prepare your own customized script.\n\n\\[Omitted image \"maintenance-rule-script.png\"\\] Alt text: Event Management script\n\n**Parent Topic:**[Manage and monitor alerts](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/it-operations-management/event-management/c_EMAlert.md)\n\n**Related topics**  \n\n\n[How alerts work with CIs in maintenance](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/it-operations-management/event-management/c_EMHowImpactTree.md)\n\n[Place an alert into maintenance](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/it-operations-management/event-management/t_EMPutAnAlertIntoMaintenance.md)\n\n"}}