IPMI Tools

There are 4 notable ipmi sw tools and here is the compare ipmi tools compare

Usage EX:
Get sensors

  • ipmi-sensors -h 10.250.210.139 -u admin -p password -D LAN_2_0

  • ipmitool -I lanplus -U admin -P password -H 10.250.210.13 sdr list

  • ipmiutil sensor -c -F lan2 -N 10.250.210.13 -U admin -R password

How to build the reusable library of ipmitool…

  1. doenload ipmitool 1.8.15

  2. yum install openssl openssl-devel (For “lanplus : yes”)

  3. cd ipmitool 1.8.15 & CC=gcc4 CFLAGS=-m32 LDFLAGS=-static & ./configure

  4. (make clean) & make & make install

  5. cd src

  6. /bin/sh ../libtool –silent –tag=CC –mode=link gcc -fno-strict-aliasing -Wreturn-type -all-static -o ipmitool.a ipmishell.o ../lib/libipmitool.la plugins/libintf.la

  7. gcc -g -lm -lcrypto ipmitool.c -fPIC -shared -o libicdcipmi.so -L. ipmitool.a -I./ipmitool-1.8.15/include/

Build own libicdcipmi.so using ipmitool.a

ipmitool.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
int getSensorsIPMI(char *interface, char *usr, char *pws, char *ip, char *retry, char *getJsonString){
int rc,i;
int argc = 13;
char** argv;
argv = malloc(argc * sizeof(char*));
for (i = 0; i < argc; i += 1)
argv[i] = malloc(32 * sizeof(char));

sprintf(argv[0],"%s", "m.out");
sprintf(argv[1],"%s", "-I");
sprintf(argv[2],"%s", interface);
sprintf(argv[3],"%s", "-U");
sprintf(argv[4],"%s", usr);
sprintf(argv[5],"%s", "-P");
sprintf(argv[6],"%s", pws);
sprintf(argv[7],"%s", "-H");
sprintf(argv[8],"%s", ip);
sprintf(argv[9],"%s", "-R");
sprintf(argv[10],"%s", retry);
sprintf(argv[11],"%s", "sensor");
sprintf(argv[12],"%s", "icdc"); // list

struct ipmi_intf_icdc iii;
memset(&iii, 0, sizeof(struct ipmi_intf_icdc));
ipmi_icdc_mian(argc, argv, ipmitool_cmd_list, NULL, &iii);

for (i = 0; i < argc; i += 1)
free(argv[i]);
free(argv);

return rc;
}
...

8.cp libicdcipmi.so /usr/lib & ldconfig

9.go build icdc_ipmi.go

icdc_ipmi.go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
#cgo LDFLAGS: -L/usr/lib/ -licdcipmi
#cgo CFLAGS: -I./
#include <stdio.h>
#include <stdlib.h>
#include "ipmitool.h"
*/

import "C"
import (
"os"
"fmt"
"runtime"
"unsafe"
)

func getSensorsIPMI() {
drvtyp := C.CString("lanplus")
nod := C.CString("10.250.210.13")
usr := C.CString("ad")
psw := C.CString( "pd")
retry := C.CString( "1")
var getJson [8192]byte
ret := C.getSensorsIPMI( drvtyp, usr, psw, nod, retry, (*C.char)(unsafe.Pointer(&getJson[0])))
C.free(unsafe.Pointer(drvtyp))
C.free(unsafe.Pointer(nod))
C.free(unsafe.Pointer(usr))
C.free(unsafe.Pointer(psw))
C.free(unsafe.Pointer(retry))
if ret == 0 {
var jsonString string
jsonString = C.GoString((*C.char)(unsafe.Pointer(&getJson[0])))
fmt.Println("getSensorsIPMI => ",jsonString)
}
}