mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Added jira alert transport (#7040)
* feature: added jira transport * Trying to fix travis-ci sql problem * Surpress mysql warnings * Fix for typo * Update Alerting.md
This commit is contained in:
committed by
Neil Lathwood
parent
c40825f233
commit
c592f901b0
@@ -27,14 +27,16 @@ Table of Content:
|
||||
- [Pushbullet](Transports.md#transports-pushbullet)
|
||||
- [Clickatell](Transports.md#transports-clickatell)
|
||||
- [PlaySMS](Transports.md#transports-playsms)
|
||||
- [VictorOps](#transports-victorops)
|
||||
- [Canopsis](#transports-canopsis)
|
||||
- [osTicket](#transports-osticket)
|
||||
- [Microsoft Teams](#transports-msteams)
|
||||
- [Cisco Spark](#transports-ciscospark)
|
||||
- [SMSEagle](#transports-smseagle)
|
||||
- [Syslog](#transports-syslog)
|
||||
- [Elasticsearch](#transports-elasticsearch)
|
||||
- [VictorOps](Transports.md#transports-victorops)
|
||||
- [Canopsis](Transports.md#transports-canopsis)
|
||||
- [osTicket](Transports.md#transports-osticket)
|
||||
- [Microsoft Teams](Transports.md#transports-msteams)
|
||||
- [Cisco Spark](Transports.md#transports-ciscospark)
|
||||
- [SMSEagle](Transports.md#transports-smseagle)
|
||||
- [Syslog](Transports.md#transports-syslog)
|
||||
- [Elasticsearch](Transports.md#transports-elasticsearch)
|
||||
- [Jira](Transports.md#transports-jira)
|
||||
|
||||
- [Entities](Entities.md)
|
||||
- [Devices](Entities.md#entity-devices)
|
||||
- [BGP Peers](Entities.md#entity-bgppeers)
|
||||
|
@@ -478,3 +478,19 @@ $config['alert']['transports']['elasticsearch']['es_index'] = 'librenms-%Y.%m.%
|
||||
$config['alert']['transports']['elasticsearch']['es_proxy'] = false;
|
||||
```
|
||||
~
|
||||
|
||||
## <a name="transports-jira">JIRA</a>
|
||||
|
||||
You can have LibreNMS create issues on a Jira instance for critical and warning alerts. The Jira transport only sets summary and description fiels. Therefore your Jira project must not have any other mandatory field for the provided issuetype. The config fields that need to set are Jira URL, Jira username, Jira password, Project key, and issue type.
|
||||
Currently http authentication is used to access Jira and Jira username and password will be stored as cleartext in the LibreNMS database.
|
||||
|
||||
~
|
||||
```php
|
||||
$config['alert']['transports']['jira']['url'] = 'https://myjira.mysite.com';
|
||||
$config['alert']['transports']['jira']['username'] = 'myjirauser';
|
||||
$config['alert']['transports']['jira']['password'] = 'myjirapass';
|
||||
$config['alert']['transports']['jira']['prjkey'][] = 'JIRAPROJECTKEY';
|
||||
$config['alert']['transports']['jira']['issuetype'][] = 'Myissuetype';
|
||||
```
|
||||
~
|
||||
|
||||
|
@@ -1354,6 +1354,72 @@ echo '
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
// Jira Transport Section
|
||||
$jira_prj = get_config_by_name('alert.transports.jira.prjkey');
|
||||
$jira_url = get_config_by_name('alert.transports.jira.url');
|
||||
$jira_username = get_config_by_name('alert.transports.jira.username');
|
||||
$jira_password = get_config_by_name('alert.transports.jira.password');
|
||||
$jira_issuetype = get_config_by_name('alert.transports.jira.issuetype');
|
||||
echo '
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#jira_transport_expand"><i class="fa fa-caret-down"></i> Jira transport</a> <button name="test-alert" id="test-alert" type="button" data-transport="jira" class="btn btn-primary btn-xs pull-right">Test transport</button>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="jira_transport_expand" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<div class="form-group has-feedback">
|
||||
<label for="jira_prj" class="col-sm-4 control-label">Jira Project Key </label>
|
||||
<div class="col-sm-4">
|
||||
<input id="jira_prj" class="form-control" type="text" name="global-config-input" value="'.$jira_prj['config_value'].'" data-config_id="'.$jira_prj['config_id'].'">
|
||||
<span class="form-control-feedback">
|
||||
<i class="fa" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label for="jira_url" class="col-sm-4 control-label">Jira URL </label>
|
||||
<div class="col-sm-4">
|
||||
<input id="jira_url" class="form-control" type="url" name="global-config-input" value="'.$jira_url['config_value'].'" data-config_id="'.$jira_url['config_id'].'">
|
||||
<span class="form-control-feedback">
|
||||
<i class="fa" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label for="jira_issuetype" class="col-sm-4 control-label">Jira Issue Type </label>
|
||||
<div class="col-sm-4">
|
||||
<input id="jira_issuetype" class="form-control" type="text" name="global-config-input" value="'.$jira_issuetype['config_value'].'" data-config_id="'.$jira_issuetype['config_id'].'">
|
||||
<span class="form-control-feedback">
|
||||
<i class="fa" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label for="jira_username" class="col-sm-4 control-label">Jira Username </label>
|
||||
<div class="col-sm-4">
|
||||
<input id="jira_username" class="form-control" type="text" name="global-config-input" value="'.$jira_username['config_value'].'" data-config_id="'.$jira_username['config_id'].'">
|
||||
<span class="form-control-feedback">
|
||||
<i class="fa" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label for="jira_password" class="col-sm-4 control-label">Jira Password </label>
|
||||
<div class="col-sm-4">
|
||||
<input id="jira_password" class="form-control" type="password" name="global-config-input" value="'.$jira_password['config_value'].'" data-config_id="'.$jira_password['config_id'].'">
|
||||
<span class="form-control-feedback">
|
||||
<i class="fa" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
// End Jira Transport Section
|
||||
|
||||
$es_host = get_config_by_name('alert.transports.elasticsearch.es_host');
|
||||
$es_port = get_config_by_name('alert.transports.elasticsearch.es_port');
|
||||
$es_index = get_config_by_name('alert.transports.elasticsearch.es_index');
|
||||
@@ -1409,6 +1475,7 @@ echo '
|
||||
</form>
|
||||
</div>
|
||||
';
|
||||
|
||||
?>
|
||||
|
||||
<script>
|
||||
@@ -1485,7 +1552,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">Error creating config item</div>');
|
||||
$("#message").html('<div class="alert alert-danger">Error creating config item</div>');
|
||||
}
|
||||
});
|
||||
});// End Add API config
|
||||
@@ -1521,7 +1588,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">Error creating config item</div>');
|
||||
$("#message").html('<div class="alert alert-danger">Error creating config item</div>');
|
||||
}
|
||||
});
|
||||
});// End Add Slack config
|
||||
@@ -1557,7 +1624,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">Error creating config item</div>');
|
||||
$("#message").html('<div class="alert alert-danger">Error creating config item</div>');
|
||||
}
|
||||
});
|
||||
});// End Add Slack config
|
||||
@@ -1597,7 +1664,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">Error creating config item</div>');
|
||||
$("#message").html('<div class="alert alert-danger">Error creating config item</div>');
|
||||
}
|
||||
});
|
||||
});// End Add Hipchat config
|
||||
@@ -1636,7 +1703,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">Error creating config item</div>');
|
||||
$("#message").html('<div class="alert alert-danger">Error creating config item</div>');
|
||||
}
|
||||
});
|
||||
});// End Add Pushover config
|
||||
@@ -1672,7 +1739,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">Error creating config item</div>');
|
||||
$("#message").html('<div class="alert alert-danger">Error creating config item</div>');
|
||||
}
|
||||
});
|
||||
});// End Add Boxcar config
|
||||
@@ -1708,7 +1775,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">Error creating config item</div>');
|
||||
$("#message").html('<div class="alert alert-danger">Error creating config item</div>');
|
||||
}
|
||||
});
|
||||
});// End Add Telegram config
|
||||
@@ -1729,7 +1796,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
$("#message").html('<div class="alert alert-danger">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});// End delete api config
|
||||
@@ -1750,7 +1817,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
$("#message").html('<div class="alert alert-danger">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});// End delete slack config
|
||||
@@ -1771,7 +1838,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
$("#message").html('<div class="alert alert-danger">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});// End delete rocket config
|
||||
@@ -1792,7 +1859,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
$("#message").html('<div class="alert alert-danger">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});// End delete hipchat config
|
||||
@@ -1813,7 +1880,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
$("#message").html('<div class="alert alert-danger">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});// End delete pushover config
|
||||
@@ -1834,7 +1901,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
$("#message").html('<div class="alert alert-danger">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});// End delete Boxcar config
|
||||
@@ -1856,7 +1923,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
$("#message").html('<div class="alert alert-danger">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});// End delete Telegram config
|
||||
@@ -1889,10 +1956,11 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
$("#message").html('<div class="alert alert-danger">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('blur', 'textarea[name="global-config-textarea"]', function(event) {
|
||||
event.preventDefault();
|
||||
var $this = $(this);
|
||||
@@ -1922,7 +1990,7 @@ echo '
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
$("#message").html('<div class="alert alert-danger">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
64
includes/alerts/transport.jira.php
Normal file
64
includes/alerts/transport.jira.php
Normal file
@@ -0,0 +1,64 @@
|
||||
/* Copyright (C) 2015 Aldemir Akpinar <aldemir.akpinar@gmail.com>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/**
|
||||
* Jira API Transport
|
||||
* @author Aldemir Akpinar <aldemir.akpinar@gmail.com>
|
||||
* @copyright 2017 Aldemir Akpinar, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
// Don't create tickets for resolutions
|
||||
if($obj['status'] == 0 && $obj['msg'] != 'This is a test alert') {
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
$username = $opts['username'];
|
||||
$password = $opts['password'];
|
||||
$prjkey = $opts['prjkey'];
|
||||
$issuetype = $opts['issuetype'];
|
||||
$details = "Librenms alert for: ".$obj['hostname'];
|
||||
$description = $obj['msg'];
|
||||
$url = $opts['url'].'/rest/api/latest/issue';
|
||||
$curl = curl_init();
|
||||
|
||||
$data = array("project" => array("key" => $prjkey),
|
||||
"summary" => $details,
|
||||
"description" => $description,
|
||||
"issuetype" => array("name" => $issuetype));
|
||||
$postdata = array("fields" => $data);
|
||||
$datastring = json_encode($postdata);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
|
||||
$headers = array('Accept: application/json', 'Content-Type: application/json');
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $datastring);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code == 200 ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
5
sql-schema/200.sql
Normal file
5
sql-schema/200.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
INSERT INTO `config` (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values('alert.transports.jira.prjkey','','','Jira Project Key','alerting',0,'transports',0,default,default);
|
||||
INSERT INTO `config` (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values('alert.transports.jira.url','','','Jira URL','alerting',0,'transports',0,default,default);
|
||||
INSERT INTO `config` (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values('alert.transports.jira.username','','','Jira Username','alerting',0,'transports',0,default,default);
|
||||
INSERT INTO `config` (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values('alert.transports.jira.password','','','Jira Password','alerting',0,'transports',0,default,default);
|
||||
INSERT INTO `config` (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values('alert.transports.jira.issuetype','','','Jira Issue Type','alerting',0,'transports',0,default,default);
|
Reference in New Issue
Block a user