Giter VIP home page Giter VIP logo

logdna-cos's Introduction

LogDNA COS

IBM Cloud Powered Platform LICENSE PRs Welcome

Use Serverless function or VM to send all log registries from IBM Cloud Object Storage (stored by Log push on IBM Cloud Internet Service) to IBM Log Analysis with LogDNA. It will require to setup a Trigger rule to call the function every 5 minutes (to be synced with CIS Log Push time interval).

Architecture Design

Deployment

To deploy, you need to install IBM Cloud CLI and IBM Cloud Functions CLI in your local machine. After this step, you need to login in your IBM Cloud account on IBM Cloud CLI (if you haven't already done, run ibmcloud login), follow all steps below.

1. Clone this repository

git clone https://github.com/victorshinya/logdna-cos.git
cd logdna-cos

2. Open the project in a text editor

If you are going to run on a Serverless function replace all lines, described below. Or if you're going to run on a VM, you can simply add all credencials on a .env file (follow the skeleton on .env.example).

Replace on handler.js:

  • [ Line 33 ] {endpoint} by your IBM Cloud Object Storage's endpoint.
  • [ Line 34 ] {apiKeyId} by your IBM Cloud Object Storage's apiKeyId.
  • [ Line 36 ] {serviceInstanceId} by your IBM Cloud Object Storage's serviceInstanceId.
  • [ Line 44 ] {bucketReceiver} by your IBM Cloud Object Storage's bucket that will receive all log files from IBM Cloud Internet Service.
  • [ Line 45 ] {bucketArchive} by your IBM Cloud Object Storage's bucket after sending all logs to LogDNA.
  • [ Line 60 ] {ingestionKey} by your LogDNA's API Key.
  • [ Line 61 ] {host} by your LogDNA's hostname (defined by you).

3. Deploy all functions

Run the following command to deploy handler.js function. It requires an account on IBM Cloud.

As you are using IBM Cloud Functions, you don't need to install any package or setup a package.json. The platform already has the package installed.

ibmcloud fn deploy --manifest serverless.yml

Execute function on VM

In order to start the script on a VM, with a recursive mode, you have to uncomment all code below DEBUG:: on handler.js (do not uncomment the DEBUG:: line):

async function main() {
    console.time("LogDNA-COS")
    const response = await downloadAndSend()
    console.log(`DEBUG: downloadAndSend = ${JSON.stringify(response.message)}`)
    console.timeEnd("LogDNA-COS")
    // DEBUG::
    // switch (response.status) {
    //     case 200:
    //         console.log(`DEBUG: Fetch new log file`)
    //         await main()
    //         break
    //     case 204:
    //         console.log(`DEBUG: Wait 3 minutes to fetch new log file on COS Bucket`)
    //         await new Promise(r => setTimeout(r, 180000))
    //         await main()
    //         break
    //     default:
    //         console.log(`DEBUG: Uncommon behavior`)
    //         break
    // }
}

// DEBUG::
// main()

Don't forget to add all credencials on a .env file (follow the skeleton on .env.example).

Tip: Use pm2 to run the script on background in your Virtual Machine.

API Reference

Troubleshooting

LICENSE

Copyright 2020 Victor Shinya

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

logdna-cos's People

Contributors

victorshinya avatar imgbotapp avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.