Skip to content

A Fledge processing filter that is used to modify the name of an asset, datapoint or both.

License

Notifications You must be signed in to change notification settings

fledge-iot/fledge-filter-rename

Repository files navigation

fledge-filter-rename

It is a filter plugin for Fledge which can be used to modify the name of an asset, datapoint or both.

Configuration options

  • config item: 'operation', type: 'enumeration', default: 'asset'
    Search and replace operation be performed on asset name, datapoint name or both
  • config item: 'find', type: 'string', default: 'assetName'
    A regular expression to match for the given operation
  • config item: 'replaceWith', type: 'string', default: 'newAssetName'
    A substitution string to replace the matched text with
  • config item: 'enable', type: 'boolean', default: 'false'
    Enable/Disable filter plugin

Examples

  • An input of reading object
{
    "readings": {
        "sinusoid": -0.978147601,
        "a": {
            "sinusoid": "2.0"
        }
    },
    "asset": "sinusoid",
    "id": "a1bedea3-8d80-47e8-b256-63370ccfce5b",
    "ts": "2021-06-28 14:03:22.106562+00:00",
    "user_ts": "2021-06-28 14:03:22.106435+00:00"
}

Apply the configuration:

  1. Case1
  • 'Operation' : 'asset'
  • 'Find' : 'sinusoid'
  • 'Replace With' : 'sin'
  • 'Enabled' : 'True'

Output

{
    "readings": {
        "sinusoid": -0.978147601,
        "a": {
            "sinusoid": 2.0
        }
    },
    "asset": "sin",
    "id": "a1bedea3-8d80-47e8-b256-63370ccfce5b",
    "ts": "2021-06-28 14:03:22.106562+00:00",
    "user_ts": "2021-06-28 14:03:22.106435+00:00"
}

See the asset 'sinusoid' is replaced with 'sin'

  1. Case2
  • 'Operation' : 'datapoint'
  • 'Find' : 'sinusoid'
  • 'Replace With' : 'sin'
  • 'Enabled' : 'True'

Output

{
    "readings": {
        "sin": -0.978147601,
        "a": {
            "sin": 2.0
        }
    },
    "asset": "sinusoid",
    "id": "a1bedea3-8d80-47e8-b256-63370ccfce5b",
    "ts": "2021-06-28 14:03:22.106562+00:00",
    "user_ts": "2021-06-28 14:03:22.106435+00:00"
}

See the readings datapoint 'sinusoid' is replaced with 'sin' even for the nested elements as well

  1. Case3
  • 'Operation' : 'both'
  • 'Find' : 'sinusoid'
  • 'Replace With' : 'sin'
  • 'Enabled' : 'True'

Output

{
    "readings": {
        "sin": -0.978147601,
        "a": {
            "sin": 2.0
        }
    },
    "asset": "sin",
    "id": "a1bedea3-8d80-47e8-b256-63370ccfce5b",
    "ts": "2021-06-28 14:03:22.106562+00:00",
    "user_ts": "2021-06-28 14:03:22.106435+00:00"
}

See the asset & readings datapoint 'sinusoid' is replaced with 'sin'

  1. Case4 - With regular expression, note that escaping do it by your own
  • 'Operation' : 'both'
  • 'Find' : '^(.+)$'
  • 'Replace With' : 'NEW.\1'
  • 'Enabled' : 'True'

Output

{
    "readings": {
        "NEW.sinusoid": -0.978147601,
        "a": {
            "NEW.sinusoid": 2.0
        }
    },
    "asset": "NEW.sinusoid",
    "id": "a1bedea3-8d80-47e8-b256-63370ccfce5b",
    "ts": "2021-06-28 14:03:22.106562+00:00",
    "user_ts": "2021-06-28 14:03:22.106435+00:00"
}

See the asset & readings datapoint 'sinusoid' is replaced with 'New.sinusoid'

  1. Case5
  • 'Operation' : 'asset'
  • 'Find' : '^sin.*'
  • 'Replace With' : 'sine'
  • 'Ignore Case' : 'False'
  • 'Enabled' : 'True'
{
    "readings": {
        "sinusoid": -0.978147601,
        "a": {
            "sinusoid": "2.0"
        }
    },
    "asset": "sine",
    "id": "a1bedea3-8d80-47e8-b256-63370ccfce5b",
    "ts": "2021-06-28 14:03:22.106562+00:00",
    "user_ts": "2021-06-28 14:03:22.106435+00:00"
}

With case insensitive search, see the asset 'sinusoid' is replaced with 'sine'

  1. Case6
  • 'Operation' : 'both'
  • 'Find' : '^Sin.*'
  • 'Replace With' : 'sine'
  • 'Ignore Case' : 'True'
  • 'Enabled' : 'True'
{
    "readings": {
        "sinusoid": -0.978147601,
        "a": {
            "sinusoid": "2.0"
        }
    },
    "asset": "sinusoid",
    "id": "a1bedea3-8d80-47e8-b256-63370ccfce5b",
    "ts": "2021-06-28 14:03:22.106562+00:00",
    "user_ts": "2021-06-28 14:03:22.106435+00:00"
}

With case sensitive search, Nothing to get replaced

About

A Fledge processing filter that is used to modify the name of an asset, datapoint or both.

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages