Availabilty Calculation for Service offering once outage has been raised against it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 02:28 AM
I am trying to calculate the availability of service offering against which an outage is raised but the availability still remains to 100% " . On investigating further , i have concluded that once the service offering is copied to CI field on outage form than the availability is calculated ( which reflect the basic functionality i.e CI set on the outage ) . Please note that i have introduced service offering field on outage form .
There is a business rule "Recalculate Availability" for the outage availability calcs, and it uses the script include 'AvailabilitySummarizer' . My question is if i want to calculate the outage on service offering or business service basis than where do i need to make necessary change .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 05:14 AM
Hi Ali,
you have to make changes in the business rule.
what availability are you trying to check ?, outage duration ?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 06:45 AM
Thanks Harish , we are trying to get the absolute_availability ( % Total Availability) for the service offering . Suppose ABC service hit 2 outages and it's Total availability goes down to say 87% . Can you please point me out where i do have to change.
Code:
processOutageChange();
function processOutageChange() {
if (current.cmdb_ci.nil() && current.operation() != "update")
return; // no service offering to calculate against, and no previous CI
if (current.cmdb_ci.sys_class_name != "service_offering" && (!current.cmdb_ci.changes() || current.operation() != "update"))
return; // not a service offering, and CI didn't change
if (current.operation() == "update" && current.cmdb_ci.sys_class_name != "service_offering" && previous.cmdb_ci.sys_class_name != "service_offering")
return; // neither current nor previous CI is a Service Offering
if (current.type != "outage") {
if (!current.type.changes())
return; // not an "outage" outage
if (previous.type != "outage")
return; // not an "outage" outage
}
var oldTZ = gs.getSession().getTimeZoneName();
var defaultTZ = GlideUser.getSysTimeZone();
gs.print("Setting session timezone to " + defaultTZ + " for Service Offering availability calculations");
gs.getSession().setTimeZoneName(defaultTZ);
recalcAvailability();
gs.getSession().setTimeZoneName(oldTZ);
gs.print("Restored session timezone to " + oldTZ + " after Service Offering availability calculations");
}
function recalcAvailability() {
var current_ci_class = current.cmdb_ci.sys_class_name;
var newEndVal = current.end.getGlideObject().getNumericValue();
var newBeginVal = current.begin.getGlideObject().getNumericValue();
if (current.operation() == "delete" || current.operation() == "insert") {
if (current_ci_class == "service_offering")
updateCalc(newBeginVal, newEndVal, current);
return;
}
// this is an update
var oldEndVal = previous.end.getGlideObject().getNumericValue();
var oldBeginVal = previous.begin.getGlideObject().getNumericValue();
var intersect = isIntersect(oldBeginVal, oldEndVal, newBeginVal, newEndVal);
var previous_ci_class = previous.cmdb_ci.sys_class_name;
if (current.cmdb_ci.changes()) {
if (current_ci_class == "service_offering")
updateCalc(newBeginVal, newEndVal, current);
if (previous_ci_class == "service_offering")
updateCalc(oldBeginVal, oldEndVal, previous);
return;
}
// CI didn't change, so quit if not a Service Offering
if (current_ci_class != "service_offering")
return;
if (previous.begin.nil() || previous.end.nil()) {
// this is our first time calculating for this outage
updateCalc(newBeginVal, newEndVal, current);
return;
}
// we've calculated before for this outage, so need to be careful to cover the bases
if (current.type.changes()) {
// recalc with consideration that Begin or End may have changed
updateCalc(Math.min(newBeginVal, oldBeginVal), Math.max(newEndVal, oldEndVal), current);
return;
}
// Outage type didn't change, so just need to recalc dates covered by
// the difference between new and old Start times, and dates covered by
// difference between new and old End times
if (intersect) {
updateCalc(newEndVal, oldEndVal, current); // recalc days between new and old End values
updateCalc(newBeginVal, oldBeginVal, current); // recalc days between new and old Begin values
} else {
updateCalc(newBeginVal, newEndVal, current); // recalc days between new interval
updateCalc(oldBeginVal, oldEndVal, current); // recalc days between old interval
}
}
function updateCalc(v1, v2, ci) {
if (v1 == v2 || v1 == 0 || v2 == 0)
return;
var today = new GlideDateTime(gs.beginningOfTomorrow()).getNumericValue();
low = Math.max(0, Math.min(v1, v2));
high = Math.max(0, v1, v2);
if (low == high)
return;
while (low <= high && low < today) {
var cur = new GlideDateTime();
cur.setNumericValue(low);
gs.print("Calculating availability for Service Offering: " + ci.u_service_offering.getDisplayValue() + ", date: " + cur.getDisplayValue());
var d = new GlideDateTime();
d.setNumericValue(low);
var ac = new AvailabilitySummarizer();
// ac.setCI(ci.cmdb_ci.toString());
c.setCI(ci.u_service_offering.toString()); // Done these changes , u_serve_offering is the ref field on outage form
ac.summarize(d);
if (!gs.isLastDayOfWeek(d)) {
var week = new GlideDateTime(gs.beginningOfThisWeek()).getNumericValue();
if (low < week) {
gs.print("Recalculating relevant week");
ac.summarize(gs.endOfWeek(d));
}
}
if (!gs.isLastDayOfMonth(d)) {
var month = new GlideDateTime(gs.beginningOfThisMonth()).getNumericValue();
if (low < month) {
gs.print("Recalculating relevant month");
ac.summarize(gs.endOfMonth(d));
}
}
if (!gs.isLastDayOfYear(d)) {
var year = new GlideDateTime(gs.beginningOfThisYear()).getNumericValue();
if (low < year) {
gs.print("Recalculating relevant year");
ac.summarize(gs.endOfYear(d));
}
}
low += 24 * 3600 * 1000;
}
var twelvemonths = new GlideDateTime(gs.monthsAgoStart(12)).getNumericValue();
if (high > twelvemonths) {
gs.print("Recalculating last 7 days, last 30 days, last 12 months availability for Service Offering: " + ci.u_service_offering.getDisplayValue());
ac.summarize(gs.beginningOfYesterday());
// create or update Monthly availability records for last 12 months
for (var i = 0; i < 12; i++)
ac.summarize(new GlideDateTime(gs.monthsAgoEnd(i)));
}
}
function isIntersect(oldBegin, oldEnd, newBegin, newEnd) {
if (newBegin > oldEnd || newEnd < oldBegin)
return false;
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 07:22 AM
Ali can you specify what is your requirement ?
what exactly you need to change and what should you get modifying the code.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 05:59 PM
We are trying to calculate the availability of service offerings against which an outage is raised but the availability still remains to 100% ". We have introduced a custom field of service offering on outage form to capture it . System default behaviour is to calculate availability against CI's . ope this will clear the issue