This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Create custom resource to show "Who is On Call" via OpsGenie API

I'm setting up an OpsGenie trial right now, with SolarWinds Orion integration for on-call management. The feature set looks pretty sweet after having managed scheduling, rotation, and weekly changes manually!

Question: I'm curious if there is a way to create a custom resource on an Orion page that shows the current on-call person[s] via OpsGenie's API.

Parents
  • You can do this by adding a custom html widget in your dashboard and setting that resource up with a javascript to query the API then parse the response into something that looks readable.

    I don't have any code examples of this specifically, but here's something I snagged from google that would give you a starting point

    1. var url ="http://www.rediff.com/rss/inrss.xml";//change url and params
    2. try{
    3.   $.ajax({
    4.   url  :'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q='+ encodeURIComponent(url),
    5.   dataType :'json',
    6.   success  :function(data){
    7. if(data.responseData.feed && data.responseData.feed.entries){
    8.   $.each(data.responseData.feed.entries,function(i, e){
    9. var title = e.title;
    10. var link = e.link;
    11.   list = list +'<li><a href="javascript:display_post(\''+ link +'\')">';
    12.   list = list + title;
    13.   list = list +'</a></li>';
    14. });
    15. }
    16.   list = list +'</ul>';
    17.   document.getElementById("single_feed").innerHTML = list;
    18.   $.ui.loadContent("#single_feed");
    19. }
    20. });
    21. }
    22. catch(e){
    23.   alert(e);
    24. }
  • Thanks. This gives me a little to go on, although I have almost zero experience with scripting API calls. Will have to keep digging and learn as I have time unless someone else has already tried this!

  • Using this should render a nice widget with optional Lync (Skype for Business) link to direct open a chat window with them. Adding in and pulling additional services like Teams, Slack, and more should be relatively straightforward.

    This bit of script assumes emails are formatted first.last@domain and then automatically converts that to First Last with mailto link applied to it. If you want to get fancy you can even add in a subject field. 

    <div id="oncall_table" class="sw-rpt-tbl-frame">
    <script>
    
    //OpsGenie Oncall Table Generator 0.9.5 written by Chris O'Rourke April 27th, 2020. 
    
    	var swql="SELECT de.ColumnLabel, de.StringData FROM Orion.APM.DynamicEvidence AS de JOIN Orion.apm.CurrentComponentStatus AS ccs ON ccs.ComponentStatusID = de.ComponentStatusID WHERE ccs.ComponentID = 2120 AND de.StringData IS NOT NULL"
    
    	var params = JSON.stringify({
    		query: swql,
    		parameters: {
    		}
    	});
    	
    	$.ajax({
    		type: 'POST',
    		url: '/Orion/Services/Information.asmx/QueryWithParameters',
    		data: params,
    		contentType: "application/json; charset=utf-8",
    		dataType: "json",
    		success: function(response) {
    			//console.log(response.d.Rows);
    		
    			//Initial Table
    			var oncallTable = "<table class='sw-custom-query-table NeedsZebraStripes' style='table-layout: fixed; width: 100%;' cellpadding='2' cellspacing='0'>";
    			
    			//Colgroup
    			oncallTable += "<colgroup>";
    			oncallTable += "<col span='2' />";
    			oncallTable += "<col span='2' style='width: 50px' />";
    			oncallTable += "</colgroup>";
    			
    			//Table Headers
    			oncallTable += "<thead><tr class='HeaderRow'>";
    			oncallTable += "<th class='ReportHeader' style='font-weight: bold; font-size: 12px; text-align: left;'>Team</th>";
    			oncallTable += "<th class='ReportHeader' style='font-weight: bold; font-size: 12px; text-align: left;'>Oncall Resource</th>";
    			oncallTable += "<th class='ReportHeader' colspan='2' style='font-weight: bold; font-size: 12px; text-align: left;'>Contact</th>";
    			oncallTable += "</tr></thead>";
    
    			//Add Resources to Table
    			for(var i=0; i < response.d.Rows.length; i++){
    				oncallTable += "<tr>";
    				
    				for(var j=0; j < response.d.Rows[i].length; j++) {
    					if (response.d.Rows[i][j].indexOf("@") == -1) {			
    						oncallTable += "<td>" + response.d.Rows[i][j] + "</td>";
    					} else {
    						
    						//Retrieve slack userid
    						
    					
    						//Massage email into First Last name (expects single user oncall)
    						var name = '' + response.d.Rows[i][j];
    						name = name.split("@");
    						name = name[0].split(".");
    						name[1] = name[1].replace(/[0-9]/g, '');
    						//console.log(name);
    						
    						//Render mailto  
    						oncallTable += "<td style='text-transform: capitalize;'>";
    						oncallTable += "<a href='mailto:" + response.d.Rows[i][j] + "'>" + name[0] + " " + name[1] + "</a>";
    						oncallTable += "</td>";
    						
    						//Render skype
    						oncallTable += "<td style='text-transform: capitalize;'>";
    						oncallTable += "<a href='im:sip:" + response.d.Rows[i][j] + "'><img src='/Orion/yourimgs/lync-icon.png'></a>";
    						oncallTable += "</td>";
    
    					}
    				}
    				
    				oncallTable += "</tr>";
    			}
    
    
    			//Table Close
    			oncallTable += "</table>";
    			
    			//Grab Element from DOM and Write
    			var table = document.getElementById('oncall_table');
    			table.innerHTML = oncallTable;
    		}
    	})
    </script>
    </div>
Reply
  • Using this should render a nice widget with optional Lync (Skype for Business) link to direct open a chat window with them. Adding in and pulling additional services like Teams, Slack, and more should be relatively straightforward.

    This bit of script assumes emails are formatted first.last@domain and then automatically converts that to First Last with mailto link applied to it. If you want to get fancy you can even add in a subject field. 

    <div id="oncall_table" class="sw-rpt-tbl-frame">
    <script>
    
    //OpsGenie Oncall Table Generator 0.9.5 written by Chris O'Rourke April 27th, 2020. 
    
    	var swql="SELECT de.ColumnLabel, de.StringData FROM Orion.APM.DynamicEvidence AS de JOIN Orion.apm.CurrentComponentStatus AS ccs ON ccs.ComponentStatusID = de.ComponentStatusID WHERE ccs.ComponentID = 2120 AND de.StringData IS NOT NULL"
    
    	var params = JSON.stringify({
    		query: swql,
    		parameters: {
    		}
    	});
    	
    	$.ajax({
    		type: 'POST',
    		url: '/Orion/Services/Information.asmx/QueryWithParameters',
    		data: params,
    		contentType: "application/json; charset=utf-8",
    		dataType: "json",
    		success: function(response) {
    			//console.log(response.d.Rows);
    		
    			//Initial Table
    			var oncallTable = "<table class='sw-custom-query-table NeedsZebraStripes' style='table-layout: fixed; width: 100%;' cellpadding='2' cellspacing='0'>";
    			
    			//Colgroup
    			oncallTable += "<colgroup>";
    			oncallTable += "<col span='2' />";
    			oncallTable += "<col span='2' style='width: 50px' />";
    			oncallTable += "</colgroup>";
    			
    			//Table Headers
    			oncallTable += "<thead><tr class='HeaderRow'>";
    			oncallTable += "<th class='ReportHeader' style='font-weight: bold; font-size: 12px; text-align: left;'>Team</th>";
    			oncallTable += "<th class='ReportHeader' style='font-weight: bold; font-size: 12px; text-align: left;'>Oncall Resource</th>";
    			oncallTable += "<th class='ReportHeader' colspan='2' style='font-weight: bold; font-size: 12px; text-align: left;'>Contact</th>";
    			oncallTable += "</tr></thead>";
    
    			//Add Resources to Table
    			for(var i=0; i < response.d.Rows.length; i++){
    				oncallTable += "<tr>";
    				
    				for(var j=0; j < response.d.Rows[i].length; j++) {
    					if (response.d.Rows[i][j].indexOf("@") == -1) {			
    						oncallTable += "<td>" + response.d.Rows[i][j] + "</td>";
    					} else {
    						
    						//Retrieve slack userid
    						
    					
    						//Massage email into First Last name (expects single user oncall)
    						var name = '' + response.d.Rows[i][j];
    						name = name.split("@");
    						name = name[0].split(".");
    						name[1] = name[1].replace(/[0-9]/g, '');
    						//console.log(name);
    						
    						//Render mailto  
    						oncallTable += "<td style='text-transform: capitalize;'>";
    						oncallTable += "<a href='mailto:" + response.d.Rows[i][j] + "'>" + name[0] + " " + name[1] + "</a>";
    						oncallTable += "</td>";
    						
    						//Render skype
    						oncallTable += "<td style='text-transform: capitalize;'>";
    						oncallTable += "<a href='im:sip:" + response.d.Rows[i][j] + "'><img src='/Orion/yourimgs/lync-icon.png'></a>";
    						oncallTable += "</td>";
    
    					}
    				}
    				
    				oncallTable += "</tr>";
    			}
    
    
    			//Table Close
    			oncallTable += "</table>";
    			
    			//Grab Element from DOM and Write
    			var table = document.getElementById('oncall_table');
    			table.innerHTML = oncallTable;
    		}
    	})
    </script>
    </div>
Children
  • Keep getting these errors and have been unable (so far) to have this pull back all teams in one query so far.
    "You are making too many requests! To avoid errors, we recommend you limit requests.

    Has anyone else hit this limit? If so, How are you getting around it?