
Alert Notification offers platform alerts and notifications for resources in the SAP Cloud Platform and gives you the possibility to create custom alerts for these resources.
This GA released at June 2019.
You also have to option to import a JSON containing the one of the following parameters:
{"type":"BASIC"} - use for creating basic authentication credentials
{"type":"OAUTH"} - use for creating OAuth 2.0 credentials
In this time, we use Basic authentication.
cd /d D:\html5
npm install express-generator -g
express -e alertnode
cd alertnode
{
"name": "alertnode",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"ejs": "~2.6.1",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"morgan": "~1.9.1",
"request": "*"
}
}
npm install
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var request = require('request');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use("/api/notify", function(req,res,next){
var options = {
url: 'https://clm-sl-ans-live-ans-service-api.cfapps.eu10.hana.ondemand.com/cf/producer/v1/resource-events', // Endpoint URL + "/cf/producer/v1/resource-events"
method: 'POST',
auth: {
user: "<YOUR_BASIC_USER>", // Change here.
password: "<YOUR_BASIC_PASS>" // Change here.
},
json: {
"eventType": "mycustomevent",
"resource": {
"resourceName": "Your Node.js App.",
"resourceType": "app",
"tags": {
"env": "develop environment"
}
},
"severity": "FATAL",
"category": "ALERT",
"subject": "Something is wrong.",
"body": "Hello world",
"tags": {
"ans:correlationId": "30118",
"ans:status": "CREATE_OR_UPDATE",
"customTag": "42"
}
}
}
// Send request
request(options, function (error, response, body) {
console.log(response.body);
res.send('Send E-mail Notification.');
});
});
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
npm start
> alertnode@0.0.0 start D:\html5\alertnode
> node ./bin/www
cf api https://api.cf.eu10.hana.ondemand.com
cf login
# Deploy command.
cf push alertnode
Pushing app alertnode to org XXXXXXXX.XXXXXXXX / space dev as unoys@qunie.com...
Getting app info...
Updating app with these attributes...
name: alertnode
path: D:\html5\alertnode
buildpack: nodejs
command: npm start
disk quota: 1G
health check type: port
instances: 1
memory: 1G
stack: cflinuxfs3
routes:
alertnode.cfapps.eu10.hana.ondemand.com
Updating app alertnode...
Mapping routes...
Comparing local files to remote cache...
Packaging files to upload...
Uploading files...
1.40 MiB / 1.40 MiB [=====================================================================================] 100.00% 6s
Waiting for API to complete processing files...
Stopping app...
Staging app and tracing logs...
Downloaded app package (1.8M)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
7 | |
6 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |