-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInbound-Action-Script-For-Oracle-Cloud-Events-From-Nagios.txt
47 lines (41 loc) · 2.21 KB
/
Inbound-Action-Script-For-Oracle-Cloud-Events-From-Nagios.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//Parsing Email received from Nagios to get IP address of instance
var ip_address = email.body_text.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/)[0];
//Parsing Email received from nagios to get state of instance
var state = email.body_text.match(/(State)(.*)/g)[0].split(" ")[1];
//Parsing Email received from nagios to get resource and type for notification and this can be key element to differentiate events for services from same source
var type = "Host";
var resource = email.body_text.match(/(Service)(.*)/g);
if(resource != null){
resource = resource[0].split(":")[1];
type = "Service";
}
//State which we got in email, is string and Service Now couldnot map the string to its Severity list. Hence we are manipulating its value to index value of choice list.
if(state == "WARNING") { state = 4; }
else if((state == "CRITICAL") || (state == "UNKNOWN") || (state == "DOWN")) { state = 1;}
else {state = 5;}
//get Instance name and Instance_id using IP address from Virtual Machine table for mapping it to Event.
var instance_id='';
var instance_name='';
//querying OC Virtual Machine table for ip
var getIns = new GlideRecord("x_xr_oracle_cloud_oc_virtual_machines");
//We are querying both the coloumns, since ip_address registered can be either public or private ip address.
getIns.addQuery('public_ip_address','=', ip_address).addOrCondition('private_ip_address','=',ip_address);
getIns.query();
if(getIns.next()){
instance_id = getIns.getValue("sys_id");
instance_name = getIns.getValue("name");
}
if (instance_id != ''){
//Creating Event
current.source = "Nagios";
current.description = email.body_text;
current.type = type;
current.resource = resource; // resource is a key element in notification to differentiate events.
current.cmdb_ci = instance_id; //cmdb_ci is assigned to map the event and its alert to corresponding instance.Since cmdb_ci is a reference field, it accept only primary key. So instance id is assigned.
current.severity = state; // severity is list , so we have to assign index value of choice.
current.node = instance_name;
current.insert();
}
else{
gs.error("Virtual Machine with IP- "+ip_address+" not Found. Hence this Notification is Ignored!!");
}