Hi @Uday, There are several approaches to create a server status dashboard in Splunk when you don't have explicit "server up/down" logs. Here are the most effective methods:
## Method 1: Check for Recent Log Activity
This is the simplest approach - if a server is sending logs, it's probably up:
```
| metadata type=hosts index=*
| search host=*
| eval lastTime=strftime(recentTime,"%Y-%m-%d %H:%M:%S")
| eval status=if(now()-recentTime < 600, "UP", "DOWN")
| table host lastTime status
| sort host
```
Customize the time threshold (600 seconds = 10 minutes) based on your expected log frequency.
## Method 2: Using Rangemap for Visualization
Use rangemap to assign colors to status values:
```
| metadata type=hosts index=*
| search host=*
| eval lastTime=strftime(recentTime,"%Y-%m-%d %H:%M:%S")
| eval seconds_since_last_log=now()-recentTime
| eval status=if(seconds_since_last_log < 600, "UP", "DOWN")
| rangemap field=status up="0-0" down="1-1"
| table host lastTime status range
| sort host
```
For dashboard visualization, you'll need to add:
1. A CSS file (table_decorations.css) with content:
```css
.severe {
background-color: #dc4e41 !important;
color: white !important;
}
.low {
background-color: #65a637 !important;
color: white !important;
}
```
2. A JavaScript file (table_icons_rangemap.js) with content:
```javascript
require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/tableview',
'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
canRender: function(cell) {
return cell.field === 'range';
},
render: function($td, cell) {
var value = cell.value;
if(value === "severe") {
$td.addClass('severe');
$td.html('Down');
} else if(value === "low") {
$td.addClass('low');
$td.html('Up');
}
return $td;
}
});
mvc.Components.get('table1').getVisualization(function(tableView) {
tableView.addCellRenderer(new CustomRangeRenderer());
tableView.render();
});
});
```
3. Dashboard XML that includes these files:
```xml
<form script="table_icons_rangemap.js" stylesheet="table_decorations.css">
<label>Server Status Dashboard</label>
<fieldset submitButton="false">
<input type="time" token="field1">
<label></label>
<default>
<earliest>-60m@m</earliest>
<latest>now</latest>
</default>
</input>
</fieldset>
<row>
<panel>
<table id="table1">
<search>
<query>| metadata type=hosts index=*
| search host=*
| eval lastTime=strftime(recentTime,"%Y-%m-%d %H:%M:%S")
| eval seconds_since_last_log=now()-recentTime
| eval status=if(seconds_since_last_log < 600, "UP", "DOWN")
| rangemap field=status up="0-0" down="1-1"
| table host lastTime status range
| sort host</query>
<earliest>$field1.earliest$</earliest>
<latest>$field1.latest$</latest>
</search>
<option name="drilldown">none</option>
</table>
</panel>
</row>
</form>
```
## Method 3: Include All Expected Servers
To also show servers that aren't sending logs at all, use a lookup with all expected servers:
```
| inputlookup your_servers.csv
| append [| metadata type=hosts index=*]
| stats max(recentTime) as recentTime by host
| eval lastTime=if(isnotnull(recentTime),strftime(recentTime,"%Y-%m-%d %H:%M:%S"),"Never")
| eval seconds_since_last_log=if(isnotnull(recentTime),now()-recentTime,999999)
| eval status=if(seconds_since_last_log < 600, "UP", "DOWN")
| rangemap field=status up="0-0" down="1-1"
| table host lastTime status range
| sort host
```
## Method 4: Advanced Server Status Check (Recommended for Critical Systems)
If exact server status is critical, create a scheduled search that sends heartbeats from each server and alerts when they're missing:
1. Create a small script on each server that sends a heartbeat every few minutes:
```
index=server_status sourcetype=heartbeat host=$HOSTNAME$ status=ALIVE
```
2. Then use this search for your dashboard:
```
| inputlookup your_servers.csv
| map search="search earliest=-10m latest=now index=server_status sourcetype=heartbeat host=$host$ | head 1 | fields host"
| fillnull value="DOWN" status
| eval status=if(host=="NULL","DOWN","UP")
| rangemap field=status up="0-0" down="1-1"
| table host status range
```
This solution is more accurate than just checking for any logs, as it specifically monitors for heartbeat messages.
Remember to place your CSS and JS files in the /appserver/static/ directory of your app, and restart Splunk after adding them.
Please give 👍 for support 😁 happly splunking .... 😎
... View more